refactor: use Nuxt 4 directory structure

This commit is contained in:
AnotiaWang
2025-02-28 16:16:02 +08:00
parent 7a87ed5def
commit c45d75fad2
31 changed files with 33 additions and 28 deletions

View File

@ -0,0 +1,46 @@
import { createDeepSeek } from '@ai-sdk/deepseek'
import { createOpenRouter } from '@openrouter/ai-sdk-provider'
import { createOpenAI } from '@ai-sdk/openai'
import {
extractReasoningMiddleware,
wrapLanguageModel,
type LanguageModelV1,
} from 'ai'
export const useAiModel = () => {
const { config, aiApiBase } = useConfigStore()
let model: LanguageModelV1
if (config.ai.provider === 'openrouter') {
const openRouter = createOpenRouter({
apiKey: config.ai.apiKey,
baseURL: aiApiBase,
})
model = openRouter(config.ai.model, {
includeReasoning: true,
})
} else if (
config.ai.provider === 'deepseek' ||
config.ai.provider === 'siliconflow' ||
// Special case if model name includes 'deepseek'
// This ensures compatibilty with providers like Siliconflow
config.ai.model?.toLowerCase().includes('deepseek')
) {
const deepSeek = createDeepSeek({
apiKey: config.ai.apiKey,
baseURL: aiApiBase,
})
model = deepSeek(config.ai.model)
} else {
const openai = createOpenAI({
apiKey: config.ai.apiKey,
baseURL: aiApiBase,
})
model = openai(config.ai.model)
}
return wrapLanguageModel({
model,
middleware: extractReasoningMiddleware({ tagName: 'think' }),
})
}