- 新增 qianfan 服务商配置(config.js) - DeepSeekAPI 支持动态 model 和 appId 参数 - 千帆 API 需要额外的 appid header - 更新所有 API 调用点传递完整配置 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
95 lines
2.8 KiB
JavaScript
95 lines
2.8 KiB
JavaScript
// 环境变量配置
|
|
// 模型服务商配置列表
|
|
export const modelProviders = {
|
|
deepseek: {
|
|
id: 'deepseek',
|
|
name: 'DeepSeek',
|
|
description: '深度求索',
|
|
apiUrl: import.meta.env.VITE_DEEPSEEK_API_URL || 'https://api.deepseek.com/chat/completions',
|
|
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',
|
|
description: 'GPT 系列',
|
|
apiUrl: import.meta.env.VITE_OPENAI_API_URL || 'https://api.openai.com/v1/chat/completions',
|
|
apiKey: import.meta.env.VITE_OPENAI_API_KEY || '',
|
|
model: import.meta.env.VITE_OPENAI_MODEL || 'gpt-4o'
|
|
},
|
|
claude: {
|
|
id: 'claude',
|
|
name: 'Claude',
|
|
description: 'Anthropic Claude',
|
|
apiUrl: import.meta.env.VITE_CLAUDE_API_URL || 'https://api.anthropic.com/v1/messages',
|
|
apiKey: import.meta.env.VITE_CLAUDE_API_KEY || '',
|
|
model: import.meta.env.VITE_CLAUDE_MODEL || 'claude-3-5-sonnet'
|
|
},
|
|
custom: {
|
|
id: 'custom',
|
|
name: '自定义',
|
|
description: '自定义 API 端点',
|
|
apiUrl: import.meta.env.VITE_CUSTOM_API_URL || '',
|
|
apiKey: import.meta.env.VITE_CUSTOM_API_KEY || '',
|
|
model: import.meta.env.VITE_CUSTOM_MODEL || ''
|
|
}
|
|
}
|
|
|
|
// 获取已配置的服务商列表(有 API Key 的)
|
|
export const getConfiguredProviders = () => {
|
|
return Object.values(modelProviders).filter(p => p.apiKey && p.apiKey.length > 0)
|
|
}
|
|
|
|
// 获取默认服务商
|
|
export const getDefaultProvider = () => {
|
|
const configured = getConfiguredProviders()
|
|
return configured.length > 0 ? configured[0] : modelProviders.deepseek
|
|
}
|
|
|
|
// 兼容旧版配置
|
|
export const config = {
|
|
// 向后兼容:使用第一个已配置的服务商
|
|
get apiUrl() {
|
|
return getDefaultProvider().apiUrl
|
|
},
|
|
get apiKey() {
|
|
return getDefaultProvider().apiKey
|
|
},
|
|
|
|
// 应用配置
|
|
appVersion: '1.0.0',
|
|
isDev: import.meta.env.DEV,
|
|
mode: import.meta.env.MODE
|
|
}
|
|
|
|
// 验证必需的环境变量
|
|
export const validateConfig = () => {
|
|
const errors = []
|
|
const configured = getConfiguredProviders()
|
|
|
|
if (configured.length === 0) {
|
|
errors.push('未配置任何模型服务商的 API Key')
|
|
}
|
|
|
|
return errors
|
|
}
|
|
|
|
// 获取配置摘要(用于调试)
|
|
export const getConfigSummary = () => {
|
|
return {
|
|
configuredProviders: getConfiguredProviders().map(p => p.name),
|
|
defaultProvider: getDefaultProvider().name,
|
|
mode: config.mode,
|
|
isDev: config.isDev
|
|
}
|
|
}
|