mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-03 07:33:45 +00:00
feat: compaction
This commit is contained in:
@@ -29,6 +29,7 @@ export namespace SessionCompaction {
|
||||
}
|
||||
|
||||
const COMPACTION_BUFFER = 20_000
|
||||
const COMPACTION_BUFFER_TOOTHFAIRYAI = 100_000
|
||||
|
||||
export async function isOverflow(input: { tokens: MessageV2.Assistant["tokens"]; model: Provider.Model }) {
|
||||
const config = await Config.get()
|
||||
@@ -40,8 +41,11 @@ export namespace SessionCompaction {
|
||||
input.tokens.total ||
|
||||
input.tokens.input + input.tokens.output + input.tokens.cache.read + input.tokens.cache.write
|
||||
|
||||
const reserved =
|
||||
config.compaction?.reserved ?? Math.min(COMPACTION_BUFFER, ProviderTransform.maxOutputTokens(input.model))
|
||||
const defaultBuffer =
|
||||
input.model.providerID === "toothfairyai"
|
||||
? COMPACTION_BUFFER_TOOTHFAIRYAI
|
||||
: Math.min(COMPACTION_BUFFER, ProviderTransform.maxOutputTokens(input.model))
|
||||
const reserved = config.compaction?.reserved ?? defaultBuffer
|
||||
const usable = input.model.limit.input
|
||||
? input.model.limit.input - reserved
|
||||
: context - ProviderTransform.maxOutputTokens(input.model)
|
||||
|
||||
Reference in New Issue
Block a user