limit prompt template

This commit is contained in:
archer
2023-09-05 18:15:42 +08:00
parent 9bf5a3ec76
commit fa3f3e6264
9 changed files with 31 additions and 24 deletions

View File

@@ -14,7 +14,7 @@
| FastAI4k - 对话 | 0.015 |
| FastAI16k - 对话 | 0.03 |
| FastAI-Plus - 对话 | 0.45 |
| 文件拆分 | 0.03 |
| 文件 QA 拆分 | 0.03 |
**其他问题**
| 交流群 | 小助手 |

View File

@@ -38,6 +38,7 @@
"Admin Mark Content": "Corrected response",
"Complete Response": "Complete Response",
"Confirm to clear history": "Confirm to clear history?",
"Confirm to clear share chat histroy": " Are you sure to delete all chats?",
"Exit Chat": "Exit",
"Feedback Close": "Close Feedback",
"Feedback Failed": "Feedback Failed",

View File

@@ -38,6 +38,7 @@
"Admin Mark Content": "纠正后的回复",
"Complete Response": "完整响应",
"Confirm to clear history": "确认清空该应用的在线聊天记录?分享和 API 调用的记录不会被清空。",
"Confirm to clear share chat histroy": "确认删除所有聊天记录?",
"Exit Chat": "退出聊天",
"Feedback Close": "关闭反馈",
"Feedback Failed": "提交反馈异常",

View File

@@ -80,7 +80,7 @@ const MermaidBlock = ({ code }: { code: string }) => {
ctx.fillRect(0, 0, w, h);
const img = new Image();
img.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(ref.current.innerHTML)}`;
img.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(ref.current?.innerHTML)}`;
img.onload = () => {
ctx.drawImage(img, 0, 0, w, h);

View File

@@ -20,7 +20,7 @@ import { ContextExtractEnum, HttpPropsEnum } from './flowField';
export const ChatModelSystemTip =
'模型固定的引导词,通过调整该内容,可以引导模型聊天方向。该内容会被固定在上下文的开头。可使用变量,例如 {{language}}';
export const ChatModelLimitTip =
'限定模型对话范围,会被放置在本次提问前,拥有强引导和限定性。可使用变量,例如 {{language}}。引导例子:\n1. 知识库是关于 Laf 的介绍,参考知识库回答问题,与 "Laf" 无关内容,直接回复: "我不知道"。\n2. 你仅回答关于 "xxx" 的问题,其他问题回复: "xxxx"';
'限定模型对话范围,会被放置在本次提问前,拥有强引导和限定性。不建议内容太长,会影响上下文,可使用变量,例如 {{language}}。可在文档中找到对应的限定例子';
export const userGuideTip = '可以添加特殊的对话前后引导模块,更好的让用户进行对话';
export const welcomeTextTip =
'每次对话开始前,发送一个初始内容。支持标准 Markdown 语法,可使用的额外标记:\n[快捷按键]: 用户点击后可以直接发送该问题';
@@ -156,6 +156,7 @@ export const ChatModule: FlowModuleTemplateType = {
key: 'systemPrompt',
type: FlowInputItemTypeEnum.textarea,
label: '系统提示词',
max: 300,
valueType: FlowValueTypeEnum.string,
description: ChatModelSystemTip,
placeholder: ChatModelSystemTip,
@@ -166,6 +167,7 @@ export const ChatModule: FlowModuleTemplateType = {
type: FlowInputItemTypeEnum.textarea,
valueType: FlowValueTypeEnum.string,
label: '限定词',
max: 500,
description: ChatModelLimitTip,
placeholder: ChatModelLimitTip,
value: ''
@@ -175,6 +177,7 @@ export const ChatModule: FlowModuleTemplateType = {
key: 'quoteQA',
type: FlowInputItemTypeEnum.target,
label: '引用内容',
description: "对象数组格式,结构:\n [{q:'问题',a:'回答'}]",
valueType: FlowValueTypeEnum.kbQuote
},
Input_Template_History,
@@ -666,6 +669,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] =
type: 'textarea',
valueType: 'string',
label: '限定词',
max: 500,
description:
'限定模型对话范围,会被放置在本次提问前,拥有强引导和限定性。可使用变量,例如 {{language}}。引导例子:\n1. 知识库是关于 Laf 的介绍,参考知识库回答问题,与 "Laf" 无关内容,直接回复: "我不知道"。\n2. 你仅回答关于 "xxx" 的问题,其他问题回复: "xxxx"',
placeholder:

View File

@@ -104,7 +104,7 @@ const PayModal = ({ onClose }: { onClose: () => void }) => {
| FastAI4k - 对话 | 0.015 |
| FastAI16k - 对话 | 0.03 |
| FastAI-Plus - 对话 | 0.45 |
| 文件拆分 | 0.03 |`}
| 文件QA拆分 | 0.03 |`}
/>
</>
)}

