Refactor token counting after completion. Simplify code.

This commit is contained in:
maver
2023-07-21 16:13:25 +02:00
parent dfd49813af
commit 57fd04b974
2 changed files with 32 additions and 11 deletions

View File

@ -512,7 +512,7 @@ function populateDialogueExamples(prompts, chatCompletion) {
* @param {string} options.type - The type of the chat, can be 'impersonate'.
*/
function populateChatCompletion (prompts, chatCompletion, {bias, quietPrompt, type, cyclePrompt} = {}) {
//Helper function for the recurring task of preparing a prompt for the chat completion
// Helper function for the recurring task of preparing a prompt for the chat completion
const addToChatCompletion = (source, target = null) => {
// We need the prompts array to determine a position for the source.
if (false === prompts.has(source)) return;
@ -779,9 +779,8 @@ function prepareOpenAIMessages({
chatCompletion.log(error);
}
} finally {
const messages = chatCompletion.getMessages();
if (null === promptManager.error) promptManager.populateTokenHandler(messages);
promptManager.setMessages(messages);
// Pass chat completion to prompt manager for inspection
promptManager.setChatCompletion(chatCompletion);
// All information are up-to-date, render.
if (false === dryRun) promptManager.render(false);