From eefc976d4286c9d0569498f1fa09dfe1ce0d4fe2 Mon Sep 17 00:00:00 2001
From: archer <545436317@qq.com>
Date: Sat, 26 Aug 2023 19:21:15 +0800
Subject: [PATCH] perf: qa prompt
---
README.md | 6 +++---
client/src/pages/kb/detail/components/Import/QA.tsx | 6 +++---
client/src/service/events/generateQA.ts | 8 ++++----
client/src/utils/file.ts | 8 ++++++--
4 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/README.md b/README.md
index ba08dd567..f4a273d20 100644
--- a/README.md
+++ b/README.md
@@ -85,9 +85,9 @@ FastGPT 是一个基于 LLM 大语言模型的知识库问答系统,提供开
## 🏘️ 社区交流群
-| 交流群 | 小助手 |
-| --------------------------------------------------- | ---------------------------------------------- |
-|  |  |
+| 交流群 | 小助手 |
+| ------------------------------------------------- | ---------------------------------------------- |
+|  |  |
## 👀 其他
diff --git a/client/src/pages/kb/detail/components/Import/QA.tsx b/client/src/pages/kb/detail/components/Import/QA.tsx
index d3fc1c609..eb3cc0b7e 100644
--- a/client/src/pages/kb/detail/components/Import/QA.tsx
+++ b/client/src/pages/kb/detail/components/Import/QA.tsx
@@ -187,20 +187,20 @@ const QAImport = ({ kbId }: { kbId: string }) => {
QA 拆分引导词{' '}
- 下面是
+ 关于
(e.target.value ? setPrompt(`下面是"${e.target.value}"`) : '')}
+ onBlur={(e) => (e.target.value ? setPrompt(`关于"${e.target.value}"`) : '')}
/>
diff --git a/client/src/service/events/generateQA.ts b/client/src/service/events/generateQA.ts
index 2a98b1605..d94547f57 100644
--- a/client/src/service/events/generateQA.ts
+++ b/client/src/service/events/generateQA.ts
@@ -64,14 +64,14 @@ export async function generateQA(): Promise {
const messages: ChatCompletionRequestMessage[] = [
{
role: 'system',
- content: `你是出题人,${
- data.prompt || '我会发送一段长文本'
- },请从中提取出 25 个问题和答案. 答案详细完整,并按下面格式返回:
+ content: `我会给你发送一段长文本,${
+ data.prompt ? `是${data.prompt},` : ''
+ }请学习它,并用 markdown 格式给出 25 个问题和答案,问题可以多样化、自由扩展;答案要详细、解读到位,答案包含普通文本、链接、代码、表格、公示、媒体链接等。按下面 QA 问答格式返回:
Q1:
A1:
Q2:
A2:
-...`
+……`
},
{
role: 'user',
diff --git a/client/src/utils/file.ts b/client/src/utils/file.ts
index 32735e280..4afbc49a4 100644
--- a/client/src/utils/file.ts
+++ b/client/src/utils/file.ts
@@ -148,7 +148,7 @@ export const fileDownload = ({
* maxLen > overlapLen
*/
export const splitText2Chunks = ({ text, maxLen }: { text: string; maxLen: number }) => {
- const overlapLen = Math.floor(maxLen * 0.3); // Overlap length
+ const overlapLen = Math.floor(maxLen * 0.25); // Overlap length
try {
const splitTexts = text.split(/(?<=[。!?;.!?;])/g);
@@ -281,6 +281,10 @@ export const simpleText = (text: string) => {
text = text.replace(/([\u4e00-\u9fa5])\s+([\u4e00-\u9fa5])/g, '$1$2');
text = text.replace(/\n{2,}/g, '\n');
text = text.replace(/\s{2,}/g, ' ');
- text = text.replace(/[^\x00-\x7F]/g, ' ');
+
+ text = text.replace(/\\x([0-9A-Fa-f]{2})/g, function (match, hex) {
+ return String.fromCharCode(parseInt(hex, 16));
+ });
+
return text;
};