mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-29 21:33:54 +00:00
feat: compaction
This commit is contained in:
parent
e581d80c7a
commit
191f907b2d
2
bun.lock
2
bun.lock
@ -381,7 +381,7 @@
|
||||
},
|
||||
"packages/tfcode": {
|
||||
"name": "tfcode",
|
||||
"version": "1.0.7",
|
||||
"version": "1.0.8",
|
||||
"bin": {
|
||||
"tfcode": "./bin/tfcode",
|
||||
},
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"version": "1.0.7",
|
||||
"version": "1.0.8",
|
||||
"name": "tfcode",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user