perf: qa prompt

This commit is contained in:
archer 2023-08-26 19:21:15 +08:00
parent be33794a5f
commit eefc976d42
No known key found for this signature in database
GPG Key ID: 569A5660D2379E28
4 changed files with 16 additions and 12 deletions

View File

@ -86,8 +86,8 @@ FastGPT 是一个基于 LLM 大语言模型的知识库问答系统,提供开
## 🏘️ 社区交流群 ## 🏘️ 社区交流群
| 交流群 | 小助手 | | 交流群 | 小助手 |
| --------------------------------------------------- | ---------------------------------------------- | | ------------------------------------------------- | ---------------------------------------------- |
| ![](https://otnvvf-imgs.oss.laf.run/wxqun300-2.jpg) | ![](https://otnvvf-imgs.oss.laf.run/wx300.jpg) | | ![](https://otnvvf-imgs.oss.laf.run/wxqun300.jpg) | ![](https://otnvvf-imgs.oss.laf.run/wx300.jpg) |
## 👀 其他 ## 👀 其他

View File

@ -187,20 +187,20 @@ const QAImport = ({ kbId }: { kbId: string }) => {
<Box mb={2}> <Box mb={2}>
QA {' '} QA {' '}
<MyTooltip <MyTooltip
label={`可输入关于文件内容的范围介绍,例如:\n1. 关于 Laf 的介绍\n2. xxx的简历`} label={`可输入关于文件内容的范围介绍,例如:\n1. Laf 的介绍\n2. xxx的简历\n最终会补全为: 关于{输入的内容}`}
forceShow forceShow
> >
<QuestionOutlineIcon ml={1} /> <QuestionOutlineIcon ml={1} />
</MyTooltip> </MyTooltip>
</Box> </Box>
<Flex alignItems={'center'} fontSize={'sm'}> <Flex alignItems={'center'} fontSize={'sm'}>
<Box mr={2}></Box> <Box mr={2}></Box>
<Input <Input
flex={1} flex={1}
placeholder={'Laf 云函数的介绍'} placeholder={'Laf 云函数的介绍'}
bg={'myWhite.500'} bg={'myWhite.500'}
defaultValue={prompt} defaultValue={prompt}
onBlur={(e) => (e.target.value ? setPrompt(`下面是"${e.target.value}"`) : '')} onBlur={(e) => (e.target.value ? setPrompt(`关于"${e.target.value}"`) : '')}
/> />
</Flex> </Flex>
</Box> </Box>

View File

@ -64,14 +64,14 @@ export async function generateQA(): Promise<any> {
const messages: ChatCompletionRequestMessage[] = [ const messages: ChatCompletionRequestMessage[] = [
{ {
role: 'system', role: 'system',
content: `你是出题人${ content: `我会给你发送一段长文本${
data.prompt || '我会发送一段长文本' data.prompt ? `${data.prompt}` : ''
} 25 . : } markdown 25 QA :
Q1: Q1:
A1: A1:
Q2: Q2:
A2: A2:
...` `
}, },
{ {
role: 'user', role: 'user',

View File

@ -148,7 +148,7 @@ export const fileDownload = ({
* maxLen > overlapLen * maxLen > overlapLen
*/ */
export const splitText2Chunks = ({ text, maxLen }: { text: string; maxLen: number }) => { 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 { try {
const splitTexts = text.split(/(?<=[。!?;.!?;])/g); 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(/([\u4e00-\u9fa5])\s+([\u4e00-\u9fa5])/g, '$1$2');
text = text.replace(/\n{2,}/g, '\n'); text = text.replace(/\n{2,}/g, '\n');
text = text.replace(/\s{2,}/g, ' '); 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; return text;
}; };