perf: prompt and gpt4

This commit is contained in:
archer
2023-05-10 12:03:54 +08:00
parent e3c9b8179e
commit cdf4b9f324
12 changed files with 47 additions and 24 deletions

View File

@@ -105,11 +105,11 @@ export const searchKb = async ({
: [
{
obj: ChatRoleEnum.System,
value: `我们玩问答游戏,规则为:
value: `我们玩问答游戏,规则为:
1.你完全忘记你已有的知识
2.你只能回答关于"${model.name}"的问题
3.你只能从知识库中选择内容进行回答
4.如果问题不在知识库中,你回答"我不知道。"
4.如果问题不在知识库中,你必须回答:我不知道。
务必遵守规则`
}
])
@@ -161,7 +161,7 @@ export const searchKb = async ({
searchPrompts: [
{
obj: ChatRoleEnum.System,
value: `知识库:'${filterSystemPrompt}'`
value: `知识库:${filterSystemPrompt}`
},
...fixedPrompts
]

View File

@@ -55,11 +55,11 @@ export const getApiKey = async ({
},
[OpenAiChatEnum.GPT4]: {
userOpenAiKey: user.openaiKey || '',
systemAuthKey: process.env.OPENAIKEY as string
systemAuthKey: process.env.GPT4KEY as string
},
[OpenAiChatEnum.GPT432k]: {
userOpenAiKey: user.openaiKey || '',
systemAuthKey: process.env.OPENAIKEY as string
systemAuthKey: process.env.GPT4KEY as string
},
[ClaudeEnum.Claude]: {
userOpenAiKey: '',

View File

@@ -25,9 +25,9 @@ export const lafClaudChat = async ({
.filter((item) => item.obj === 'System')
.map((item) => item.value)
.join('\n');
const systemPromptText = systemPrompt ? `\n知识库内容:'${systemPrompt}'\n` : '';
const systemPromptText = systemPrompt ? `你本次知识:${systemPrompt}\n` : '';
const prompt = `${systemPromptText}\n我的问题是:'${messages[messages.length - 1].value}'`;
const prompt = `${systemPromptText}我的问题是:'${messages[messages.length - 1].value}'`;
const lafResponse = await axios.post(
'https://hnvacz.laf.run/claude-gpt',

View File

@@ -118,8 +118,8 @@ export const ChatContextFilter = ({
messages: chats
});
/* 整体 tokens 超出范围 */
if (tokens >= maxTokens) {
/* 整体 tokens 超出范围, system必须保留 */
if (tokens >= maxTokens && formatPrompts[i].obj !== ChatRoleEnum.System) {
return chats.slice(1);
}
}