More accurate token estimates

This commit is contained in:
Webifi 2023-05-28 20:32:22 -05:00
parent 74d296cac7
commit 8297041059
1 changed files with 6 additions and 2 deletions

View File

@ -160,9 +160,13 @@
// Get an estimate of the total prompt size we're sending // Get an estimate of the total prompt size we're sending
const promptTokenCount:number = filtered.reduce((a, m) => { const promptTokenCount:number = filtered.reduce((a, m) => {
a += encode(m.content).length + 8 // + 8, always seems to under count by around 8 // Not sure how OpenAI formats it, but this seems to get close to the right counts
// Sure would be nice to know
a += encode('## ' + m.role + " ##:\r\n\r\n" + m.content + "\r\n\r\n\r\n").length
return a return a
}, 0) }, 0) + 3
// console.log('Estimated',promptTokenCount,'prompt token for this request')
if (chatSettings.useSummarization && if (chatSettings.useSummarization &&
!withSummary && !doingSummary && !withSummary && !doingSummary &&