Do not count messages with empty prompts
This commit is contained in:
parent
6617243f1b
commit
312b02c36e
|
@ -1164,7 +1164,12 @@ class Message {
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
this.role = role;
|
this.role = role;
|
||||||
this.content = content;
|
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) {
|
static fromPrompt(prompt) {
|
||||||
|
@ -1219,8 +1224,8 @@ class ChatCompletion {
|
||||||
}
|
}
|
||||||
|
|
||||||
setTokenBudget(context, response) {
|
setTokenBudget(context, response) {
|
||||||
console.log(`Context size: ${context}`);
|
console.log(`Prompt tokens: ${context}`);
|
||||||
console.log(`Response size: ${response}`);
|
console.log(`Completion tokens: ${response}`);
|
||||||
|
|
||||||
this.tokenBudget = context - response;
|
this.tokenBudget = context - response;
|
||||||
|
|
||||||
|
@ -1238,6 +1243,7 @@ class ChatCompletion {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.decreaseTokenBudgetBy(collection.getTokens());
|
this.decreaseTokenBudgetBy(collection.getTokens());
|
||||||
|
|
||||||
this.log(`Added ${collection.identifier}. Remaining tokens: ${this.tokenBudget}`);
|
this.log(`Added ${collection.identifier}. Remaining tokens: ${this.tokenBudget}`);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -1261,12 +1267,13 @@ class ChatCompletion {
|
||||||
else if ('end' === position) this.messages.collection[index].collection.push(message);
|
else if ('end' === position) this.messages.collection[index].collection.push(message);
|
||||||
|
|
||||||
this.decreaseTokenBudgetBy(message.getTokens());
|
this.decreaseTokenBudgetBy(message.getTokens());
|
||||||
|
|
||||||
this.log(`Inserted ${message.identifier} into ${identifier}. Remaining tokens: ${this.tokenBudget}`);
|
this.log(`Inserted ${message.identifier} into ${identifier}. Remaining tokens: ${this.tokenBudget}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
canAfford(message) {
|
canAfford(message) {
|
||||||
return 0 < this.tokenBudget - message.getTokens();
|
return 0 <= this.tokenBudget - message.getTokens();
|
||||||
}
|
}
|
||||||
|
|
||||||
has(identifier) {
|
has(identifier) {
|
||||||
|
|
Loading…
Reference in New Issue