From 8c80cc00b3d4fe90bb8dd945840e21bcd7b01451 Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Fri, 26 Jul 2024 10:34:55 +0800 Subject: [PATCH] feat(provider.ts): add API endpoint configuration for each provider with editable status --- src/renderer/src/config/provider.ts | 52 +++++++++++++++++++ src/renderer/src/i18n/index.ts | 2 + .../settings/components/ProviderSetting.tsx | 33 +++++++----- 3 files changed, 73 insertions(+), 14 deletions(-) diff --git a/src/renderer/src/config/provider.ts b/src/renderer/src/config/provider.ts index cb8832e6..000a5b79 100644 --- a/src/renderer/src/config/provider.ts +++ b/src/renderer/src/config/provider.ts @@ -85,6 +85,10 @@ export function getModelLogo(modelId: string) { export const PROVIDER_CONFIG = { openai: { + api: { + url: 'https://api.openai.com', + editable: true + }, websites: { official: 'https://openai.com/', apiKey: 'https://platform.openai.com/api-keys', @@ -93,6 +97,10 @@ export const PROVIDER_CONFIG = { } }, silicon: { + api: { + url: 'https://cloud.siliconflow.cn', + editable: false + }, websites: { official: 'https://www.siliconflow.cn/', apiKey: 'https://cloud.siliconflow.cn/account/ak', @@ -101,6 +109,10 @@ export const PROVIDER_CONFIG = { } }, deepseek: { + api: { + url: 'https://api.deepseek.com', + editable: false + }, websites: { official: 'https://deepseek.com/', apiKey: 'https://platform.deepseek.com/api_keys', @@ -109,6 +121,10 @@ export const PROVIDER_CONFIG = { } }, yi: { + api: { + url: 'https://api.lingyiwanwu.com', + editable: false + }, websites: { official: 'https://platform.lingyiwanwu.com/', apiKey: 'https://platform.lingyiwanwu.com/apikeys', @@ -117,6 +133,10 @@ export const PROVIDER_CONFIG = { } }, zhipu: { + api: { + url: 'https://open.bigmodel.cn/api/paas/v4/', + editable: false + }, websites: { official: 'https://open.bigmodel.cn/', apiKey: 'https://open.bigmodel.cn/usercenter/apikeys', @@ -125,6 +145,10 @@ export const PROVIDER_CONFIG = { } }, moonshot: { + api: { + url: 'https://api.moonshot.cn', + editable: false + }, websites: { official: 'https://moonshot.ai/', apiKey: 'https://platform.moonshot.cn/console/api-keys', @@ -133,6 +157,10 @@ export const PROVIDER_CONFIG = { } }, baichuan: { + api: { + url: 'https://api.baichuan-ai.com', + editable: false + }, websites: { official: 'https://www.baichuan-ai.com/', apiKey: 'https://platform.baichuan-ai.com/console/apikey', @@ -141,6 +169,10 @@ export const PROVIDER_CONFIG = { } }, dashscope: { + api: { + url: 'https://dashscope.aliyuncs.com/compatible-mode/v1/', + editable: false + }, websites: { official: 'https://dashscope.aliyun.com/', apiKey: 'https://help.aliyun.com/zh/dashscope/developer-reference/acquisition-and-configuration-of-api-key', @@ -149,6 +181,10 @@ export const PROVIDER_CONFIG = { } }, openrouter: { + api: { + url: 'https://openrouter.ai/api/v1/', + editable: false + }, websites: { official: 'https://openrouter.ai/', apiKey: 'https://openrouter.ai/settings/keys', @@ -157,6 +193,10 @@ export const PROVIDER_CONFIG = { } }, groq: { + api: { + url: 'https://api.groq.com/openai', + editable: false + }, websites: { official: 'https://groq.com/', apiKey: 'https://console.groq.com/keys', @@ -165,6 +205,10 @@ export const PROVIDER_CONFIG = { } }, ollama: { + api: { + url: 'http://localhost:11434/v1/', + editable: true + }, websites: { official: 'https://ollama.com/', docs: 'https://github.com/ollama/ollama/tree/main/docs', @@ -172,6 +216,10 @@ export const PROVIDER_CONFIG = { } }, anthropic: { + api: { + url: 'https://api.anthropic.com/', + editable: false + }, websites: { official: 'https://anthropic.com/', apiKey: 'https://console.anthropic.com/settings/keys', @@ -180,6 +228,10 @@ export const PROVIDER_CONFIG = { } }, aihubmix: { + api: { + url: 'https://aihubmix.com', + editable: false + }, websites: { official: 'https://aihubmix.com/', apiKey: 'https://aihubmix.com/token', diff --git a/src/renderer/src/i18n/index.ts b/src/renderer/src/i18n/index.ts index 4ccd1b35..ab46ca35 100644 --- a/src/renderer/src/i18n/index.ts +++ b/src/renderer/src/i18n/index.ts @@ -121,6 +121,7 @@ const resources = { 'provider.docs_check': 'Check', 'provider.docs_more_details': 'for more details', 'provider.search_placeholder': 'Search model id or name', + 'provider.api.url.reset': 'Reset', 'models.default_assistant_model': 'Default Assistant Model', 'models.topic_naming_model': 'Topic Naming Model', 'models.add.add_model': 'Add Model', @@ -276,6 +277,7 @@ const resources = { 'provider.docs_check': '查看', 'provider.docs_more_details': '获取更多详情', 'provider.search_placeholder': '搜索模型 ID 或名称', + 'provider.api.url.reset': '重置', 'models.default_assistant_model': '默认助手模型', 'models.topic_naming_model': '话题命名模型', 'models.add.add_model': '添加模型', diff --git a/src/renderer/src/pages/settings/components/ProviderSetting.tsx b/src/renderer/src/pages/settings/components/ProviderSetting.tsx index ac82e635..3b113f80 100644 --- a/src/renderer/src/pages/settings/components/ProviderSetting.tsx +++ b/src/renderer/src/pages/settings/components/ProviderSetting.tsx @@ -52,8 +52,13 @@ const ProviderSetting: FC = ({ provider: _provider }) => { const apiKeyWebsite = providerConfig?.websites?.apiKey const docsWebsite = providerConfig?.websites?.docs const modelsWebsite = providerConfig?.websites?.models + const configedApiHost = providerConfig?.api?.url + const apiEditable = provider.isSystem ? providerConfig?.api?.editable : true - const apiKeyDisabled = provider.id === 'ollama' + const onReset = () => { + setApiHost(configedApiHost) + updateProvider({ ...provider, apiHost: configedApiHost }) + } return ( @@ -81,15 +86,12 @@ const ProviderSetting: FC = ({ provider: _provider }) => { onChange={(e) => setApiKey(e.target.value)} onBlur={onUpdateApiKey} spellCheck={false} - disabled={apiKeyDisabled} type="password" autoFocus={provider.enabled && apiKey === ''} /> - {!apiKeyDisabled && ( - - )} + {apiKeyWebsite && ( @@ -99,13 +101,16 @@ const ProviderSetting: FC = ({ provider: _provider }) => { )} {t('settings.provider.api_host')} - setApiHost(e.target.value)} - onBlur={onUpdateApiHost} - /> + + setApiHost(e.target.value)} + onBlur={onUpdateApiHost} + disabled={!apiEditable} + /> + {apiEditable && } + {t('common.models')} {Object.keys(modelGroups).map((group) => (