feat: add TokenTracker for managing token usage, costs, and context.
This commit is contained in:
@@ -37,15 +37,15 @@ internal sealed class TokenTracker
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns true if the context is getting too large and should be compacted.
|
/// Returns true if the context is getting too large and should be compacted.
|
||||||
/// Triggers at min(75% of model context, 100K tokens).
|
/// Triggers at min(75% of model context, 150K tokens).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool ShouldCompact()
|
public bool ShouldCompact()
|
||||||
{
|
{
|
||||||
if (LastInputTokens <= 0) return false;
|
if (LastInputTokens <= 0) return false;
|
||||||
|
|
||||||
int threshold = ContextLength > 0
|
int threshold = ContextLength > 0
|
||||||
? Math.Min((int)(ContextLength * 0.75), 100_000)
|
? Math.Min((int)(ContextLength * 0.75), 150_000)
|
||||||
: 100_000;
|
: 150_000;
|
||||||
|
|
||||||
return LastInputTokens >= threshold;
|
return LastInputTokens >= threshold;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user