fix serverUrl bug

This commit is contained in:
IndieKKY
2025-03-06 18:26:11 +08:00
parent ce2a2da6f5
commit 4896722d1f
3 changed files with 6 additions and 12 deletions

View File

@@ -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',

View File

@@ -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上限大'

View File

@@ -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