mirror of
https://github.com/labring/FastGPT.git
synced 2026-05-07 01:02:55 +08:00
fix: ts (#6794)
This commit is contained in:
@@ -8,23 +8,28 @@ import { OutLinkChatAuthSchema } from '../../../../support/permission/chat';
|
||||
import { StoreEdgeItemTypeSchema } from '../../../../core/workflow/type/edge';
|
||||
import { OpenAPIStoreNodeItemTypeSchema } from '../../workflow/node';
|
||||
|
||||
const nullishToUndefined = <T extends z.ZodTypeAny>(schema: T) =>
|
||||
z.preprocess((v) => v ?? undefined, schema);
|
||||
|
||||
const WebCompletionsSchema = z.object({
|
||||
chatId: z
|
||||
.string()
|
||||
.max(1024)
|
||||
.nullish()
|
||||
.meta({ description: '聊天ID, 传入的话会自动获取历史记录,不传入则认为是新对话' }),
|
||||
appId: ObjectIdSchema.nullish(),
|
||||
customUid: z.string().max(1024).nullish().meta({ description: '自定义用户ID(分享链接)' }),
|
||||
metadata: z.record(z.string(), z.any()).nullish().meta({ description: '元数据' })
|
||||
chatId: nullishToUndefined(z.string().max(1024).optional()).meta({
|
||||
description: '聊天ID, 传入的话会自动获取历史记录,不传入则认为是新对话'
|
||||
}),
|
||||
appId: nullishToUndefined(ObjectIdSchema.optional()),
|
||||
customUid: nullishToUndefined(z.string().max(1024).optional()).meta({
|
||||
description: '自定义用户ID(分享链接)'
|
||||
}),
|
||||
metadata: nullishToUndefined(z.record(z.string(), z.any()).optional()).meta({
|
||||
description: '元数据'
|
||||
})
|
||||
});
|
||||
|
||||
// completions 接口实际上并没有用完所有字段,所以这里就取局部即可
|
||||
const ChatCompletionCreateParamsSchema = z.object({
|
||||
messages: z.array(ChatCompletionMessageParamSchema).nullish().default([]).meta({
|
||||
messages: nullishToUndefined(z.array(ChatCompletionMessageParamSchema).default([])).meta({
|
||||
description: '消息列表'
|
||||
}),
|
||||
stream: z.boolean().nullish().default(false).meta({
|
||||
stream: nullishToUndefined(z.boolean().default(false)).meta({
|
||||
description: '是否流式返回'
|
||||
})
|
||||
});
|
||||
@@ -32,23 +37,24 @@ const ChatCompletionCreateParamsSchema = z.object({
|
||||
export const CompletionsPropsSchema = OutLinkChatAuthSchema.extend(WebCompletionsSchema.shape)
|
||||
.extend(ChatCompletionCreateParamsSchema.shape)
|
||||
.extend({
|
||||
variables: z.record(z.string(), z.any()).nullish().default({}).meta({
|
||||
variables: nullishToUndefined(z.record(z.string(), z.any()).default({})).meta({
|
||||
description: '全局变量或插件输入'
|
||||
}),
|
||||
responseChatItemId: z
|
||||
.string()
|
||||
.nullish()
|
||||
.default(() => getNanoid())
|
||||
.meta({
|
||||
description: '自定义响应的 assistant 的消息 ID,如果不传入,则自动生成一个'
|
||||
}),
|
||||
detail: z.boolean().nullish().default(false).meta({
|
||||
responseChatItemId: nullishToUndefined(
|
||||
z
|
||||
.string()
|
||||
.default(() => getNanoid())
|
||||
.meta({
|
||||
description: '自定义响应的 assistant 的消息 ID,如果不传入,则自动生成一个'
|
||||
})
|
||||
),
|
||||
detail: nullishToUndefined(z.boolean().default(false)).meta({
|
||||
description: '是否返回详细信息,包括 reasoning_content, tool_calls, usage 等'
|
||||
}),
|
||||
retainDatasetCite: z.boolean().nullish().default(false).meta({
|
||||
retainDatasetCite: nullishToUndefined(z.boolean().default(false)).meta({
|
||||
description: '是否保留数据集引用'
|
||||
}),
|
||||
showSkillReferences: z.boolean().nullish().default(false).meta({
|
||||
showSkillReferences: nullishToUndefined(z.boolean().default(false)).meta({
|
||||
description: '是否显示技能引用'
|
||||
})
|
||||
});
|
||||
@@ -134,7 +140,7 @@ export const ChatTestPropsSchema = z.object({
|
||||
nodes: z.array(OpenAPIStoreNodeItemTypeSchema).meta({ description: '节点列表' }),
|
||||
edges: z.array(StoreEdgeItemTypeSchema).meta({ description: '边列表' }),
|
||||
chatConfig: AppChatConfigTypeSchema.meta({ description: '聊天配置' }),
|
||||
variables: z.record(z.string(), z.any()).nullish().default({}).meta({
|
||||
variables: nullishToUndefined(z.record(z.string(), z.any()).default({})).meta({
|
||||
description: '全局变量或插件输入'
|
||||
}),
|
||||
appId: ObjectIdSchema.meta({ description: '应用ID' }),
|
||||
|
||||
Reference in New Issue
Block a user