// 环境变量配置 // 模型服务商配置列表 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 } }