fix(stage-web|stage-tamagotchi): locked to openrouter-ai

This commit is contained in:
Neko Ayaka
2025-03-17 01:45:26 +08:00
parent 0463fbb7d1
commit 8e1ed7ec19
5 changed files with 42 additions and 8 deletions
+11 -2
View File
@@ -71,7 +71,7 @@ export const useChatStore = defineStore('chat', () => {
const streamingMessage = ref<AssistantMessage>({ role: 'assistant', content: '' })
async function send(sendingMessage: string, options: { model: string, chatProvider: ChatProvider }) {
async function send(sendingMessage: string, options: { model: string, chatProvider: ChatProvider, providerConfig?: Record<string, unknown> }) {
try {
sending.value = true
@@ -95,7 +95,16 @@ export const useChatStore = defineStore('chat', () => {
await hook(sendingMessage)
}
const res = await stream(options.model, options.chatProvider, newMessages as Message[])
const headersArray = options.providerConfig?.headers as { key: string, value: string }[] | undefined
const headers = headersArray
?.filter(h => h.key && h.value)
.reduce((acc, curr) => {
acc[curr.key] = curr.value
return acc
}, {} as Record<string, string>)
const res = await stream(options.model, options.chatProvider, newMessages as Message[], { headers })
for (const hook of onAfterSendHooks.value) {
await hook(sendingMessage)
+6 -1
View File
@@ -6,13 +6,18 @@ import { streamText } from '@xsai/stream-text'
import { defineStore } from 'pinia'
export const useLLM = defineStore('llm', () => {
async function stream(model: string, chatProvider: ChatProvider, messages: Message[]) {
async function stream(model: string, chatProvider: ChatProvider, messages: Message[], options?: {
headers?: Record<string, string>
}) {
const headers = options?.headers
return await streamText({
...chatProvider.chat(model),
messages,
streamOptions: {
usage: true,
},
headers,
})
}