feat: 集成千帆大模型(百度文心一言)支持

- 新增 qianfan 服务商配置(config.js)
- DeepSeekAPI 支持动态 model 和 appId 参数
- 千帆 API 需要额外的 appid header
- 更新所有 API 调用点传递完整配置

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
empty
2026-01-12 04:10:50 +08:00
parent 81e597ccdc
commit 823ff9c96d
3 changed files with 57 additions and 13 deletions

View File

@@ -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

View File

@@ -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()
// 构建 PromptXML 结构化数据)
@@ -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()
// 构建上文内容,保持连贯性

View File

@@ -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',