Do not count messages with empty prompts

This commit is contained in:
maver 2023-06-22 20:22:55 +02:00
parent 6617243f1b
commit 312b02c36e
1 changed files with 11 additions and 4 deletions

View File

@ -1164,7 +1164,12 @@ class Message {
this.identifier = identifier;
this.role = role;
this.content = content;
this.tokens = tokenHandler.count(this);
if (this.content) {
this.tokens = tokenHandler.count({role: this.role, content: this.content})
} else {
this.tokens = 0;
}
}
static fromPrompt(prompt) {
@ -1219,8 +1224,8 @@ class ChatCompletion {
}
setTokenBudget(context, response) {
console.log(`Context size: ${context}`);
console.log(`Response size: ${response}`);
console.log(`Prompt tokens: ${context}`);
console.log(`Completion tokens: ${response}`);
this.tokenBudget = context - response;
@ -1238,6 +1243,7 @@ class ChatCompletion {
}
this.decreaseTokenBudgetBy(collection.getTokens());
this.log(`Added ${collection.identifier}. Remaining tokens: ${this.tokenBudget}`);
return this;
@ -1261,12 +1267,13 @@ class ChatCompletion {
else if ('end' === position) this.messages.collection[index].collection.push(message);
this.decreaseTokenBudgetBy(message.getTokens());
this.log(`Inserted ${message.identifier} into ${identifier}. Remaining tokens: ${this.tokenBudget}`);
}
}
canAfford(message) {
return 0 < this.tokenBudget - message.getTokens();
return 0 <= this.tokenBudget - message.getTokens();
}
has(identifier) {