fix: v1 api

This commit is contained in:
archer
2023-06-24 21:39:34 +08:00
parent 057c3411b9
commit 5be57da407
2 changed files with 34 additions and 15 deletions

View File

@@ -65,10 +65,14 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
const modelConstantsData = ChatModelMap[model.chat.chatModel]; const modelConstantsData = ChatModelMap[model.chat.chatModel];
const prompt = prompts[prompts.length - 1]; const prompt = prompts[prompts.length - 1];
const { userSystemPrompt = [], quotePrompt = [] } = await (async () => { const {
userSystemPrompt = [],
userLimitPrompt = [],
quotePrompt = []
} = await (async () => {
// 使用了知识库搜索 // 使用了知识库搜索
if (model.chat.relatedKbs?.length > 0) { if (model.chat.relatedKbs?.length > 0) {
const { userSystemPrompt, quotePrompt } = await appKbSearch({ const { quotePrompt, userSystemPrompt, userLimitPrompt } = await appKbSearch({
model, model,
userId, userId,
fixedQuote: [], fixedQuote: [],
@@ -78,21 +82,29 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
}); });
return { return {
userSystemPrompt: userSystemPrompt ? [userSystemPrompt] : [], userSystemPrompt,
userLimitPrompt,
quotePrompt: [quotePrompt] quotePrompt: [quotePrompt]
}; };
} }
if (model.chat.systemPrompt) { return {
return { userSystemPrompt: model.chat.systemPrompt
userSystemPrompt: [ ? [
{ {
obj: ChatRoleEnum.System, obj: ChatRoleEnum.System,
value: model.chat.systemPrompt value: model.chat.systemPrompt
} }
] ]
}; : [],
} userLimitPrompt: model.chat.limitPrompt
return {}; ? [
{
obj: ChatRoleEnum.Human,
value: model.chat.limitPrompt
}
]
: []
};
})(); })();
// search result is empty // search result is empty
@@ -102,7 +114,13 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
} }
// 读取对话内容 // 读取对话内容
const completePrompts = [...quotePrompt, ...prompts.slice(0, -1), ...userSystemPrompt, prompt]; const completePrompts = [
...quotePrompt,
...userSystemPrompt,
...prompts.slice(0, -1),
...userLimitPrompt,
prompt
];
// 计算温度 // 计算温度
const temperature = (modelConstantsData.maxTemperature * (model.chat.temperature / 10)).toFixed( const temperature = (modelConstantsData.maxTemperature * (model.chat.temperature / 10)).toFixed(

View File

@@ -238,6 +238,7 @@ export const V2_StreamResponse = async ({
} }
if (error) { if (error) {
console.log(error);
return Promise.reject(error); return Promise.reject(error);
} }