fix(config): add missing provider env mappings
Enable Anthropic env-based default model creation and align provider lists/matching across desktop logs, MCP selection, and docs.
This commit is contained in:
1 parent
b96f2d06e7
commit
c916d9eef3
10 files changed
+64
-11
No files matched your search
@@ -193,7 +193,7 @@ MCP Server 需要配置 API 密钥才能正常工作。主要的 MCP 专属配
|
||||
|
||||
```bash
|
||||
# MCP 服务器配置
|
||||
MCP_DEFAULT_MODEL_PROVIDER=openai # 可选值:openai, gemini, deepseek, siliconflow, zhipu, custom
|
||||
MCP_DEFAULT_MODEL_PROVIDER=openai # 可选值:openai, gemini, anthropic, deepseek, siliconflow, zhipu, dashscope, openrouter, modelscope, custom
|
||||
MCP_LOG_LEVEL=info # 日志级别
|
||||
```
|
||||
|
||||
@@ -469,4 +469,4 @@ xattr -rd com.apple.quarantine ~/Downloads/PromptOptimizer-*.dmg
|
||||
|
||||
- 提交 Issue
|
||||
- 发起 Pull Request
|
||||
- 加入讨论组
|
||||
- 加入讨论组
|
||||
+2
-2
@@ -196,7 +196,7 @@ MCP Server requires API key configuration to function properly. Main MCP-specifi
|
||||
|
||||
```bash
|
||||
# MCP Server Configuration
|
||||
MCP_DEFAULT_MODEL_PROVIDER=openai # Options: openai, gemini, deepseek, siliconflow, zhipu, custom
|
||||
MCP_DEFAULT_MODEL_PROVIDER=openai # Options: openai, gemini, anthropic, deepseek, siliconflow, zhipu, dashscope, openrouter, modelscope, custom
|
||||
MCP_LOG_LEVEL=info # Log level
|
||||
```
|
||||
|
||||
@@ -471,4 +471,4 @@ If this project is helpful to you, please consider giving it a Star ⭐️
|
||||
|
||||
- Submit an Issue
|
||||
- Create a Pull Request
|
||||
- Join the discussion group
|
||||
- Join the discussion group
|
||||
@@ -72,7 +72,7 @@ VITE_CUSTOM_API_MODEL=qwen2.5:0.5b
|
||||
|
||||
```bash
|
||||
# 首选模型提供商(当配置了多个 API 密钥时)
|
||||
# 可选值:openai, gemini, deepseek, siliconflow, zhipu, custom
|
||||
# 可选值:openai, gemini, anthropic, deepseek, siliconflow, zhipu, dashscope, openrouter, modelscope, custom
|
||||
MCP_DEFAULT_MODEL_PROVIDER=openai
|
||||
|
||||
# 日志级别(可选,默认 debug)
|
||||
|
||||
@@ -72,7 +72,7 @@ VITE_CUSTOM_API_MODEL=qwen2.5:0.5b
|
||||
|
||||
```bash
|
||||
# Preferred model provider (when multiple API keys are configured)
|
||||
# Options: openai, gemini, deepseek, siliconflow, zhipu, custom
|
||||
# Options: openai, gemini, anthropic, deepseek, siliconflow, zhipu, dashscope, openrouter, modelscope, custom
|
||||
MCP_DEFAULT_MODEL_PROVIDER=openai
|
||||
|
||||
# Log level (optional, default: debug)
|
||||
|
||||
+4
-1
@@ -11,6 +11,9 @@
|
||||
# Google Gemini API 配置
|
||||
# VITE_GEMINI_API_KEY=your-gemini-api-key-here
|
||||
|
||||
# Anthropic Claude API 配置
|
||||
# VITE_ANTHROPIC_API_KEY=your-anthropic-api-key-here
|
||||
|
||||
# ===== 图像生成 API 密钥配置 =====
|
||||
# Gemini 图像生成复用 VITE_GEMINI_API_KEY(无需单独配置)
|
||||
# Seedream (Doubao) / 火山方舟 ARK API Key(任选其一变量,优先级从上到下)
|
||||
@@ -70,7 +73,7 @@
|
||||
# 以下配置仅在使用 MCP 服务器时需要
|
||||
|
||||
# 首选模型提供商(当配置了多个 API 密钥时)
|
||||
# 可选值:openai, gemini, deepseek, siliconflow, zhipu, custom, custom_<suffix>
|
||||
# 可选值:openai, gemini, anthropic, deepseek, siliconflow, zhipu, dashscope, openrouter, modelscope, custom, custom_<suffix>
|
||||
# 注意:必须与上面配置的 API 密钥对应
|
||||
# 示例:如果配置了 VITE_CUSTOM_API_KEY_qwen3,可以使用 custom_qwen3
|
||||
# MCP_DEFAULT_MODEL_PROVIDER=openai
|
||||
|
||||
@@ -76,7 +76,7 @@ VITE_CUSTOM_API_MODEL=qwen2.5:0.5b
|
||||
|
||||
```bash
|
||||
# 首选模型提供商(当配置了多个 API 密钥时)
|
||||
# 可选值:openai, gemini, deepseek, siliconflow, zhipu, custom
|
||||
# 可选值:openai, gemini, anthropic, deepseek, siliconflow, zhipu, dashscope, openrouter, modelscope, custom
|
||||
MCP_DEFAULT_MODEL_PROVIDER=openai
|
||||
|
||||
# 日志级别(可选,默认 debug)
|
||||
@@ -190,4 +190,3 @@ MCP_DEFAULT_MODEL_PROVIDER=openai # 不是 OpenAI
|
||||
2. 检查 URL 是否正确
|
||||
3. 确认防火墙设置
|
||||
4. 查看 Claude Desktop 日志
|
||||
|
||||
@@ -11,6 +11,7 @@ import { generateDynamicModels } from './model-utils';
|
||||
const PROVIDER_ENV_KEYS = {
|
||||
openai: 'VITE_OPENAI_API_KEY',
|
||||
gemini: 'VITE_GEMINI_API_KEY',
|
||||
anthropic: 'VITE_ANTHROPIC_API_KEY',
|
||||
deepseek: 'VITE_DEEPSEEK_API_KEY',
|
||||
siliconflow: 'VITE_SILICONFLOW_API_KEY',
|
||||
zhipu: 'VITE_ZHIPU_API_KEY',
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { getBuiltinModelIds, getDefaultTextModels } from '../../../src/services/model/defaults'
|
||||
import { afterAll, beforeEach, describe, expect, it } from 'vitest'
|
||||
|
||||
describe('model defaults provider env mapping', () => {
|
||||
const originalAnthropicApiKey = process.env.VITE_ANTHROPIC_API_KEY
|
||||
|
||||
beforeEach(() => {
|
||||
delete process.env.VITE_ANTHROPIC_API_KEY
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
if (originalAnthropicApiKey === undefined) {
|
||||
delete process.env.VITE_ANTHROPIC_API_KEY
|
||||
return
|
||||
}
|
||||
process.env.VITE_ANTHROPIC_API_KEY = originalAnthropicApiKey
|
||||
})
|
||||
|
||||
it('should include anthropic in builtin model ids', () => {
|
||||
const builtinModelIds = getBuiltinModelIds()
|
||||
expect(builtinModelIds).toContain('anthropic')
|
||||
})
|
||||
|
||||
it('should include anthropic config and keep it disabled when api key is empty', () => {
|
||||
const models = getDefaultTextModels()
|
||||
|
||||
expect(models.anthropic).toBeDefined()
|
||||
expect(models.anthropic.providerMeta.id).toBe('anthropic')
|
||||
expect(models.anthropic.enabled).toBe(false)
|
||||
})
|
||||
|
||||
it('should enable anthropic when VITE_ANTHROPIC_API_KEY is provided', () => {
|
||||
process.env.VITE_ANTHROPIC_API_KEY = 'test-anthropic-key'
|
||||
|
||||
const models = getDefaultTextModels()
|
||||
|
||||
expect(models.anthropic.enabled).toBe(true)
|
||||
expect(models.anthropic.connectionConfig.apiKey).toBe('test-anthropic-key')
|
||||
})
|
||||
})
|
||||
@@ -537,9 +537,13 @@ async function initializeServices() {
|
||||
const staticEnvVars = [
|
||||
'VITE_OPENAI_API_KEY',
|
||||
'VITE_GEMINI_API_KEY',
|
||||
'VITE_ANTHROPIC_API_KEY',
|
||||
'VITE_DEEPSEEK_API_KEY',
|
||||
'VITE_SILICONFLOW_API_KEY',
|
||||
'VITE_ZHIPU_API_KEY',
|
||||
'VITE_DASHSCOPE_API_KEY',
|
||||
'VITE_OPENROUTER_API_KEY',
|
||||
'VITE_MODELSCOPE_API_KEY',
|
||||
'VITE_CUSTOM_API_KEY',
|
||||
'VITE_CUSTOM_API_BASE_URL',
|
||||
'VITE_CUSTOM_API_MODEL'
|
||||
|
||||
@@ -27,9 +27,15 @@ export async function setupDefaultModel(
|
||||
|
||||
// 1. 如果指定了 preferredProvider,尝试匹配
|
||||
if (preferredProvider) {
|
||||
const normalizedPreferred = preferredProvider.toLowerCase();
|
||||
|
||||
selectedModel = availableModels.find(([key, config]) =>
|
||||
config.provider === preferredProvider.toLowerCase() ||
|
||||
config.name.toLowerCase().includes(preferredProvider.toLowerCase())
|
||||
// 直接匹配模型 key(支持 custom_<suffix>)
|
||||
key.toLowerCase() === normalizedPreferred ||
|
||||
// 匹配 provider id
|
||||
String(config.providerMeta?.id || config.modelMeta?.providerId || config.provider || '').toLowerCase() === normalizedPreferred ||
|
||||
// 兼容通过名称模糊匹配
|
||||
String(config.name || '').toLowerCase().includes(normalizedPreferred)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user