From 4896722d1fb4a389b6340a9b166345026fe27e44 Mon Sep 17 00:00:00 2001 From: IndieKKY Date: Thu, 6 Mar 2025 18:26:11 +0800 Subject: [PATCH] fix serverUrl bug --- src/chrome/openaiService.ts | 6 +++++- src/consts/const.ts | 2 +- src/utils/bizUtil.ts | 10 ---------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/chrome/openaiService.ts b/src/chrome/openaiService.ts index 84c0233..2c8614c 100644 --- a/src/chrome/openaiService.ts +++ b/src/chrome/openaiService.ts @@ -7,13 +7,17 @@ const getServerUrl = (serverUrl?: string) => { if (serverUrl.endsWith('/')) { serverUrl = serverUrl.slice(0, -1) } + //如果serverUrl不以/vxxx结尾,则添加/v1 + if (!/\/v\d+$/.test(serverUrl.toLowerCase())) { + serverUrl += '/v1' + } return serverUrl } export const handleChatCompleteTask = async (task: Task) => { const data = task.def.data const serverUrl = getServerUrl(task.def.serverUrl) - const resp = await fetch(`${serverUrl}/v1/chat/completions`, { + const resp = await fetch(`${serverUrl}/chat/completions`, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/src/consts/const.ts b/src/consts/const.ts index 2abe27d..9decfd8 100644 --- a/src/consts/const.ts +++ b/src/consts/const.ts @@ -265,7 +265,7 @@ export const SUMMARIZE_THRESHOLD = 100 export const SUMMARIZE_LANGUAGE_DEFAULT = 'cn' export const SUMMARIZE_ALL_THRESHOLD = 5 export const ASK_ENABLED_DEFAULT = true -export const DEFAULT_SERVER_URL_OPENAI = 'https://api.openai.com' +export const DEFAULT_SERVER_URL_OPENAI = 'https://api.openai.com/v1' export const CUSTOM_MODEL_TOKENS = 16385 export const MODEL_TIP = '推荐gpt-4o-mini,能力强,价格低,token上限大' diff --git a/src/utils/bizUtil.ts b/src/utils/bizUtil.ts index f3b4a14..13edf96 100644 --- a/src/utils/bizUtil.ts +++ b/src/utils/bizUtil.ts @@ -119,16 +119,6 @@ export const getSummaryStr = (summary: Summary) => { return s } -export const getServerUrl = (serverUrl?: string) => { - if (!serverUrl) { - return 'https://api.openai.com' - } - if (serverUrl.endsWith('/')) { - serverUrl = serverUrl.slice(0, -1) - } - return serverUrl -} - export const getModel = (envData: EnvData) => { if (envData.model === 'custom') { return envData.customModel