diff --git a/document/content/docs/upgrading/4-14/4145.mdx b/document/content/docs/upgrading/4-14/4145.mdx index 6fa0cfbeb..95df5d844 100644 --- a/document/content/docs/upgrading/4-14/4145.mdx +++ b/document/content/docs/upgrading/4-14/4145.mdx @@ -17,6 +17,7 @@ description: 'FastGPT V4.14.5 更新说明' 1. MCP 工具创建时,使用自定义鉴权头会报错。 2. 获取对话日志列表时,如果用户头像为空,会抛错。 3. chatAgent 未开启问题优化时,前端 UI 显示开启。 +4. 加载默认模型时,maxTokens 字段未赋值,导致模型最大响应值配置为空。 ## 插件 diff --git a/document/data/doc-last-modified.json b/document/data/doc-last-modified.json index 301fb3e29..a034479c5 100644 --- a/document/data/doc-last-modified.json +++ b/document/data/doc-last-modified.json @@ -120,7 +120,7 @@ "document/content/docs/upgrading/4-14/4142.mdx": "2025-11-18T19:27:14+08:00", "document/content/docs/upgrading/4-14/4143.mdx": "2025-11-26T20:52:05+08:00", "document/content/docs/upgrading/4-14/4144.mdx": "2025-12-16T14:56:04+08:00", - "document/content/docs/upgrading/4-14/4145.mdx": "2025-12-18T11:09:13+08:00", + "document/content/docs/upgrading/4-14/4145.mdx": "2025-12-18T23:25:48+08:00", "document/content/docs/upgrading/4-8/40.mdx": "2025-08-02T19:38:37+08:00", "document/content/docs/upgrading/4-8/41.mdx": "2025-08-02T19:38:37+08:00", "document/content/docs/upgrading/4-8/42.mdx": "2025-08-02T19:38:37+08:00", diff --git a/packages/global/core/chat/api.ts b/packages/global/core/chat/api.ts deleted file mode 100644 index 3d66d3890..000000000 --- a/packages/global/core/chat/api.ts +++ /dev/null @@ -1,68 +0,0 @@ -import type { OutLinkChatAuthType } from '../../support/permission/chat/type'; -import { OutLinkChatAuthSchema } from '../../support/permission/chat/type'; -import { ObjectIdSchema } from '../../common/type/mongo'; -import z from 'zod'; - -export const PresignChatFileGetUrlSchema = z - .object({ - key: z.string().min(1), - appId: ObjectIdSchema, - outLinkAuthData: OutLinkChatAuthSchema.optional() - }) - .meta({ - description: '获取对话文件预览链接', - example: { - key: '1234567890', - appId: '1234567890', - outLinkAuthData: { - shareId: '1234567890', - outLinkUid: '1234567890' - } - } - }); -export type PresignChatFileGetUrlParams = z.infer & { - outLinkAuthData?: OutLinkChatAuthType; -}; - -export const PresignChatFilePostUrlSchema = z - .object({ - filename: z.string().min(1), - appId: ObjectIdSchema, - chatId: ObjectIdSchema, - outLinkAuthData: OutLinkChatAuthSchema.optional() - }) - .meta({ - description: '获取上传对话文件预签名 URL', - example: { - filename: '1234567890', - appId: '1234567890', - chatId: '1234567890', - outLinkAuthData: { - shareId: '1234567890', - outLinkUid: '1234567890' - } - } - }); -export type PresignChatFilePostUrlParams = z.infer & { - outLinkAuthData?: OutLinkChatAuthType; -}; - -export const UpdateChatFeedbackSchema = z - .object({ - appId: z.string().min(1), - chatId: z.string().min(1), - dataId: z.string().min(1), - userBadFeedback: z.string().optional(), - userGoodFeedback: z.string().optional() - }) - .meta({ - description: '更新对话反馈', - example: { - appId: '1234567890', - chatId: '1234567890', - dataId: '1234567890', - userBadFeedback: '1234567890', - userGoodFeedback: '1234567890' - } - }); -export type UpdateChatFeedbackProps = z.infer; diff --git a/packages/global/openapi/api.ts b/packages/global/openapi/api.ts index 169e16f75..663353445 100644 --- a/packages/global/openapi/api.ts +++ b/packages/global/openapi/api.ts @@ -1,9 +1,9 @@ import { z } from 'zod'; export const PaginationSchema = z.object({ - pageSize: z.union([z.number(), z.string()]).optional(), - offset: z.union([z.number(), z.string()]).optional(), - pageNum: z.union([z.number(), z.string()]).optional() + pageSize: z.union([z.number(), z.string()]).optional().describe('每页条数'), + offset: z.union([z.number(), z.string()]).optional().describe('偏移量(与页码二选一)'), + pageNum: z.union([z.number(), z.string()]).optional().describe('页码(与偏移量二选一)') }); export type PaginationType = z.infer; diff --git a/packages/global/openapi/core/chat/api.ts b/packages/global/openapi/core/chat/api.ts new file mode 100644 index 000000000..cb0a97a61 --- /dev/null +++ b/packages/global/openapi/core/chat/api.ts @@ -0,0 +1,42 @@ +import type { OutLinkChatAuthType } from '../../../support/permission/chat/type'; +import { OutLinkChatAuthSchema } from '../../../support/permission/chat/type'; +import { ObjectIdSchema } from '../../../common/type/mongo'; +import z from 'zod'; + +export const PresignChatFileGetUrlSchema = z + .object({ + key: z.string().min(1).describe('文件key'), + appId: ObjectIdSchema.describe('应用ID'), + outLinkAuthData: OutLinkChatAuthSchema.optional().describe('外链鉴权数据') + }) + .meta({ + example: { + key: '1234567890', + appId: '1234567890', + outLinkAuthData: { + shareId: '1234567890', + outLinkUid: '1234567890' + } + } + }); +export type PresignChatFileGetUrlParams = z.infer; + +export const PresignChatFilePostUrlSchema = z + .object({ + filename: z.string().min(1).describe('文件名'), + appId: ObjectIdSchema.describe('应用ID'), + chatId: z.string().min(1).describe('对话ID'), + outLinkAuthData: OutLinkChatAuthSchema.optional().describe('外链鉴权数据') + }) + .meta({ + example: { + filename: '1234567890', + appId: '1234567890', + chatId: '1234567890', + outLinkAuthData: { + shareId: '1234567890', + outLinkUid: '1234567890' + } + } + }); +export type PresignChatFilePostUrlParams = z.infer; diff --git a/packages/global/openapi/core/chat/feedback/index.ts b/packages/global/openapi/core/chat/feedback/index.ts index d01622c85..2f2ea7aee 100644 --- a/packages/global/openapi/core/chat/feedback/index.ts +++ b/packages/global/openapi/core/chat/feedback/index.ts @@ -14,81 +14,9 @@ import { } from './api'; export const ChatFeedbackPath: OpenAPIPath = { - '/core/chat/feedback/updateFeedbackReadStatus': { - post: { - summary: '更新反馈阅读状态', - description: '标记指定消息的反馈为已读或未读状态', - tags: [TagsMap.chatFeedback], - requestBody: { - content: { - 'application/json': { - schema: UpdateFeedbackReadStatusBodySchema - } - } - }, - responses: { - 200: { - description: '成功更新反馈阅读状态', - content: { - 'application/json': { - schema: UpdateFeedbackReadStatusResponseSchema - } - } - } - } - } - }, - '/core/chat/feedback/adminUpdate': { - post: { - summary: '管理员标注反馈', - description: '管理员为指定消息添加或更新标注反馈,包含数据集关联信息', - tags: [TagsMap.chatFeedback], - requestBody: { - content: { - 'application/json': { - schema: AdminUpdateFeedbackBodySchema - } - } - }, - responses: { - 200: { - description: '成功更新管理员反馈标注', - content: { - 'application/json': { - schema: AdminUpdateFeedbackResponseSchema - } - } - } - } - } - }, - '/core/chat/feedback/closeCustom': { - post: { - summary: '关闭自定义反馈', - description: '删除或关闭指定索引位置的自定义反馈条目', - tags: [TagsMap.chatFeedback], - requestBody: { - content: { - 'application/json': { - schema: CloseCustomFeedbackBodySchema - } - } - }, - responses: { - 200: { - description: '成功关闭自定义反馈', - content: { - 'application/json': { - schema: CloseCustomFeedbackResponseSchema - } - } - } - } - } - }, '/core/chat/feedback/updateUserFeedback': { post: { - summary: '更新用户反馈', + summary: '添加/更新用户反馈', description: '用户对消息添加或更新好评/差评反馈', tags: [TagsMap.chatFeedback], requestBody: { @@ -133,5 +61,77 @@ export const ChatFeedbackPath: OpenAPIPath = { } } } + }, + '/core/chat/feedback/updateFeedbackReadStatus': { + post: { + summary: '应用管理员-更新反馈阅读状态', + description: '标记指定消息的反馈为已读或未读状态', + tags: [TagsMap.chatFeedback], + requestBody: { + content: { + 'application/json': { + schema: UpdateFeedbackReadStatusBodySchema + } + } + }, + responses: { + 200: { + description: '成功更新反馈阅读状态', + content: { + 'application/json': { + schema: UpdateFeedbackReadStatusResponseSchema + } + } + } + } + } + }, + '/core/chat/feedback/adminUpdate': { + post: { + summary: '应用管理员-标注反馈', + description: '管理员为指定消息添加或更新标注反馈,包含数据集关联信息', + tags: [TagsMap.chatFeedback], + requestBody: { + content: { + 'application/json': { + schema: AdminUpdateFeedbackBodySchema + } + } + }, + responses: { + 200: { + description: '成功更新管理员反馈标注', + content: { + 'application/json': { + schema: AdminUpdateFeedbackResponseSchema + } + } + } + } + } + }, + '/core/chat/feedback/closeCustom': { + post: { + summary: '应用管理员-关闭自定义反馈', + description: '删除或关闭指定索引位置的自定义反馈条目', + tags: [TagsMap.chatFeedback], + requestBody: { + content: { + 'application/json': { + schema: CloseCustomFeedbackBodySchema + } + } + }, + responses: { + 200: { + description: '成功关闭自定义反馈', + content: { + 'application/json': { + schema: CloseCustomFeedbackResponseSchema + } + } + } + } + } } }; diff --git a/packages/global/openapi/core/chat/history/api.ts b/packages/global/openapi/core/chat/history/api.ts index 04a03bf12..74b2f3088 100644 --- a/packages/global/openapi/core/chat/history/api.ts +++ b/packages/global/openapi/core/chat/history/api.ts @@ -5,18 +5,14 @@ import { ChatSourceEnum } from '../../../../core/chat/constants'; import { PaginationSchema, PaginationResponseSchema } from '../../../api'; // Get chat histories schema -export const GetHistoriesBodySchema = PaginationSchema.and( - OutLinkChatAuthSchema.and( - z.object({ - appId: z.string().optional().describe('应用ID'), - source: z.enum(ChatSourceEnum).optional().describe('对话来源'), - startCreateTime: z.string().optional().describe('创建时间开始'), - endCreateTime: z.string().optional().describe('创建时间结束'), - startUpdateTime: z.string().optional().describe('更新时间开始'), - endUpdateTime: z.string().optional().describe('更新时间结束') - }) - ) -); +export const GetHistoriesBodySchema = PaginationSchema.extend(OutLinkChatAuthSchema.shape).extend({ + appId: z.string().optional().describe('应用ID'), + source: z.enum(ChatSourceEnum).optional().describe('对话来源'), + startCreateTime: z.string().optional().describe('创建时间开始'), + endCreateTime: z.string().optional().describe('创建时间结束'), + startUpdateTime: z.string().optional().describe('更新时间开始'), + endUpdateTime: z.string().optional().describe('更新时间结束') +}); export type GetHistoriesBodyType = z.infer; export const GetHistoriesResponseSchema = PaginationResponseSchema( z.object({ @@ -43,20 +39,16 @@ export const UpdateHistoryBodySchema = OutLinkChatAuthSchema.and( export type UpdateHistoryBodyType = z.infer; // Delete single chat history schema -export const DelChatHistorySchema = OutLinkChatAuthSchema.and( - z.object({ - appId: ObjectIdSchema.describe('应用ID'), - chatId: z.string().min(1).describe('对话ID') - }) -); +export const DelChatHistorySchema = OutLinkChatAuthSchema.extend({ + appId: ObjectIdSchema.describe('应用ID'), + chatId: z.string().min(1).describe('对话ID') +}); export type DelChatHistoryType = z.infer; // Clear all chat histories schema -export const ClearChatHistoriesSchema = OutLinkChatAuthSchema.and( - z.object({ - appId: ObjectIdSchema.describe('应用ID') - }) -); +export const ClearChatHistoriesSchema = OutLinkChatAuthSchema.extend({ + appId: ObjectIdSchema.describe('应用ID') +}); export type ClearChatHistoriesType = z.infer; // Batch delete chat histories schema (for log manager) diff --git a/packages/global/openapi/core/chat/index.ts b/packages/global/openapi/core/chat/index.ts index 5d44ce944..48f1b5300 100644 --- a/packages/global/openapi/core/chat/index.ts +++ b/packages/global/openapi/core/chat/index.ts @@ -5,7 +5,7 @@ import { ChatFeedbackPath } from './feedback/index'; import { ChatHistoryPath } from './history/index'; import { z } from 'zod'; import { CreatePostPresignedUrlResultSchema } from '../../../../service/common/s3/type'; -import { PresignChatFileGetUrlSchema, PresignChatFilePostUrlSchema } from '../../../core/chat/api'; +import { PresignChatFileGetUrlSchema, PresignChatFilePostUrlSchema } from './api'; import { TagsMap } from '../../tag'; export const ChatPath: OpenAPIPath = { @@ -14,34 +14,10 @@ export const ChatPath: OpenAPIPath = { ...ChatFeedbackPath, ...ChatHistoryPath, - '/core/chat/presignChatFileGetUrl': { - post: { - summary: '获取对话文件预签名 URL', - description: '获取对话文件的预签名 URL', - tags: [TagsMap.chatPage], - requestBody: { - content: { - 'application/json': { - schema: PresignChatFileGetUrlSchema - } - } - }, - responses: { - 200: { - description: '成功获取对话文件预签名 URL', - content: { - 'application/json': { - schema: z.string() - } - } - } - } - } - }, '/core/chat/presignChatFilePostUrl': { post: { - summary: '上传对话文件预签名 URL', - description: '上传对话文件的预签名 URL', + summary: '获取文件上传 URL', + description: '获取文件上传 URL', tags: [TagsMap.chatPage], requestBody: { content: { @@ -61,5 +37,29 @@ export const ChatPath: OpenAPIPath = { } } } + }, + '/core/chat/presignChatFileGetUrl': { + post: { + summary: '获取文件预览地址', + description: '获取文件预览地址', + tags: [TagsMap.chatPage], + requestBody: { + content: { + 'application/json': { + schema: PresignChatFileGetUrlSchema + } + } + }, + responses: { + 200: { + description: '成功获取对话文件预签名 URL', + content: { + 'application/json': { + schema: z.string() + } + } + } + } + } } }; diff --git a/packages/global/support/permission/chat.ts b/packages/global/support/permission/chat.ts index 6bc4499eb..353116ce7 100644 --- a/packages/global/support/permission/chat.ts +++ b/packages/global/support/permission/chat.ts @@ -12,5 +12,5 @@ export const TeamChatAuthSchema = z.object({ }); export type TeamChatAuthProps = z.infer; -export const OutLinkChatAuthSchema = ShareChatAuthSchema.and(TeamChatAuthSchema); +export const OutLinkChatAuthSchema = ShareChatAuthSchema.extend(TeamChatAuthSchema.shape); export type OutLinkChatAuthProps = z.infer; diff --git a/packages/service/core/ai/config/utils.ts b/packages/service/core/ai/config/utils.ts index 8a1678889..3e53ef8d6 100644 --- a/packages/service/core/ai/config/utils.ts +++ b/packages/service/core/ai/config/utils.ts @@ -140,9 +140,13 @@ export const loadSystemModels = async (init = false, language = 'en') => { type: dbModel?.metadata?.type || model.type, isCustom: false, + ...(model.type === ModelTypeEnum.llm && { + maxResponse: model.maxTokens || 4000 + }), + ...(model.type === ModelTypeEnum.llm && dbModel?.metadata?.type === ModelTypeEnum.llm ? { - maxResponse: dbModel?.metadata?.maxResponse ?? model.maxTokens ?? 1000, + maxResponse: dbModel?.metadata?.maxResponse ?? model.maxTokens ?? 4000, defaultConfig: mergeObject(model.defaultConfig, dbModel?.metadata?.defaultConfig), fieldMap: mergeObject(model.fieldMap, dbModel?.metadata?.fieldMap), maxTokens: undefined diff --git a/projects/app/src/pages/api/core/chat/presignChatFileGetUrl.ts b/projects/app/src/pages/api/core/chat/presignChatFileGetUrl.ts index fc5b8a32b..5658d1dca 100644 --- a/projects/app/src/pages/api/core/chat/presignChatFileGetUrl.ts +++ b/projects/app/src/pages/api/core/chat/presignChatFileGetUrl.ts @@ -2,7 +2,7 @@ import type { ApiRequestProps } from '@fastgpt/service/type/next'; import { NextAPI } from '@/service/middleware/entry'; import { getS3ChatSource } from '@fastgpt/service/common/s3/sources/chat'; import { authChatCrud } from '@/service/support/permission/auth/chat'; -import type { PresignChatFileGetUrlParams } from '@fastgpt/global/core/chat/api'; +import type { PresignChatFileGetUrlParams } from '@fastgpt/global/openapi/core/chat/api'; async function handler(req: ApiRequestProps): Promise { const { key, appId, outLinkAuthData } = req.body; diff --git a/projects/app/src/pages/api/core/chat/presignChatFilePostUrl.ts b/projects/app/src/pages/api/core/chat/presignChatFilePostUrl.ts index 394e9be9f..d918bc93f 100644 --- a/projects/app/src/pages/api/core/chat/presignChatFilePostUrl.ts +++ b/projects/app/src/pages/api/core/chat/presignChatFilePostUrl.ts @@ -5,7 +5,7 @@ import { getS3ChatSource } from '@fastgpt/service/common/s3/sources/chat'; import { authChatCrud } from '@/service/support/permission/auth/chat'; import { authFrequencyLimit } from '@/service/common/frequencyLimit/api'; import { addSeconds } from 'date-fns'; -import type { PresignChatFilePostUrlParams } from '@fastgpt/global/core/chat/api'; +import type { PresignChatFilePostUrlParams } from '@fastgpt/global/openapi/core/chat/api'; const authUploadLimit = (tmbId: string) => { if (!global.feConfigs.uploadFileMaxAmount) return;