Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Labring main #960

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
bc48e38
Changes to be committed:
zenyanbo Jan 17, 2024
352a2c9
去掉Markdown语法
zenyanbo Jan 17, 2024
71cf0bb
将回复模板中的中文改为英文
zenyanbo Jan 17, 2024
052e30c
增加对公式的要求
zenyanbo Jan 17, 2024
d506ecb
多余的question
zenyanbo Jan 17, 2024
15d82f6
Merge pull request #1 from labring/main
zenyanbo Jan 18, 2024
56bddf9
注释max_tokens
zenyanbo Jan 18, 2024
e1c9a1a
Merge branch 'main' of https://github.com/zenyanbo/FastGPT
zenyanbo Jan 18, 2024
f9312c6
优化QA Prompt
zenyanbo Jan 19, 2024
ce9866c
Update agent.ts
zenyanbo Jan 19, 2024
c5a5f60
Update agent.ts
zenyanbo Jan 20, 2024
4cd75e4
Update agent.ts
zenyanbo Jan 20, 2024
ce609a1
Update AIChat.ts
zenyanbo Jan 20, 2024
963ef7b
123
zenyanbo Jan 20, 2024
f40078c
Merge branch 'labring-main'
zenyanbo Jan 20, 2024
88e9edc
Merge branch 'main' of https://github.com/zenyanbo/FastGPT
zenyanbo Jan 20, 2024
211ec92
Merge pull request #3 from labring/main
zenyanbo Jan 23, 2024
a92878f
Update AIChat.ts
zenyanbo Jan 23, 2024
0dd40d5
Update agent.ts
zenyanbo Jan 23, 2024
a7558e6
Update agent.ts
zenyanbo Jan 23, 2024
253c143
Update agent.ts
zenyanbo Jan 23, 2024
4f11f2f
Changes to be committed:
zenyanbo Jan 23, 2024
a9fdef2
修改匹配\\n的正则表达式
zenyanbo Jan 23, 2024
68d34fd
Changes to be committed:
zenyanbo Jan 23, 2024
04e6c67
Changes to be committed:
zenyanbo Jan 23, 2024
0916d17
Changes to be committed:
zenyanbo Jan 23, 2024
f1b15e4
Update agent.ts
zenyanbo Jan 24, 2024
9f076fb
Update agent.ts
zenyanbo Jan 24, 2024
cc2979f
Update agent.ts
zenyanbo Jan 25, 2024
651dca5
Merge branch
zenyanbo Feb 6, 2024
2dc7af6
Merge branch 'labring-main'
zenyanbo Feb 6, 2024
a025c0c
Merge pull request #5 from labring/main
zenyanbo Feb 21, 2024
7a8cf8d
Merge pull request #6 from labring/main
zenyanbo Feb 22, 2024
f493bb2
Improve prompt
zenyanbo Feb 23, 2024
7cb8cc2
Changes to be committed:
zenyanbo Feb 23, 2024
8317948
Update agent.ts
zenyanbo Feb 23, 2024
5288474
Update agent.ts
zenyanbo Feb 23, 2024
9134ba6
Update agent.ts
zenyanbo Feb 23, 2024
c6267f3
Update agent.ts
zenyanbo Feb 23, 2024
b296ca7
Merge branch 'main' of https://github.com/labring/FastGPT into labrin…
zenyanbo Mar 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions docSite/content/docs/workflow/examples/fixingEvidence.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,12 @@ weight: 401
"value": "gpt-3.5-turbo",
"list": [
{
"label": "FastGPT-4k",
"label": "FastGPT",
"value": "gpt-3.5-turbo"
},
{
"label": "FastGPT-16k",
"value": "gpt-3.5-turbo-16k"
},
{
"label": "文心一言",
"value": "ERNIE-Bot"
},
{
"label": "FastGPT-Plus",
"value": "gpt-4"
},
{
"label": "glm2(演示娱乐)",
"value": "glm2-6b"
}
],
"connected": true
Expand Down
2 changes: 1 addition & 1 deletion projects/app/src/components/Markdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const Markdown = ({ source, isChatting = false }: { source: string; isChatting?:
);

const formatSource = source
.replace(/\\n/g, '\n ')
.replace(/\\n\W/g, '\n ')
.replace(/(http[s]?:\/\/[^\s,。]+)([。,])/g, '$1 $2')
.replace(/\n*(\[QUOTE SIGN\]\(.*\))/g, '$1');

Expand Down
50 changes: 27 additions & 23 deletions projects/app/src/global/core/prompt/AIChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ export const Prompt_QuoteTemplateList: PromptTemplateItem[] = [
{
title: '问答模板',
desc: '适合 QA 问答结构的知识库,可以让AI较为严格的按预设内容回答',
value: `<Question>
value: `<QA>
<问题>
{{q}}
</Question>
<Answer>
{{a}}
</Answer>`
</答案>
</QA>`
},
{
title: '标准严格模板',
Expand All @@ -26,29 +28,31 @@ export const Prompt_QuoteTemplateList: PromptTemplateItem[] = [
{
title: '严格问答模板',
desc: '在问答模板基础上,对模型的回答做更严格的要求。',
value: `<Question>
value: `<QA>
<问题>
{{q}}
</Question>
<Answer>
{{a}}
</Answer>`
</答案>
</QA>`
}
];

export const Prompt_QuotePromptList: PromptTemplateItem[] = [
{
title: '标准模板',
desc: '',
value: `使用 <Data></Data> 标记中的内容作为你的知识:
value: `使用 <data></data> 标记中的内容作为你的知识:

<Data>
{{quote}}
</Data>

回答要求:
- 如果你不清楚答案,你需要澄清。
- 避免提及你是从 <Data></Data> 获取的知识。
- 保持答案与 <Data></Data> 中描述的一致。
- 避免提及你是从 <data></data> 获取的知识。
- 保持答案与 <data></data> 中描述的一致。
- 使用 Markdown 语法优化回答格式。
- 使用与问题相同的语言回答。

Expand All @@ -57,37 +61,39 @@ export const Prompt_QuotePromptList: PromptTemplateItem[] = [
{
title: '问答模板',
desc: '',
value: `使用 <QA></QA> 标记中的问答对进行回答。
value: `Use the Q&A pairs within <QA></QA> tags for responses.

<QA>
{{quote}}
</QA>

回答要求:
- 选择其中一个或多个问答对进行回答。
- 回答的内容应尽可能与 <答案></答案> 中的内容一致。
- 如果没有相关的问答对,你需要澄清。
- 避免提及你是从 QA 获取的知识,只需要回复答案。

问题:"""{{question}}"""`
Answer Requirements:
- Choose one or more Q&A pairs to respond to.
- Ensure that the response closely aligns with the content within <Answer></Answer>.
- Clarify if there are no relevant Q&A pairs.
- Avoid mentioning that knowledge comes from Q&A pairs unless the user mentions
- All Mathematical symbols and formulas must be expressed in the following LaTex format. Inline format $g_{\\mu\\nu}$ and display format:
$$
i\\hbar \\frac{\\partial}{\\partial t}\\left|\\Psi(t)\\right>=H\\left|\\Psi(t)\\right>
$$

Question:"""{{question}}"""`
},
{
title: '标准严格模板',
desc: '',
value: `忘记你已有的知识,仅使用 <Data></Data> 标记中的内容作为你的知识:
value: `忘记你已有的知识,仅使用 <data></data> 标记中的内容作为你的知识:

<Data>
{{quote}}
</Data>

思考流程:
1. 判断问题是否与 <Data></Data> 标记中的内容有关。
1. 判断问题是否与 <data></data> 标记中的内容有关。
2. 如果有关,你按下面的要求回答。
3. 如果无关,你直接拒绝回答本次问题。

回答要求:
- 避免提及你是从 <Data></Data> 获取的知识。
- 保持答案与 <Data></Data> 中描述的一致。
- 避免提及你是从 <data></data> 获取的知识。
- 保持答案与 <data></data> 中描述的一致。
- 使用 Markdown 语法优化回答格式。
- 使用与问题相同的语言回答。

Expand All @@ -98,9 +104,7 @@ export const Prompt_QuotePromptList: PromptTemplateItem[] = [
desc: '',
value: `忘记你已有的知识,仅使用 <QA></QA> 标记中的问答对进行回答。

<QA>
{{quote}}
</QA>}

思考流程:
1. 判断问题是否与 <QA></QA> 标记中的内容有关。
Expand Down
64 changes: 36 additions & 28 deletions projects/app/src/global/core/prompt/agent.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
export const Prompt_AgentQA = {
description: `<Context></Context> 标记中是一段文本,学习和分析它,并整理学习成果:
- 提出问题并给出每个问题的答案。
- 答案需详细完整,尽可能保留原文描述。
- 答案可以包含普通文字、链接、代码、表格、公示、媒体链接等 Markdown 元素。
- 最多提出 30 个问题。
description: `As a theoretical physicist, you are familiar with both the core and advanced courses (QFT, GR, etc). Mathematics courses are also covered. Your style is to understand physics from mathematics, because the use of mathematical language and concepts makes the problem clear.

## Your task is
- The content in the <context></context> tag is part of the academic paper in LaTeX source code form. Study and analyze it. Notice: the content may be incomplete, you try to complete
- Understand the content, recall relevant knowledge or examples in your mind, then think step by step
- According to the paper, pose at least 5 questions and their answers (Q&A pairs)

## Q&A pairs should
- Keep Q&A complete
- Professional answer. Provide in-depth explanations and mathematical derivations
- Equations should be expained
- All Mathematical symbols and formulas must be expressed in the following LaTex format. Inline format $g_{\\mu\\nu}$ and display format:
$$
i\\hbar \\frac{\\partial}{\\partial t}\\left|\\Psi(t)\\right>=H\\left|\\Psi(t)\\right>
$$
`,
fixedText: `请按以下格式整理学习成果:
<Context>
文本
</Context>
fixedText: `最后,你需要按下面的格式返回多个问题和答案:
Q1: 问题。
A1: 答案。
Q2:
Expand All @@ -20,43 +27,44 @@ A2:

<Context>
{{text}}
<Context/>
<context/>
`
};

export const Prompt_ExtractJson = `你可以从 <对话记录></对话记录> 中提取指定 JSON 信息,你仅需返回 JSON 字符串,无需回答问题。
<提取要求>
export const Prompt_ExtractJson = `You can extract specified JSON information from <Conversation></Conversation> records. Please return the JSON string without answering questions.
<Extraction Requirements>
{{description}}
</提取要求>
</Extraction Requirements>

<字段说明>
1. 下面的 JSON 字符串均按照 JSON Schema 的规则描述。
2. key 代表字段名;description 代表字段的描述;enum 是可选值,代表可选的 value。
3. 如果没有可提取的内容,忽略该字段。
4. 本次需提取的JSON Schema:{{json}}
2. key 代表字段名;description 代表字段的描述;required 代表字段是否必须;enum 是可选值,代表可选的 value。
3. 如果字段内容为空,你可以返回空字符串。

{{json}}
</字段说明>

<对话记录>
<Conversation Records>
{{text}}
</对话记录>
</Conversation Records>
`;

export const Prompt_CQJson = `我会给你几个问题类型,请参考背景知识(可能为空)和对话记录,判断我“本次问题”的类型,并返回一个问题“类型ID”:
<问题类型>
export const Prompt_CQJson = `I will provide you with several question types. Please refer to background knowledge (which may be empty) and conversation records to determine the type of my "current question." Return a question "type ID" accordingly:
<Question Types>
{{typeList}}
</问题类型>
</Question Types>

<背景知识>
<Background Knowledge>
{{systemPrompt}}
</背景知识>
</Background Knowledge>

<对话记录>
<Conversation Records>
{{history}}
</对话记录>
</Conversation Records>

Human"{{question}}"
Human: "{{question}}"

类型ID=
Type ID=
`;

export const Prompt_QuestionGuide = `我不太清楚问你什么问题,请帮我生成 3 个问题,引导我继续提问。问题的长度应小于20个字符,按 JSON 格式返回: ["问题1", "问题2", "问题3"]`;
export const Prompt_QuestionGuide = `I'm not sure what questions to ask you. Please help me generate 3 questions to guide further inquiries. The length of each question should be less than 20 characters. Return in JSON format: ["Question1", "Question2", "Question3"]`;
2 changes: 1 addition & 1 deletion projects/app/src/service/events/generateQA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ ${replaceVariable(Prompt_AgentQA.fixedText, { text })}`;
* 检查文本是否按格式返回
*/
function formatSplitText(text: string, rawText: string) {
text = text.replace(/\\n/g, '\n'); // 将换行符替换为空格
text = text.replace(/\\n\W/g, '\n'); // 将换行符替换为空格
const regex = /Q\d+:(\s*)(.*)(\s*)A\d+:(\s*)([\s\S]*?)(?=Q\d|$)/g; // 匹配Q和A的正则表达式
const matches = text.matchAll(regex); // 获取所有匹配到的结果

Expand Down
2 changes: 1 addition & 1 deletion projects/app/src/service/moduleDispatch/chat/oneapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
...modelConstantsData?.defaultConfig,
model: modelConstantsData.model,
temperature,
max_tokens,
//max_tokens,
stream,
messages: concatMessages
},
Expand Down
2 changes: 1 addition & 1 deletion projects/app/src/web/common/utils/voice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const useAudioPlay = (props?: OutLinkChatAuthProps & { ttsConfig?: AppTTS
buffer?: Uint8Array;
}) =>
new Promise<{ buffer?: Uint8Array }>(async (resolve, reject) => {
text = text.replace(/\\n/g, '\n');
text = text.replace(/\\n\W/g, '\n');
try {
// tts play
if (audio && ttsConfig && ttsConfig?.type === TTSTypeEnum.model) {
Expand Down
Loading