diff --git a/docSite/content/zh-cn/docs/development/upgrading/498.md b/docSite/content/zh-cn/docs/development/upgrading/498.md index 9a6209b18..29d9162e8 100644 --- a/docSite/content/zh-cn/docs/development/upgrading/498.md +++ b/docSite/content/zh-cn/docs/development/upgrading/498.md @@ -24,4 +24,6 @@ weight: 792 1. 应用列表/知识库列表,删除行权限展示问题。 2. 打开知识库搜索参数后,重排选项自动被打开。 +3. LLM json_schema 模式 API 请求格式错误。 +4. 重新训练时,图片过期索引未成功清除,导致图片会丢失。 diff --git a/packages/service/core/ai/utils.ts b/packages/service/core/ai/utils.ts index f29080177..2485a7af8 100644 --- a/packages/service/core/ai/utils.ts +++ b/packages/service/core/ai/utils.ts @@ -11,6 +11,7 @@ import type { import { getLLMModel } from './model'; import { getLLMDefaultUsage } from '@fastgpt/global/core/ai/constants'; import { getNanoid } from '@fastgpt/global/common/string/tools'; +import json5 from 'json5'; /* Count response max token @@ -54,8 +55,6 @@ type InferCompletionsBody = T extends { stream: true } export const llmCompletionsBodyFormat = ( body: T & { - response_format?: any; - json_schema?: string; stop?: string; }, model: string | LLMModelItemType @@ -65,8 +64,26 @@ export const llmCompletionsBodyFormat = ( return body as unknown as InferCompletionsBody; } - const response_format = body.response_format; - const json_schema = body.json_schema ?? undefined; + const response_format = (() => { + if (!body.response_format?.type) return undefined; + if (body.response_format.type === 'json_schema') { + try { + return { + type: 'json_schema', + json_schema: json5.parse(body.response_format?.json_schema as unknown as string) + }; + } catch (error) { + throw new Error('Json schema error'); + } + } + if (body.response_format.type) { + return { + type: body.response_format.type + }; + } + return undefined; + })(); + const stop = body.stop ?? undefined; const requestBody: T = { @@ -80,12 +97,7 @@ export const llmCompletionsBodyFormat = ( }) : undefined, ...modelData?.defaultConfig, - response_format: response_format - ? { - type: response_format, - json_schema - } - : undefined, + response_format, stop: stop?.split('|') }; diff --git a/packages/service/core/workflow/dispatch/agent/runTool/functionCall.ts b/packages/service/core/workflow/dispatch/agent/runTool/functionCall.ts index db53e8fdd..d22bbec3e 100644 --- a/packages/service/core/workflow/dispatch/agent/runTool/functionCall.ts +++ b/packages/service/core/workflow/dispatch/agent/runTool/functionCall.ts @@ -235,8 +235,10 @@ export const runToolWithFunctionCall = async ( max_tokens, top_p: aiChatTopP, stop: aiChatStopSign, - response_format: aiChatResponseFormat, - json_schema: aiChatJsonSchema + response_format: { + type: aiChatResponseFormat as any, + json_schema: aiChatJsonSchema + } }, toolModel ); diff --git a/packages/service/core/workflow/dispatch/agent/runTool/promptCall.ts b/packages/service/core/workflow/dispatch/agent/runTool/promptCall.ts index 5febe4951..441797aee 100644 --- a/packages/service/core/workflow/dispatch/agent/runTool/promptCall.ts +++ b/packages/service/core/workflow/dispatch/agent/runTool/promptCall.ts @@ -243,8 +243,10 @@ export const runToolWithPromptCall = async ( max_tokens, top_p: aiChatTopP, stop: aiChatStopSign, - response_format: aiChatResponseFormat, - json_schema: aiChatJsonSchema + response_format: { + type: aiChatResponseFormat as any, + json_schema: aiChatJsonSchema + } }, toolModel ); diff --git a/packages/service/core/workflow/dispatch/agent/runTool/toolChoice.ts b/packages/service/core/workflow/dispatch/agent/runTool/toolChoice.ts index bdda6d42d..63675edb9 100644 --- a/packages/service/core/workflow/dispatch/agent/runTool/toolChoice.ts +++ b/packages/service/core/workflow/dispatch/agent/runTool/toolChoice.ts @@ -296,8 +296,10 @@ export const runToolWithToolChoice = async ( max_tokens, top_p: aiChatTopP, stop: aiChatStopSign, - response_format: aiChatResponseFormat, - json_schema: aiChatJsonSchema + response_format: { + type: aiChatResponseFormat as any, + json_schema: aiChatJsonSchema + } }, toolModel ); diff --git a/packages/service/core/workflow/dispatch/chat/oneapi.ts b/packages/service/core/workflow/dispatch/chat/oneapi.ts index a98f3ee05..e34e9a49d 100644 --- a/packages/service/core/workflow/dispatch/chat/oneapi.ts +++ b/packages/service/core/workflow/dispatch/chat/oneapi.ts @@ -192,8 +192,10 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise): Promise): Promise { const { totalPoints, modelName } = formatModelChars2Points({ model, @@ -300,9 +302,9 @@ export const pushRerankUsage = ({ createUsage({ teamId, tmbId, - appName: modelName, + appName: i18nT('account_bill:rerank'), totalPoints, - source: UsageSourceEnum.fastgpt, + source, list: [ { moduleName: modelName,