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:
@@ -4,7 +4,9 @@ class DeepSeekAPI {
|
|||||||
constructor(config) {
|
constructor(config) {
|
||||||
this.baseURL = config.url
|
this.baseURL = config.url
|
||||||
this.apiKey = config.key
|
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) {
|
async _streamRequest(messages, options = {}, onContent) {
|
||||||
@@ -12,17 +14,25 @@ class DeepSeekAPI {
|
|||||||
? this.apiKey.trim()
|
? this.apiKey.trim()
|
||||||
: `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 })
|
console.log('DeepSeekAPI: Starting stream request...', { messagesLength: messages.length })
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(this.baseURL, {
|
const response = await fetch(this.baseURL, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers,
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Authorization': authHeader
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
model: 'deepseek-chat',
|
model: this.model,
|
||||||
messages,
|
messages,
|
||||||
stream: true,
|
stream: true,
|
||||||
...options
|
...options
|
||||||
|
|||||||
@@ -119,7 +119,12 @@ export const useAppStore = defineStore('app', () => {
|
|||||||
|
|
||||||
ref.isAnalyzing = true
|
ref.isAnalyzing = true
|
||||||
try {
|
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 = ''
|
let fullTags = ''
|
||||||
|
|
||||||
console.log(`Store: Analyzing style for reference [${index}]...`)
|
console.log(`Store: Analyzing style for reference [${index}]...`)
|
||||||
@@ -152,7 +157,12 @@ export const useAppStore = defineStore('app', () => {
|
|||||||
generationStage.value = 'thinking'
|
generationStage.value = 'thinking'
|
||||||
|
|
||||||
try {
|
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()
|
const streamParser = createStreamParser()
|
||||||
|
|
||||||
// 构建 Prompt(XML 结构化数据)
|
// 构建 Prompt(XML 结构化数据)
|
||||||
@@ -332,7 +342,12 @@ ${draft}
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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 = ''
|
let fullContent = ''
|
||||||
|
|
||||||
console.log('Store: 调用 API 分析文章...')
|
console.log('Store: 调用 API 分析文章...')
|
||||||
@@ -453,7 +468,12 @@ ${draft}
|
|||||||
|
|
||||||
// 通用 API 调用方法
|
// 通用 API 调用方法
|
||||||
const callApi = async (prompt, onContent, options = {}) => {
|
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)
|
return api.generateContent(prompt, onContent, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -645,7 +665,12 @@ ${draft}
|
|||||||
section.generatedContent = ''
|
section.generatedContent = ''
|
||||||
|
|
||||||
try {
|
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()
|
const streamParser = createStreamParser()
|
||||||
|
|
||||||
// 构建上文内容,保持连贯性
|
// 构建上文内容,保持连贯性
|
||||||
|
|||||||
@@ -9,6 +9,15 @@ export const modelProviders = {
|
|||||||
apiKey: import.meta.env.VITE_DEEPSEEK_API_KEY || '',
|
apiKey: import.meta.env.VITE_DEEPSEEK_API_KEY || '',
|
||||||
model: import.meta.env.VITE_DEEPSEEK_MODEL || 'deepseek-chat'
|
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: {
|
openai: {
|
||||||
id: 'openai',
|
id: 'openai',
|
||||||
name: 'OpenAI',
|
name: 'OpenAI',
|
||||||
|
|||||||
Reference in New Issue
Block a user