Count hiddenPromptPrefix tokens
This commit is contained in:
parent
ac7d99948f
commit
15e988758f
|
@ -37,7 +37,7 @@
|
||||||
faLightbulb,
|
faLightbulb,
|
||||||
faCommentSlash
|
faCommentSlash
|
||||||
} from '@fortawesome/free-solid-svg-icons/index'
|
} from '@fortawesome/free-solid-svg-icons/index'
|
||||||
// import { encode } from 'gpt-tokenizer'
|
import { encode } from 'gpt-tokenizer'
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
import { countPromptTokens, getModelMaxTokens, getPrice } from './Stats.svelte'
|
import { countPromptTokens, getModelMaxTokens, getPrice } from './Stats.svelte'
|
||||||
import { autoGrowInputOnEvent, scrollToMessage, sizeTextElements } from './Util.svelte'
|
import { autoGrowInputOnEvent, scrollToMessage, sizeTextElements } from './Util.svelte'
|
||||||
|
@ -184,12 +184,16 @@
|
||||||
let filtered = messages.filter(messageFilter)
|
let filtered = messages.filter(messageFilter)
|
||||||
|
|
||||||
// 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 = countPromptTokens(filtered, model)
|
let promptTokenCount:number = countPromptTokens(filtered, model)
|
||||||
|
|
||||||
let summarySize = chatSettings.summarySize
|
let summarySize = chatSettings.summarySize
|
||||||
|
|
||||||
const hiddenPromptPrefix = mergeProfileFields(chatSettings, chatSettings.hiddenPromptPrefix).trim()
|
const hiddenPromptPrefix = mergeProfileFields(chatSettings, chatSettings.hiddenPromptPrefix).trim()
|
||||||
|
|
||||||
|
if (hiddenPromptPrefix && filtered.length && filtered[filtered.length - 1].role === 'user') {
|
||||||
|
promptTokenCount += encode(hiddenPromptPrefix + '\n\n').length
|
||||||
|
}
|
||||||
|
|
||||||
// console.log('Estimated',promptTokenCount,'prompt token for this request')
|
// console.log('Estimated',promptTokenCount,'prompt token for this request')
|
||||||
|
|
||||||
if (chatSettings.continuousChat && !opts.didSummary &&
|
if (chatSettings.continuousChat && !opts.didSummary &&
|
||||||
|
|
Loading…
Reference in New Issue