merge
This commit is contained in:
@@ -105,11 +105,12 @@ export const searchKb = async ({
|
||||
: [
|
||||
{
|
||||
obj: ChatRoleEnum.System,
|
||||
value: `我们来玩问答游戏,规则为:
|
||||
1.你只能回答关于"${model.name}"的问题
|
||||
2.你只能从知识库中选择内容进行回答
|
||||
3.如果问题不在知识库中,你会回答"我不知道。"
|
||||
务必遵守规则`
|
||||
value: `玩一个问答游戏,规则为:
|
||||
1.你完全忘记你已有的知识
|
||||
2.你只回答关于"${model.name}"的问题
|
||||
3.你只从知识库中选择内容进行回答
|
||||
4.如果问题不在知识库中,你会回答:"我不知道。"
|
||||
请务必遵守规则`
|
||||
}
|
||||
])
|
||||
];
|
||||
@@ -125,7 +126,8 @@ export const searchKb = async ({
|
||||
length: Math.floor(maxTokens * rate)
|
||||
})
|
||||
)
|
||||
.join('\n');
|
||||
.join('\n')
|
||||
.trim();
|
||||
|
||||
/* 高相似度+不回复 */
|
||||
if (!filterSystemPrompt && model.chat.searchMode === ModelVectorSearchModeEnum.hightSimilarity) {
|
||||
@@ -160,7 +162,7 @@ export const searchKb = async ({
|
||||
searchPrompts: [
|
||||
{
|
||||
obj: ChatRoleEnum.System,
|
||||
value: `知识库:'${filterSystemPrompt}'`
|
||||
value: `知识库:${filterSystemPrompt}`
|
||||
},
|
||||
...fixedPrompts
|
||||
]
|
||||
|
||||
@@ -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: '',
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -109,35 +109,22 @@ export const ChatContextFilter = ({
|
||||
|
||||
// 根据 tokens 截断内容
|
||||
const chats: ChatItemSimpleType[] = [];
|
||||
let systemPrompt: ChatItemSimpleType | null = null;
|
||||
|
||||
// System 词保留
|
||||
if (formatPrompts[0].obj === ChatRoleEnum.System) {
|
||||
const prompt = formatPrompts.shift();
|
||||
if (prompt) {
|
||||
systemPrompt = prompt;
|
||||
}
|
||||
}
|
||||
|
||||
let messages: ChatItemSimpleType[] = [];
|
||||
|
||||
// 从后往前截取对话内容
|
||||
for (let i = formatPrompts.length - 1; i >= 0; i--) {
|
||||
chats.unshift(formatPrompts[i]);
|
||||
|
||||
messages = systemPrompt ? [systemPrompt, ...chats] : chats;
|
||||
|
||||
const tokens = modelToolMap[model].countTokens({
|
||||
messages
|
||||
messages: chats
|
||||
});
|
||||
|
||||
/* 整体 tokens 超出范围 */
|
||||
if (tokens >= maxTokens) {
|
||||
return systemPrompt ? [systemPrompt, ...chats.slice(1)] : chats.slice(1);
|
||||
/* 整体 tokens 超出范围, system必须保留 */
|
||||
if (tokens >= maxTokens && formatPrompts[i].obj !== ChatRoleEnum.System) {
|
||||
return chats.slice(1);
|
||||
}
|
||||
}
|
||||
|
||||
return messages;
|
||||
return chats;
|
||||
};
|
||||
|
||||
/* stream response */
|
||||
|
||||
Reference in New Issue
Block a user