refactor: use @xsai/model instead of openai (#1)
This commit is contained in:
@@ -39,11 +39,11 @@
|
||||
"@unocss/reset": "^0.65.0",
|
||||
"@vueuse/core": "^12.0.0",
|
||||
"@vueuse/head": "^2.0.0",
|
||||
"@xsai/shared-chat-completion": "^0.0.14",
|
||||
"@xsai/stream-text": "^0.0.14",
|
||||
"@xsai/model": "^0.0.16",
|
||||
"@xsai/shared-chat-completion": "^0.0.16",
|
||||
"@xsai/stream-text": "^0.0.16",
|
||||
"nprogress": "^0.2.0",
|
||||
"ofetch": "^1.4.1",
|
||||
"openai": "^4.75.0",
|
||||
"pinia": "^2.2.8",
|
||||
"pixi-live2d-display": "^0.4.0",
|
||||
"rehype-stringify": "^10.0.1",
|
||||
|
||||
@@ -253,16 +253,14 @@ watch([openAiApiBaseURL, openAiApiKey], async ([baseUrl, apiKey]) => {
|
||||
return
|
||||
}
|
||||
|
||||
const fetchedModels = await models(baseUrl, apiKey)
|
||||
supportedModels.value = fetchedModels.data
|
||||
supportedModels.value = await models(baseUrl, apiKey)
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
if (!openAiApiBaseURL.value || !openAiApiKey.value)
|
||||
return
|
||||
|
||||
const fetchedModels = await models(openAiApiBaseURL.value, openAiApiKey.value)
|
||||
supportedModels.value = fetchedModels.data
|
||||
supportedModels.value = await models(openAiApiBaseURL.value, openAiApiKey.value)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import type { GenerateAudioStream } from '@airi-proj/elevenlabs/types'
|
||||
import type { Message } from '@xsai/shared-chat-completion'
|
||||
import { listModels } from '@xsai/model'
|
||||
import { streamText } from '@xsai/stream-text'
|
||||
import { ofetch } from 'ofetch'
|
||||
import { OpenAI } from 'openai'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useLLM = defineStore('llm', () => {
|
||||
async function stream(apiUrl: string, apiKey: string, model: string, messages: Message[]) {
|
||||
return await streamText({
|
||||
url: `${apiUrl}/chat/completions`,
|
||||
baseURL: (apiUrl.endsWith('/') ? apiUrl : `${apiUrl}/`) as `${string}/`,
|
||||
apiKey,
|
||||
model,
|
||||
messages,
|
||||
@@ -27,13 +27,10 @@ export const useLLM = defineStore('llm', () => {
|
||||
}
|
||||
|
||||
try {
|
||||
const openai = new OpenAI({
|
||||
return await listModels({
|
||||
baseURL: (apiUrl.endsWith('/') ? apiUrl : `${apiUrl}/`) as `${string}/`,
|
||||
apiKey,
|
||||
baseURL: apiUrl,
|
||||
dangerouslyAllowBrowser: true,
|
||||
})
|
||||
|
||||
return await openai.models.list()
|
||||
}
|
||||
catch (err) {
|
||||
if (String(err).includes(`Failed to construct 'URL': Invalid URL`)) {
|
||||
|
||||
Generated
+26
-103
@@ -165,21 +165,21 @@ importers:
|
||||
'@vueuse/head':
|
||||
specifier: ^2.0.0
|
||||
version: 2.0.0(vue@3.5.13(typescript@5.7.2))
|
||||
'@xsai/model':
|
||||
specifier: ^0.0.16
|
||||
version: 0.0.16
|
||||
'@xsai/shared-chat-completion':
|
||||
specifier: ^0.0.14
|
||||
version: 0.0.14
|
||||
specifier: ^0.0.16
|
||||
version: 0.0.16
|
||||
'@xsai/stream-text':
|
||||
specifier: ^0.0.14
|
||||
version: 0.0.14
|
||||
specifier: ^0.0.16
|
||||
version: 0.0.16
|
||||
nprogress:
|
||||
specifier: ^0.2.0
|
||||
version: 0.2.0
|
||||
ofetch:
|
||||
specifier: ^1.4.1
|
||||
version: 1.4.1
|
||||
openai:
|
||||
specifier: ^4.75.0
|
||||
version: 4.75.0(zod@3.23.8)
|
||||
pinia:
|
||||
specifier: ^2.2.8
|
||||
version: 2.2.8(typescript@5.7.2)(vue@3.5.13(typescript@5.7.2))
|
||||
@@ -2232,15 +2232,9 @@ packages:
|
||||
'@types/ms@0.7.34':
|
||||
resolution: {integrity: sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==}
|
||||
|
||||
'@types/node-fetch@2.6.12':
|
||||
resolution: {integrity: sha512-8nneRWKCg3rMtF69nLQJnOYUcbafYeFSjqkw3jCRLsqkWFlHaoQrr5mXmofFGOx3DKn7UfmBMyov8ySvLRVldA==}
|
||||
|
||||
'@types/node-forge@1.3.11':
|
||||
resolution: {integrity: sha512-FQx220y22OKNTqaByeBGqHWYz4cl94tpcxeFdvBo3wjG6XPBuZ0BNgNZRV5J5TFmmcsJ4IzsLkmGRiQbnYsBEQ==}
|
||||
|
||||
'@types/node@18.19.67':
|
||||
resolution: {integrity: sha512-wI8uHusga+0ZugNp0Ol/3BqQfEcCCNfojtO6Oou9iVNGPTL6QNSdnUdqq85fRgIorLhLMuPIKpsN98QE9Nh+KQ==}
|
||||
|
||||
'@types/node@22.10.1':
|
||||
resolution: {integrity: sha512-qKgsUwfHZV2WCWLAnVP1JqnpE6Im6h3Y0+fYgMTasNQ7V++CBX5OT1as0g0f+OyubbFqhf6XVNIsmN4IIhEgGQ==}
|
||||
|
||||
@@ -2762,14 +2756,17 @@ packages:
|
||||
'@webgpu/types@0.1.51':
|
||||
resolution: {integrity: sha512-ktR3u64NPjwIViNCck+z9QeyN0iPkQCUOQ07ZCV1RzlkfP+olLTeEZ95O1QHS+v4w9vJeY9xj/uJuSphsHy5rQ==}
|
||||
|
||||
'@xsai/shared-chat-completion@0.0.14':
|
||||
resolution: {integrity: sha512-ZDafvSbppdvEFNvNYn0EFuIU5a7I6MH3XwwIjZioQD+JLFygr7aFopv3tlJbp0C9wYgzJzf0brUpUanH7f4fEA==}
|
||||
'@xsai/model@0.0.16':
|
||||
resolution: {integrity: sha512-0zbH+0m8KjbsjbsTKUaU64ZaGab68TQ0ewkkd3pKEPtNeSEVA6mtNU+/++A38TGLGcYcVt3sUtDpO8NvqTicKQ==}
|
||||
|
||||
'@xsai/shared@0.0.14':
|
||||
resolution: {integrity: sha512-nUllbiLK1PzD+6OQhZufepv2LkN0WEIS9S0f5AKf8XYC7pnl/aIK4AuyJdgBPMUXa6IH/aPPHrv/GzeXCwSXCA==}
|
||||
'@xsai/shared-chat-completion@0.0.16':
|
||||
resolution: {integrity: sha512-wgxk8io0QzuYuBq3I4ZgJHZ6NE0VtfQ0lzIv1aBfokDXmSZ/BFSK7um/UkcMUmbmqPVBaPBxxBO2KxCAK6vjEg==}
|
||||
|
||||
'@xsai/stream-text@0.0.14':
|
||||
resolution: {integrity: sha512-I9TIqy3C9UbXv9Z5TzZSA5jtu77PeUlWUtHMMQJaW9y+j7wIGK3o+I6ZgCL/uDotF1zlNFmBYsZO/ulnAaguBg==}
|
||||
'@xsai/shared@0.0.16':
|
||||
resolution: {integrity: sha512-hoGgMl2obi584ObHshSvHSxnOUUwWoB7vdUjjRSYaQNuTlUGK5n85j7gPl2d4oHhI0nonVdXsYTfCgO0todkYg==}
|
||||
|
||||
'@xsai/stream-text@0.0.16':
|
||||
resolution: {integrity: sha512-+humpH733OidPcOi32iZHaYRdb8d1NkUIzhQArx1JxkD+n34CEnB/SljuGtCbno2iLxLJzMMDcecJvyoYjCQgg==}
|
||||
|
||||
abort-controller@3.0.0:
|
||||
resolution: {integrity: sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==}
|
||||
@@ -2797,10 +2794,6 @@ packages:
|
||||
resolution: {integrity: sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==}
|
||||
engines: {node: '>= 14'}
|
||||
|
||||
agentkeepalive@4.5.0:
|
||||
resolution: {integrity: sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==}
|
||||
engines: {node: '>= 8.0.0'}
|
||||
|
||||
ajv@6.12.6:
|
||||
resolution: {integrity: sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==}
|
||||
|
||||
@@ -3899,9 +3892,6 @@ packages:
|
||||
for-each@0.3.3:
|
||||
resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==}
|
||||
|
||||
form-data-encoder@1.7.2:
|
||||
resolution: {integrity: sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A==}
|
||||
|
||||
form-data-encoder@4.0.2:
|
||||
resolution: {integrity: sha512-KQVhvhK8ZkWzxKxOr56CPulAhH3dobtuQ4+hNQ+HekH/Wp5gSOafqRAeTphQUJAIk0GBvHZgJ2ZGRWd5kphMuw==}
|
||||
engines: {node: '>= 18'}
|
||||
@@ -3910,10 +3900,6 @@ packages:
|
||||
resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==}
|
||||
engines: {node: '>= 6'}
|
||||
|
||||
formdata-node@4.4.1:
|
||||
resolution: {integrity: sha512-0iirZp3uVDjVGt9p49aTaqjk84TrglENEDuqfdlZQ1roC9CWlPk6Avf8EEnZNcAqPonwkG35x4n3ww/1THYAeQ==}
|
||||
engines: {node: '>= 12.20'}
|
||||
|
||||
formdata-node@6.0.3:
|
||||
resolution: {integrity: sha512-8e1++BCiTzUno9v5IZ2J6bv4RU+3UKDmqWUQD0MIMVCd9AdhWkO1gw57oo1mNEX1dMq2EGI+FbWz4B92pscSQg==}
|
||||
engines: {node: '>= 18'}
|
||||
@@ -4179,9 +4165,6 @@ packages:
|
||||
resolution: {integrity: sha512-/1/GPCpDUCCYwlERiYjxoczfP0zfvZMU/OWgQPMya9AbAE24vseigFdhAMObpc8Q4lc/kjutPfUddDYyAmejnA==}
|
||||
engines: {node: '>=18.18.0'}
|
||||
|
||||
humanize-ms@1.2.1:
|
||||
resolution: {integrity: sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==}
|
||||
|
||||
iconv-lite@0.4.24:
|
||||
resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
@@ -4913,10 +4896,6 @@ packages:
|
||||
resolution: {integrity: sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==}
|
||||
engines: {node: '>= 0.6'}
|
||||
|
||||
node-domexception@1.0.0:
|
||||
resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==}
|
||||
engines: {node: '>=10.5.0'}
|
||||
|
||||
node-fetch-native@1.6.4:
|
||||
resolution: {integrity: sha512-IhOigYzAKHd244OC0JIMIUrjzctirCmPkaIfhDeGcEETWof5zKYUW7e7MYvChGWh/4CJeXEgsRyGzuF334rOOQ==}
|
||||
|
||||
@@ -5032,15 +5011,6 @@ packages:
|
||||
resolution: {integrity: sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
openai@4.75.0:
|
||||
resolution: {integrity: sha512-8cWaK3td0qLspaflKWD6AvpQnl0gynWFbHg7sMAgiu//F20I4GJlCCpllDrECO6WFSuY8HXJj8gji3urw2BGGg==}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
zod: ^3.23.8
|
||||
peerDependenciesMeta:
|
||||
zod:
|
||||
optional: true
|
||||
|
||||
optionator@0.9.3:
|
||||
resolution: {integrity: sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==}
|
||||
engines: {node: '>= 0.8.0'}
|
||||
@@ -6201,9 +6171,6 @@ packages:
|
||||
unconfig@0.6.0:
|
||||
resolution: {integrity: sha512-4C67J0nIF2QwSXty2kW3zZx1pMZ3iXabylvJWWgHybWVUcMf9pxwsngoQt0gC+AVstRywFqrRBp3qOXJayhpOw==}
|
||||
|
||||
undici-types@5.26.5:
|
||||
resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==}
|
||||
|
||||
undici-types@6.20.0:
|
||||
resolution: {integrity: sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==}
|
||||
|
||||
@@ -6629,10 +6596,6 @@ packages:
|
||||
wbuf@1.7.3:
|
||||
resolution: {integrity: sha512-O84QOnr0icsbFGLS0O3bI5FswxzRr8/gHwWkDlQFskhSPryQXvrTMxjxGP4+iWYoauLoBvfDpkrOauZ+0iZpDA==}
|
||||
|
||||
web-streams-polyfill@4.0.0-beta.3:
|
||||
resolution: {integrity: sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==}
|
||||
engines: {node: '>= 14'}
|
||||
|
||||
webidl-conversions@3.0.1:
|
||||
resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}
|
||||
|
||||
@@ -8727,19 +8690,10 @@ snapshots:
|
||||
|
||||
'@types/ms@0.7.34': {}
|
||||
|
||||
'@types/node-fetch@2.6.12':
|
||||
dependencies:
|
||||
'@types/node': 22.10.1
|
||||
form-data: 4.0.0
|
||||
|
||||
'@types/node-forge@1.3.11':
|
||||
dependencies:
|
||||
'@types/node': 22.10.1
|
||||
|
||||
'@types/node@18.19.67':
|
||||
dependencies:
|
||||
undici-types: 5.26.5
|
||||
|
||||
'@types/node@22.10.1':
|
||||
dependencies:
|
||||
undici-types: 6.20.0
|
||||
@@ -9568,15 +9522,19 @@ snapshots:
|
||||
|
||||
'@webgpu/types@0.1.51': {}
|
||||
|
||||
'@xsai/shared-chat-completion@0.0.14':
|
||||
'@xsai/model@0.0.16':
|
||||
dependencies:
|
||||
'@xsai/shared': 0.0.14
|
||||
'@xsai/shared': 0.0.16
|
||||
|
||||
'@xsai/shared@0.0.14': {}
|
||||
|
||||
'@xsai/stream-text@0.0.14':
|
||||
'@xsai/shared-chat-completion@0.0.16':
|
||||
dependencies:
|
||||
'@xsai/shared-chat-completion': 0.0.14
|
||||
'@xsai/shared': 0.0.16
|
||||
|
||||
'@xsai/shared@0.0.16': {}
|
||||
|
||||
'@xsai/stream-text@0.0.16':
|
||||
dependencies:
|
||||
'@xsai/shared-chat-completion': 0.0.16
|
||||
|
||||
abort-controller@3.0.0:
|
||||
dependencies:
|
||||
@@ -9604,10 +9562,6 @@ snapshots:
|
||||
- supports-color
|
||||
optional: true
|
||||
|
||||
agentkeepalive@4.5.0:
|
||||
dependencies:
|
||||
humanize-ms: 1.2.1
|
||||
|
||||
ajv@6.12.6:
|
||||
dependencies:
|
||||
fast-deep-equal: 3.1.3
|
||||
@@ -10995,8 +10949,6 @@ snapshots:
|
||||
dependencies:
|
||||
is-callable: 1.2.7
|
||||
|
||||
form-data-encoder@1.7.2: {}
|
||||
|
||||
form-data-encoder@4.0.2: {}
|
||||
|
||||
form-data@4.0.0:
|
||||
@@ -11005,11 +10957,6 @@ snapshots:
|
||||
combined-stream: 1.0.8
|
||||
mime-types: 2.1.35
|
||||
|
||||
formdata-node@4.4.1:
|
||||
dependencies:
|
||||
node-domexception: 1.0.0
|
||||
web-streams-polyfill: 4.0.0-beta.3
|
||||
|
||||
formdata-node@6.0.3: {}
|
||||
|
||||
forwarded@0.2.0: {}
|
||||
@@ -11298,10 +11245,6 @@ snapshots:
|
||||
|
||||
human-signals@8.0.0: {}
|
||||
|
||||
humanize-ms@1.2.1:
|
||||
dependencies:
|
||||
ms: 2.1.3
|
||||
|
||||
iconv-lite@0.4.24:
|
||||
dependencies:
|
||||
safer-buffer: 2.1.2
|
||||
@@ -12184,8 +12127,6 @@ snapshots:
|
||||
|
||||
negotiator@0.6.3: {}
|
||||
|
||||
node-domexception@1.0.0: {}
|
||||
|
||||
node-fetch-native@1.6.4: {}
|
||||
|
||||
node-fetch@2.7.0:
|
||||
@@ -12300,20 +12241,6 @@ snapshots:
|
||||
is-docker: 2.2.1
|
||||
is-wsl: 2.2.0
|
||||
|
||||
openai@4.75.0(zod@3.23.8):
|
||||
dependencies:
|
||||
'@types/node': 18.19.67
|
||||
'@types/node-fetch': 2.6.12
|
||||
abort-controller: 3.0.0
|
||||
agentkeepalive: 4.5.0
|
||||
form-data-encoder: 1.7.2
|
||||
formdata-node: 4.4.1
|
||||
node-fetch: 2.7.0
|
||||
optionalDependencies:
|
||||
zod: 3.23.8
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
|
||||
optionator@0.9.3:
|
||||
dependencies:
|
||||
'@aashutoshrathi/word-wrap': 1.2.6
|
||||
@@ -13560,8 +13487,6 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
undici-types@5.26.5: {}
|
||||
|
||||
undici-types@6.20.0: {}
|
||||
|
||||
undici@5.28.4:
|
||||
@@ -14122,8 +14047,6 @@ snapshots:
|
||||
dependencies:
|
||||
minimalistic-assert: 1.0.1
|
||||
|
||||
web-streams-polyfill@4.0.0-beta.3: {}
|
||||
|
||||
webidl-conversions@3.0.1: {}
|
||||
|
||||
webidl-conversions@4.0.2: {}
|
||||
|
||||
Reference in New Issue
Block a user