(provider: 'qwen' | 'volcengine', apiKey?: string)
| 161 | * 验证API密钥是否存在 |
| 162 | */ |
| 163 | export function validateApiKey(provider: 'qwen' | 'volcengine', apiKey?: string): string { |
| 164 | // 优先使用传入的apiKey |
| 165 | if (apiKey) { |
| 166 | return apiKey; |
| 167 | } |
| 168 | |
| 169 | // 然后检查环境变量 |
| 170 | const config = getProviderConfig(provider); |
| 171 | if (config.apiKey) { |
| 172 | return config.apiKey; |
| 173 | } |
| 174 | |
| 175 | // 如果都没有,抛出错误 |
| 176 | throw new Error( |
| 177 | `${provider} API密钥未配置。请通过以下方式之一提供API密钥:\n` + |
| 178 | `1. 使用 --api-key 参数\n` + |
| 179 | `2. 设置环境变量 ${provider.toUpperCase()}_API_KEY\n` + |
| 180 | `3. 在 .env 文件中配置` |
| 181 | ); |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * 模型说明映射 |
no test coverage detected