mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-21 03:35:36 +00:00
fix: json schema parse error;fix: retraining image reset (#4757)
* i18n * fix: json schema parse error * fix: retraining image reset * update doc
This commit is contained in:
@@ -24,4 +24,6 @@ weight: 792
|
|||||||
|
|
||||||
1. 应用列表/知识库列表,删除行权限展示问题。
|
1. 应用列表/知识库列表,删除行权限展示问题。
|
||||||
2. 打开知识库搜索参数后,重排选项自动被打开。
|
2. 打开知识库搜索参数后,重排选项自动被打开。
|
||||||
|
3. LLM json_schema 模式 API 请求格式错误。
|
||||||
|
4. 重新训练时,图片过期索引未成功清除,导致图片会丢失。
|
||||||
|
|
||||||
|
@@ -11,6 +11,7 @@ import type {
|
|||||||
import { getLLMModel } from './model';
|
import { getLLMModel } from './model';
|
||||||
import { getLLMDefaultUsage } from '@fastgpt/global/core/ai/constants';
|
import { getLLMDefaultUsage } from '@fastgpt/global/core/ai/constants';
|
||||||
import { getNanoid } from '@fastgpt/global/common/string/tools';
|
import { getNanoid } from '@fastgpt/global/common/string/tools';
|
||||||
|
import json5 from 'json5';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Count response max token
|
Count response max token
|
||||||
@@ -54,8 +55,6 @@ type InferCompletionsBody<T> = T extends { stream: true }
|
|||||||
|
|
||||||
export const llmCompletionsBodyFormat = <T extends CompletionsBodyType>(
|
export const llmCompletionsBodyFormat = <T extends CompletionsBodyType>(
|
||||||
body: T & {
|
body: T & {
|
||||||
response_format?: any;
|
|
||||||
json_schema?: string;
|
|
||||||
stop?: string;
|
stop?: string;
|
||||||
},
|
},
|
||||||
model: string | LLMModelItemType
|
model: string | LLMModelItemType
|
||||||
@@ -65,8 +64,26 @@ export const llmCompletionsBodyFormat = <T extends CompletionsBodyType>(
|
|||||||
return body as unknown as InferCompletionsBody<T>;
|
return body as unknown as InferCompletionsBody<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response_format = body.response_format;
|
const response_format = (() => {
|
||||||
const json_schema = body.json_schema ?? undefined;
|
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 stop = body.stop ?? undefined;
|
||||||
|
|
||||||
const requestBody: T = {
|
const requestBody: T = {
|
||||||
@@ -80,12 +97,7 @@ export const llmCompletionsBodyFormat = <T extends CompletionsBodyType>(
|
|||||||
})
|
})
|
||||||
: undefined,
|
: undefined,
|
||||||
...modelData?.defaultConfig,
|
...modelData?.defaultConfig,
|
||||||
response_format: response_format
|
response_format,
|
||||||
? {
|
|
||||||
type: response_format,
|
|
||||||
json_schema
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
stop: stop?.split('|')
|
stop: stop?.split('|')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -235,8 +235,10 @@ export const runToolWithFunctionCall = async (
|
|||||||
max_tokens,
|
max_tokens,
|
||||||
top_p: aiChatTopP,
|
top_p: aiChatTopP,
|
||||||
stop: aiChatStopSign,
|
stop: aiChatStopSign,
|
||||||
response_format: aiChatResponseFormat,
|
response_format: {
|
||||||
json_schema: aiChatJsonSchema
|
type: aiChatResponseFormat as any,
|
||||||
|
json_schema: aiChatJsonSchema
|
||||||
|
}
|
||||||
},
|
},
|
||||||
toolModel
|
toolModel
|
||||||
);
|
);
|
||||||
|
@@ -243,8 +243,10 @@ export const runToolWithPromptCall = async (
|
|||||||
max_tokens,
|
max_tokens,
|
||||||
top_p: aiChatTopP,
|
top_p: aiChatTopP,
|
||||||
stop: aiChatStopSign,
|
stop: aiChatStopSign,
|
||||||
response_format: aiChatResponseFormat,
|
response_format: {
|
||||||
json_schema: aiChatJsonSchema
|
type: aiChatResponseFormat as any,
|
||||||
|
json_schema: aiChatJsonSchema
|
||||||
|
}
|
||||||
},
|
},
|
||||||
toolModel
|
toolModel
|
||||||
);
|
);
|
||||||
|
@@ -296,8 +296,10 @@ export const runToolWithToolChoice = async (
|
|||||||
max_tokens,
|
max_tokens,
|
||||||
top_p: aiChatTopP,
|
top_p: aiChatTopP,
|
||||||
stop: aiChatStopSign,
|
stop: aiChatStopSign,
|
||||||
response_format: aiChatResponseFormat,
|
response_format: {
|
||||||
json_schema: aiChatJsonSchema
|
type: aiChatResponseFormat as any,
|
||||||
|
json_schema: aiChatJsonSchema
|
||||||
|
}
|
||||||
},
|
},
|
||||||
toolModel
|
toolModel
|
||||||
);
|
);
|
||||||
|
@@ -192,8 +192,10 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
|
|||||||
max_tokens,
|
max_tokens,
|
||||||
top_p: aiChatTopP,
|
top_p: aiChatTopP,
|
||||||
stop: aiChatStopSign,
|
stop: aiChatStopSign,
|
||||||
response_format: aiChatResponseFormat as any,
|
response_format: {
|
||||||
json_schema: aiChatJsonSchema
|
type: aiChatResponseFormat as any,
|
||||||
|
json_schema: aiChatJsonSchema
|
||||||
|
}
|
||||||
},
|
},
|
||||||
modelConstantsData
|
modelConstantsData
|
||||||
);
|
);
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
"organization_name": "Organization name",
|
"organization_name": "Organization name",
|
||||||
"payment_method": "Payment method",
|
"payment_method": "Payment method",
|
||||||
"payway_coupon": "Redeem code",
|
"payway_coupon": "Redeem code",
|
||||||
|
"rerank": "Rerank",
|
||||||
"save": "save",
|
"save": "save",
|
||||||
"save_failed": "Save exception",
|
"save_failed": "Save exception",
|
||||||
"save_success": "Saved successfully",
|
"save_success": "Saved successfully",
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
"organization_name": "组织名称",
|
"organization_name": "组织名称",
|
||||||
"payment_method": "支付方式",
|
"payment_method": "支付方式",
|
||||||
"payway_coupon": "兑换码",
|
"payway_coupon": "兑换码",
|
||||||
|
"rerank": "结果重排",
|
||||||
"save": "保存",
|
"save": "保存",
|
||||||
"save_failed": "保存异常",
|
"save_failed": "保存异常",
|
||||||
"save_success": "保存成功",
|
"save_success": "保存成功",
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
"organization_name": "組織名稱",
|
"organization_name": "組織名稱",
|
||||||
"payment_method": "支付方式",
|
"payment_method": "支付方式",
|
||||||
"payway_coupon": "兌換碼",
|
"payway_coupon": "兌換碼",
|
||||||
|
"rerank": "結果重排",
|
||||||
"save": "儲存",
|
"save": "儲存",
|
||||||
"save_failed": "儲存異常",
|
"save_failed": "儲存異常",
|
||||||
"save_success": "儲存成功",
|
"save_success": "儲存成功",
|
||||||
|
@@ -51,7 +51,7 @@ async function handler(
|
|||||||
if (!collection.fileId) return Promise.reject('fileId is missing');
|
if (!collection.fileId) return Promise.reject('fileId is missing');
|
||||||
return {
|
return {
|
||||||
type: DatasetSourceReadTypeEnum.fileLocal,
|
type: DatasetSourceReadTypeEnum.fileLocal,
|
||||||
sourceId: collection.fileId
|
sourceId: String(collection.fileId)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (collection.type === DatasetCollectionTypeEnum.apiFile) {
|
if (collection.type === DatasetCollectionTypeEnum.apiFile) {
|
||||||
@@ -94,6 +94,7 @@ async function handler(
|
|||||||
const { collectionId } = await createCollectionAndInsertData({
|
const { collectionId } = await createCollectionAndInsertData({
|
||||||
dataset: collection.dataset,
|
dataset: collection.dataset,
|
||||||
rawText,
|
rawText,
|
||||||
|
relatedId: collection.metadata?.relatedImgId,
|
||||||
createCollectionParams: {
|
createCollectionParams: {
|
||||||
...data,
|
...data,
|
||||||
teamId: collection.teamId,
|
teamId: collection.teamId,
|
||||||
|
@@ -95,12 +95,13 @@ async function handler(req: ApiRequestProps<SearchTestProps>): Promise<SearchTes
|
|||||||
});
|
});
|
||||||
|
|
||||||
// push bill
|
// push bill
|
||||||
|
const source = apikey ? UsageSourceEnum.api : UsageSourceEnum.fastgpt;
|
||||||
const { totalPoints: embeddingTotalPoints } = pushGenerateVectorUsage({
|
const { totalPoints: embeddingTotalPoints } = pushGenerateVectorUsage({
|
||||||
teamId,
|
teamId,
|
||||||
tmbId,
|
tmbId,
|
||||||
inputTokens: embeddingTokens,
|
inputTokens: embeddingTokens,
|
||||||
model: dataset.vectorModel,
|
model: dataset.vectorModel,
|
||||||
source: apikey ? UsageSourceEnum.api : UsageSourceEnum.fastgpt,
|
source,
|
||||||
|
|
||||||
...(queryExtensionResult && {
|
...(queryExtensionResult && {
|
||||||
extensionModel: queryExtensionResult.model,
|
extensionModel: queryExtensionResult.model,
|
||||||
@@ -118,7 +119,8 @@ async function handler(req: ApiRequestProps<SearchTestProps>): Promise<SearchTes
|
|||||||
teamId,
|
teamId,
|
||||||
tmbId,
|
tmbId,
|
||||||
inputTokens: reRankInputTokens,
|
inputTokens: reRankInputTokens,
|
||||||
model: rerankModelData.model
|
model: rerankModelData.model,
|
||||||
|
source
|
||||||
})
|
})
|
||||||
: { totalPoints: 0 };
|
: { totalPoints: 0 };
|
||||||
|
|
||||||
|
@@ -284,12 +284,14 @@ export const pushRerankUsage = ({
|
|||||||
teamId,
|
teamId,
|
||||||
tmbId,
|
tmbId,
|
||||||
model,
|
model,
|
||||||
inputTokens
|
inputTokens,
|
||||||
|
source = UsageSourceEnum.fastgpt
|
||||||
}: {
|
}: {
|
||||||
teamId: string;
|
teamId: string;
|
||||||
tmbId: string;
|
tmbId: string;
|
||||||
model: string;
|
model: string;
|
||||||
inputTokens: number;
|
inputTokens: number;
|
||||||
|
source?: UsageSourceEnum;
|
||||||
}) => {
|
}) => {
|
||||||
const { totalPoints, modelName } = formatModelChars2Points({
|
const { totalPoints, modelName } = formatModelChars2Points({
|
||||||
model,
|
model,
|
||||||
@@ -300,9 +302,9 @@ export const pushRerankUsage = ({
|
|||||||
createUsage({
|
createUsage({
|
||||||
teamId,
|
teamId,
|
||||||
tmbId,
|
tmbId,
|
||||||
appName: modelName,
|
appName: i18nT('account_bill:rerank'),
|
||||||
totalPoints,
|
totalPoints,
|
||||||
source: UsageSourceEnum.fastgpt,
|
source,
|
||||||
list: [
|
list: [
|
||||||
{
|
{
|
||||||
moduleName: modelName,
|
moduleName: modelName,
|
||||||
|
Reference in New Issue
Block a user