From 84cf6b5658af71675aaace9f5ba6555567e5ada8 Mon Sep 17 00:00:00 2001 From: Archer <545436317@qq.com> Date: Fri, 8 Dec 2023 16:33:15 +0800 Subject: [PATCH] v4.6.4 (#585) * perf: md format * add systemConfig schema (#2) * fix: markdown * fix: root * fix: root --------- Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com> --- packages/global/common/string/textSplitter.ts | 1 + .../global/common/system/config/constants.ts | 13 ++++++++ .../global/common/system/config/type.d.ts | 8 +++++ .../service/common/system/config/schema.ts | 32 +++++++++++++++++++ .../service/support/permission/controller.ts | 15 ++------- .../app/src/components/Markdown/CodeLight.tsx | 2 +- .../src/components/Markdown/index.module.scss | 5 +-- projects/app/src/global/core/prompt/agent.ts | 15 ++++++--- 8 files changed, 70 insertions(+), 21 deletions(-) create mode 100644 packages/global/common/system/config/constants.ts create mode 100644 packages/global/common/system/config/type.d.ts create mode 100644 packages/service/common/system/config/schema.ts diff --git a/packages/global/common/string/textSplitter.ts b/packages/global/common/string/textSplitter.ts index 6291fbe7950b..6a0935d1948f 100644 --- a/packages/global/common/string/textSplitter.ts +++ b/packages/global/common/string/textSplitter.ts @@ -151,6 +151,7 @@ export const splitText2Chunks = (props: { const maxLen = splitTexts.length > 1 ? stepReges[step].maxLen : chunkLen; const minChunkLen = chunkLen * 0.7; const miniChunkLen = 30; + // console.log(splitTexts, stepReges[step].reg); const chunks: string[] = []; for (let i = 0; i < splitTexts.length; i++) { diff --git a/packages/global/common/system/config/constants.ts b/packages/global/common/system/config/constants.ts new file mode 100644 index 000000000000..0ae8aaaf5df7 --- /dev/null +++ b/packages/global/common/system/config/constants.ts @@ -0,0 +1,13 @@ +export enum SystemConfigsTypeEnum { + fastgpt = 'fastgpt', + fastgptPro = 'fastgptPro' +} + +export const SystemConfigsTypeMap = { + [SystemConfigsTypeEnum.fastgpt]: { + label: 'fastgpt' + }, + [SystemConfigsTypeEnum.fastgptPro]: { + label: 'fastgptPro' + } +}; diff --git a/packages/global/common/system/config/type.d.ts b/packages/global/common/system/config/type.d.ts new file mode 100644 index 000000000000..6e9a6d7ef4f6 --- /dev/null +++ b/packages/global/common/system/config/type.d.ts @@ -0,0 +1,8 @@ +import { SystemConfigsTypeEnum } from "./constants"; + +export type SystemConfigsType = { + _id: string; + type: `${SystemConfigsTypeEnum}`; + value: Record; + createTime: Date; +}; \ No newline at end of file diff --git a/packages/service/common/system/config/schema.ts b/packages/service/common/system/config/schema.ts new file mode 100644 index 000000000000..7dbe2ccacee6 --- /dev/null +++ b/packages/service/common/system/config/schema.ts @@ -0,0 +1,32 @@ +import { SystemConfigsType } from '@fastgpt/global/common/system/config/type'; +import { connectionMongo, type Model } from '../../../common/mongo'; +import { SystemConfigsTypeMap } from '@fastgpt/global/common/system/config/constants'; + +const { Schema, model, models } = connectionMongo; + +const collectionName = 'systemConfigs'; +const systemConfigSchema = new Schema({ + type: { + type: String, + required: true, + enum: Object.keys(SystemConfigsTypeMap) + }, + value: { + type: Object, + required: true + }, + createTime: { + type: Date, + default: () => new Date() + } +}) + +try { + systemConfigSchema.index({ createTime: -1 }, { expireAfterSeconds: 90 * 24 * 60 * 60 }); +} catch (error) { + console.log(error); +} + +export const MongoSystemConfigs: Model= + models[collectionName] || model(collectionName, systemConfigSchema); + MongoSystemConfigs.syncIndexes(); diff --git a/packages/service/support/permission/controller.ts b/packages/service/support/permission/controller.ts index 8df1cf4bd3a2..5cfebda53885 100644 --- a/packages/service/support/permission/controller.ts +++ b/packages/service/support/permission/controller.ts @@ -151,6 +151,7 @@ export async function parseHeaderCert({ authType: AuthUserTypeEnum.root }; } + // apikey: abandon if (authApiKey && apikey) { // apikey const parseResult = await authOpenApiKey({ apikey }); @@ -164,20 +165,8 @@ export async function parseHeaderCert({ }; } - return { - uid: '', - teamId: '', - tmbId: '', - appId: '', - openApiKey: '', - authType: AuthUserTypeEnum.token - }; - })(); - - // not rootUser and no uid, reject request - if (!rootkey && !uid && !teamId && !tmbId) { return Promise.reject(ERROR_ENUM.unAuthorization); - } + })(); return { userId: String(uid), diff --git a/projects/app/src/components/Markdown/CodeLight.tsx b/projects/app/src/components/Markdown/CodeLight.tsx index e9848fc917bf..21fe0ab78541 100644 --- a/projects/app/src/components/Markdown/CodeLight.tsx +++ b/projects/app/src/components/Markdown/CodeLight.tsx @@ -296,7 +296,7 @@ const CodeLight = ({ }) => { const { copyData } = useCopyData(); - if (!inline && match) { + if (!inline) { return ( 标记中是一段文本,学习它们,并整理学习成果。 + +学习要求: +- 提出问题并给出每个问题的答案。 +- 答案需详细完整,给出相关原文描述。答案可以包含普通文字、链接、代码、表格、公示、媒体链接等 markdown 元素。 +- 最多提出 30 个问题。 `, fixedText: `最后,你需要按下面的格式返回多个问题和答案: Q1: 问题。 @@ -11,7 +13,10 @@ Q2: A2: …… -我的文本:"""{{text}}"""` + +{{text}} + +` }; export const Prompt_ExtractJson = `你可以从 "对话记录" 中提取指定信息,并返回一个 JSON 对象,JSON 对象要求: