diff --git a/src/api/deepseek.js b/src/api/deepseek.js index 92c75f4..3f96750 100644 --- a/src/api/deepseek.js +++ b/src/api/deepseek.js @@ -4,25 +4,35 @@ class DeepSeekAPI { constructor(config) { this.baseURL = config.url this.apiKey = config.key - console.log('DeepSeekAPI 已初始化:', { baseURL: this.baseURL }) + this.model = config.model || 'deepseek-chat' + this.appId = config.appId || '' // 千帆大模型需要 + console.log('DeepSeekAPI 已初始化:', { baseURL: this.baseURL, model: this.model }) } async _streamRequest(messages, options = {}, onContent) { - const authHeader = this.apiKey.trim().startsWith('Bearer ') - ? this.apiKey.trim() + const authHeader = this.apiKey.trim().startsWith('Bearer ') + ? this.apiKey.trim() : `Bearer ${this.apiKey.trim()}`; + // 构建 headers + const headers = { + 'Content-Type': 'application/json', + 'Authorization': authHeader + } + + // 千帆大模型需要 appid header + if (this.appId) { + headers['appid'] = this.appId + } + console.log('DeepSeekAPI: Starting stream request...', { messagesLength: messages.length }) try { const response = await fetch(this.baseURL, { method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': authHeader - }, + headers, body: JSON.stringify({ - model: 'deepseek-chat', + model: this.model, messages, stream: true, ...options diff --git a/src/stores/app.js b/src/stores/app.js index dd1518f..6a22607 100644 --- a/src/stores/app.js +++ b/src/stores/app.js @@ -119,7 +119,12 @@ export const useAppStore = defineStore('app', () => { ref.isAnalyzing = true try { - const api = new DeepSeekAPI({ url: apiUrl.value, key: apiKey.value }) + const api = new DeepSeekAPI({ + url: apiUrl.value, + key: apiKey.value, + model: currentProvider.value.model, + appId: currentProvider.value.appId + }) let fullTags = '' console.log(`Store: Analyzing style for reference [${index}]...`) @@ -152,7 +157,12 @@ export const useAppStore = defineStore('app', () => { generationStage.value = 'thinking' try { - const api = new DeepSeekAPI({ url: apiUrl.value, key: apiKey.value }) + const api = new DeepSeekAPI({ + url: apiUrl.value, + key: apiKey.value, + model: currentProvider.value.model, + appId: currentProvider.value.appId + }) const streamParser = createStreamParser() // 构建 Prompt(XML 结构化数据) @@ -332,7 +342,12 @@ ${draft} } try { - const api = new DeepSeekAPI({ url: apiUrl.value, key: apiKey.value }) + const api = new DeepSeekAPI({ + url: apiUrl.value, + key: apiKey.value, + model: currentProvider.value.model, + appId: currentProvider.value.appId + }) let fullContent = '' console.log('Store: 调用 API 分析文章...') @@ -453,7 +468,12 @@ ${draft} // 通用 API 调用方法 const callApi = async (prompt, onContent, options = {}) => { - const api = new DeepSeekAPI({ url: apiUrl.value, key: apiKey.value }) + const api = new DeepSeekAPI({ + url: apiUrl.value, + key: apiKey.value, + model: currentProvider.value.model, + appId: currentProvider.value.appId + }) return api.generateContent(prompt, onContent, options) } @@ -645,7 +665,12 @@ ${draft} section.generatedContent = '' try { - const api = new DeepSeekAPI({ url: apiUrl.value, key: apiKey.value }) + const api = new DeepSeekAPI({ + url: apiUrl.value, + key: apiKey.value, + model: currentProvider.value.model, + appId: currentProvider.value.appId + }) const streamParser = createStreamParser() // 构建上文内容,保持连贯性 diff --git a/src/utils/config.js b/src/utils/config.js index 6c42513..88c54ea 100644 --- a/src/utils/config.js +++ b/src/utils/config.js @@ -9,6 +9,15 @@ export const modelProviders = { apiKey: import.meta.env.VITE_DEEPSEEK_API_KEY || '', model: import.meta.env.VITE_DEEPSEEK_MODEL || 'deepseek-chat' }, + qianfan: { + id: 'qianfan', + name: '千帆大模型', + description: '百度文心一言', + apiUrl: import.meta.env.VITE_QIANFAN_API_URL || 'https://qianfan.baidubce.com/v2/chat/completions', + apiKey: import.meta.env.VITE_QIANFAN_API_KEY || '', + appId: import.meta.env.VITE_QIANFAN_APP_ID || '', + model: import.meta.env.VITE_QIANFAN_MODEL || 'ernie-4.0-8k' + }, openai: { id: 'openai', name: 'OpenAI',