From cade054e1f8fab9c9a211e29de5d21c44f71ae0e Mon Sep 17 00:00:00 2001 From: josc146 Date: Wed, 7 Aug 2024 20:57:07 +0800 Subject: [PATCH] WIP, custom API Modes --- src/background/index.mjs | 4 ++-- src/popup/sections/GeneralPart.jsx | 23 ++++++++--------------- src/services/wrappers.mjs | 2 +- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/background/index.mjs b/src/background/index.mjs index 00bab8c..e2ef85b 100644 --- a/src/background/index.mjs +++ b/src/background/index.mjs @@ -83,7 +83,7 @@ async function executeApi(session, port, config) { port, session.question, session, - config.customModelApiUrl, + config.customModelApiUrl.trim() || 'http://localhost:8000/v1/chat/completions', config.customApiKey, config.customModelName, ) @@ -92,7 +92,7 @@ async function executeApi(session, port, config) { port, session.question, session, - session.apiMode.customUrl, + session.apiMode.customUrl.trim() || 'http://localhost:8000/v1/chat/completions', session.apiMode.apiKey, session.apiMode.customName, ) diff --git a/src/popup/sections/GeneralPart.jsx b/src/popup/sections/GeneralPart.jsx index 3cbff3f..3db270c 100644 --- a/src/popup/sections/GeneralPart.jsx +++ b/src/popup/sections/GeneralPart.jsx @@ -88,6 +88,10 @@ async function checkBilling(apiKey, apiUrl) { } } +function isUsingSpecialCustomModel(configOrSession) { + return isUsingCustomModel(configOrSession) && !configOrSession.apiMode +} + export function GeneralPart({ config, updateConfig, setTabIndex }) { const { t, i18n } = useTranslation() const [balance, setBalance] = useState(null) @@ -173,7 +177,7 @@ export function GeneralPart({ config, updateConfig, setTabIndex }) { style={ isUsingOpenAiApiModel(config) || isUsingMultiModeModel(config) || - isUsingCustomModel(config) || + isUsingSpecialCustomModel(config) || isUsingAzureOpenAiApiModel(config) || isUsingClaudeApiModel(config) || isUsingMoonshotApiModel(config) @@ -255,7 +259,7 @@ export function GeneralPart({ config, updateConfig, setTabIndex }) { )} )} - {isUsingCustomModel(config) && ( + {isUsingSpecialCustomModel(config) && ( )} - {isUsingCustomModel(config) && ( + {isUsingSpecialCustomModel(config) && ( )} - {isUsingCustomModel(config) && ( + {isUsingSpecialCustomModel(config) && ( )} - {isUsingAzureOpenAiApiModel(config) && ( - { - const deploymentName = e.target.value - updateConfig({ azureDeploymentName: deploymentName }) - }} - /> - )} {isUsingGithubThirdPartyApiModel(config) && (