mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-01 20:27:45 +00:00
perf: 文本截取
This commit is contained in:
@@ -110,12 +110,13 @@ export const openaiChatFilter = (prompts: ChatItemType[], maxTokens: number) =>
|
||||
// 从后往前截取
|
||||
for (let i = formatPrompts.length - 1; i >= 0; i--) {
|
||||
const tokens = encode(formatPrompts[i].value).length;
|
||||
if (maxTokens >= tokens) {
|
||||
res.unshift(formatPrompts[i]);
|
||||
maxTokens -= tokens;
|
||||
} else {
|
||||
res.unshift(formatPrompts[i]);
|
||||
/* 整体 tokens 超出范围 */
|
||||
if (tokens >= maxTokens) {
|
||||
break;
|
||||
}
|
||||
|
||||
maxTokens -= tokens;
|
||||
}
|
||||
|
||||
return systemPrompt ? [systemPrompt, ...res] : res;
|
||||
|
Reference in New Issue
Block a user