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

@@ -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 是预期回答或补充。' : '。'
}`
};
}