This commit is contained in:
Archer
2023-10-30 13:26:42 +08:00
committed by GitHub
parent 008d0af010
commit 60ee160131
216 changed files with 4429 additions and 2229 deletions

View File

@@ -7,9 +7,9 @@ import { countPromptTokens } from '@/global/common/tiktoken';
export function replaceVariable(text: string, obj: Record<string, string | number>) {
for (const key in obj) {
const val = obj[key];
if (typeof val !== 'string') continue;
if (!['string', 'number'].includes(typeof val)) continue;
text = text.replace(new RegExp(`{{(${key})}}`, 'g'), val);
text = text.replace(new RegExp(`{{(${key})}}`, 'g'), String(val));
}
return text || '';
}

View File

@@ -1,12 +1,13 @@
import type { AppSchema } from '@/types/mongoSchema';
import type { ChatItemType } from '@/types/chat';
import { AppModuleItemType, VariableItemType } from '@/types/app';
import { VariableItemType } from '@/types/app';
import type { ModuleItemType } from '@fastgpt/global/core/module/type';
export type InitChatResponse = {
chatId: string;
appId: string;
app: {
userGuideModule?: AppModuleItemType;
userGuideModule?: ModuleItemType;
chatModels?: string[];
name: string;
avatar: string;

View File

@@ -1,11 +1,12 @@
import { SystemInputEnum } from '@/constants/app';
import { FlowModuleTypeEnum } from '@/constants/flow';
import { AppModuleItemType, VariableItemType } from '@/types/app';
import { FlowNodeTypeEnum } from '@fastgpt/global/core/module/node/constant';
import { VariableItemType } from '@/types/app';
import type { ModuleItemType } from '@fastgpt/global/core/module/type';
export const getGuideModule = (modules: AppModuleItemType[]) =>
modules.find((item) => item.flowType === FlowModuleTypeEnum.userGuide);
export const getGuideModule = (modules: ModuleItemType[]) =>
modules.find((item) => item.flowType === FlowNodeTypeEnum.userGuide);
export const splitGuideModule = (guideModules?: AppModuleItemType) => {
export const splitGuideModule = (guideModules?: ModuleItemType) => {
const welcomeText: string =
guideModules?.inputs?.find((item) => item.key === SystemInputEnum.welcomeText)?.value || '';

View File

@@ -3,41 +3,81 @@ import { PromptTemplateItem } from '@fastgpt/global/core/ai/type.d';
export const Prompt_QuoteTemplateList: PromptTemplateItem[] = [
{
title: '标准模板',
desc: '包含 q 和 a 两个变量的标准模板',
desc: '标准提示词,用于结构不固定的知识库。',
value: `{{q}}\n{{a}}`
},
{
title: '问答模板',
desc: '适合 QA 问答结构的知识库,或大部分核心介绍位于 a 的知识库。',
value: `{instruction:"{{q}}",output:"{{a}}"}`
},
{
title: '全部变量',
desc: '包含 q 和 a 两个变量的标准模板',
value: `{instruction:"{{q}}",output:"{{a}}",source:"{{source}}",sourceId:"{{sourceId}}",index:"{{index}}"}`
title: '标准严格模板',
desc: '在标准模板基础上,对模型的回答做更严格的要求。',
value: `{{q}}\n{{a}}`
},
{
title: '严格问答模板',
desc: '在问答模板基础上,对模型的回答做更严格的要求。',
value: `{question:"{{q}}",answer:"{{a}}"}`
}
];
export const Prompt_QuotePromptList: PromptTemplateItem[] = [
{
title: '标准模',
title: '标准模',
desc: '',
value: `你的背景知识:
"""
{{quote}}
"""
对话要求:
1. 背景知识是最新的,其中 instruction 是相关介绍output 是预期回答或补充
2. 使用背景知识回答问题
3. 使用对话的风格回答我的问题,答案要和背景知识表述一致
1. 背景知识是最新的实时的信息,使用背景知识回答问题
2. 优先使用背景知识的内容回答我的问题,答案应与背景知识严格一致
3. 背景知识无法回答我的问题时,可以忽略背景知识,根据你的知识来自由回答
4. 使用对话的风格,自然的回答问题。
我的问题是:"{{question}}"`
},
{
title: '严格模式',
title: '问答模板',
desc: '',
value: `你的背景知识:
"""
{{quote}}
"""
对话要求:
1. 背景知识是最新的,其中 instruction 是相关介绍output 是预期回答或补充。
2. 使用背景知识回答问题
3. 背景知识无法满足问题时你需要回答我不清楚关于xxx的内容
1. 背景知识是最新的实时的信息,使用背景知识回答问题,其中 instruction 是相关介绍output 是预期回答或补充。
2. 优先使用背景知识的内容回答我的问题,答案应与背景知识严格一致
3. 背景知识无法回答我的问题时,可以忽略背景知识,根据你的知识来自由回答
4. 使用对话的风格,自然的回答问题。
我的问题是:"{{question}}"`
},
{
title: '标准严格模板',
desc: '',
value: `你的背景知识:
"""
{{quote}}
"""
对话要求:
1. 背景知识是最新的实时的信息,是你的唯一信息来源,使用背景知识回答问题。
2. 优先使用背景知识回答我的问题,答案与背景知识完全一致,无需做其他回答。
3. 背景知识与问题无关或背景知识无法回答本次问题时则拒绝回答本次问题“我不太清除xxx”。
4. 使用对话的风格,自然的回答问题。
我的问题是:"{{question}}"`
},
{
title: '严格问答模板',
desc: '',
value: `你的背景知识:
"""
{{quote}}
"""
对话要求:
1. 背景知识是最新的实时的信息,是你的唯一信息来源,使用背景知识回答问题。
2. 在背景知识的 JSON 中question 是相关问题answer 是已知答案。
3. 选择 answer 中的内容作为答案,要求答案与 answer 完全一致,无需做其他回答。
4. answer 中的答案无法满足问题直接回复“我不太清除xxx”。
我的问题是:"{{question}}"`
}
];

View File

@@ -1,5 +1,5 @@
import type { UserType } from '@/types/user';
import type { PromotionRecordSchema } from '@/types/mongoSchema';
import type { PromotionRecordSchema } from '@fastgpt/global/support/activity/type.d';
export interface ResLogin {
user: UserType;
token: string;