View File

@@ -67,13 +67,17 @@ const ChatHistorySlider = ({
const [currentTab, setCurrentTab] = useState<`${TabEnum}`>(TabEnum.history);
const isShare = useMemo(() => !appId || !userInfo, [appId, userInfo]);
// custom title edit
const { onOpenModal, EditModal: EditTitleModal } = useEditInfo({
title: '自定义历史记录标题',
placeholder: '如果设置为空,会自动跟随聊天记录。'
});
const { openConfirm, ConfirmModal } = useConfirm({
content: t('chat.Confirm to clear history')
content: isShare
? t('chat.Confirm to clear share chat histroy')
: t('chat.Confirm to clear history')
});
const concatHistory = useMemo<HistoryItemType[]>(
@@ -82,8 +86,6 @@ const ChatHistorySlider = ({
[activeChatId, history, t]
);
const isShare = useMemo(() => !appId || !userInfo, [appId, userInfo]);
useQuery(['init'], () => {
if (isShare) {
setCurrentTab(TabEnum.history);

View File

@@ -237,25 +237,16 @@ function getChatMessages({
model: ChatModelItemType;
hasQuoteOutput: boolean;
}) {
const limitText = (() => {
if (!quotePrompt) {
return limitPrompt;
}
const defaultPrompt = `三引号引用的内容是我提供给你的知识它们拥有最高优先级。instruction 是相关介绍${
hasQuoteOutput ? 'output 是预期回答或补充' : ''
},使用引用内容来回答我下面的问题。`;
if (limitPrompt) {
return `${defaultPrompt}${limitPrompt}`;
}
return `${defaultPrompt}\n回答内容限制你仅回答三引号中提及的内容下面我提出的问题与引用内容无关时你可以直接回复: "你的问题没有在知识库中体现"`;
})();
const { quoteGuidePrompt } = getDefaultPrompt({ hasQuoteOutput });
const systemText = `${quotePrompt ? `${quoteGuidePrompt}\n\n` : ''}${systemPrompt}`;
const messages: ChatItemType[] = [
...(systemPrompt
...(systemText
? [
{
obj: ChatRoleEnum.System,
value: systemPrompt
value: systemText
}
]
: []),
@@ -268,11 +259,11 @@ function getChatMessages({
]
: []),
...history,
...(limitText
...(limitPrompt
? [
{
obj: ChatRoleEnum.System,
value: limitText
value: limitPrompt
}
]
: []),
@@ -385,3 +376,11 @@ async function streamResponse({
answer
};
}
function getDefaultPrompt({ hasQuoteOutput }: { hasQuoteOutput?: boolean }) {
return {
quoteGuidePrompt: `三引号引用的内容是我提供给你的知识库它们拥有最高优先级。instruction 是相关介绍${
hasQuoteOutput ? 'output 是预期回答或补充。' : '。'
}`
};
}

View File

@@ -36,7 +36,7 @@ export type EditFormType = {
};
export const getDefaultAppForm = (): EditFormType => {
const defaultChatModel = chatModelList[0];
const defaultVectorModel = vectorModelList[0];
return {
chatModel: {
model: defaultChatModel.model,