Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use @xsai/model instead of openai #1

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/stage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 2 additions & 4 deletions packages/stage/src/components/MainStage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
11 changes: 4 additions & 7 deletions packages/stage/src/stores/llm.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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`)) {
Expand Down
127 changes: 25 additions & 102 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading