From 28ba6f3b16baf38c4d2bbb77aed8c9746ea9563e Mon Sep 17 00:00:00 2001 From: Rhys Jones Date: Tue, 29 Oct 2024 21:41:51 +0000 Subject: [PATCH] update parser builder --- .../APIHandler/AILanguageModelHandler.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/extension/background/APIHandler/AILanguageModelHandler.ts b/src/extension/background/APIHandler/AILanguageModelHandler.ts index f4ebdd2..091d2e4 100644 --- a/src/extension/background/APIHandler/AILanguageModelHandler.ts +++ b/src/extension/background/APIHandler/AILanguageModelHandler.ts @@ -75,22 +75,22 @@ class AILanguageModelHandler { let tokenCount = systemPrompt ? await AIPrompter.countTokens(systemPrompt, manifest.tokens.method) : 0 - const messagesWindow = [ - ...systemPrompt - ? [{ content: systemPrompt, role: 'system' }] - : [] - ] const history = [...initialPrompts, ...messages] + const countedMessages=[] for (let i = history.length - 1; i >= 0; i--) { const message = history[i] tokenCount += await AIPrompter.countTokens(message.content, manifest.tokens.method) if (tokenCount > manifest.tokens.max) { break } - messagesWindow.unshift(message) + countedMessages.unshift(message) } - messagesWindow.reverse() + const messagesWindow = [ + ...systemPrompt + ? [{ content: systemPrompt, role: 'system' }, ...countedMessages] + : countedMessages + ] // Send to the template const template = new Template(promptConfig.template)