mirror of
https://github.com/danielmiessler/Fabric.git
synced 2026-01-10 06:48:04 -05:00
refactor: extract token budget constants for thinking levels with validation bounds
## CHANGES - Extract hardcoded token values into named constants - Add comprehensive documentation for token budget purposes - Implement token validation bounds (1-10000) in parsing - Replace magic numbers with semantic constant references - Improve code maintainability through constant extraction
This commit is contained in:
@@ -10,9 +10,25 @@ const (
|
||||
ThinkingHigh ThinkingLevel = "high"
|
||||
)
|
||||
|
||||
// ThinkingBudgets defines standardized token budgets for reasoning-enabled models.
|
||||
// The map assigns a maximum token count to each ThinkingLevel, representing the
|
||||
// amount of context or computation that can be used for reasoning at that level.
|
||||
// These values (e.g., 1024 for low, 2048 for medium, 4096 for high) are used to
|
||||
// Token budget constants for each ThinkingLevel.
|
||||
// These values are chosen to align with typical context window sizes for LLMs at different reasoning levels.
|
||||
// Adjust these if model capabilities change.
|
||||
const (
|
||||
// TokenBudgetLow is suitable for basic reasoning or smaller models (e.g., 1k context window).
|
||||
TokenBudgetLow int64 = 1024
|
||||
// TokenBudgetMedium is suitable for intermediate reasoning or mid-sized models (e.g., 2k context window).
|
||||
TokenBudgetMedium int64 = 2048
|
||||
// TokenBudgetHigh is suitable for advanced reasoning or large models (e.g., 4k context window).
|
||||
TokenBudgetHigh int64 = 4096
|
||||
)
|
||||
|
||||
// ThinkingBudgets defines standardized token budgets for reasoning-enabled models.
|
||||
var ThinkingBudgets = map[ThinkingLevel]int64{
|
||||
ThinkingLow: 1024,
|
||||
ThinkingMedium: 2048,
|
||||
ThinkingHigh: 4096,
|
||||
ThinkingLow: TokenBudgetLow,
|
||||
ThinkingMedium: TokenBudgetMedium,
|
||||
ThinkingHigh: TokenBudgetHigh,
|
||||
}
|
||||
|
||||
@@ -167,7 +167,9 @@ func parseThinking(level domain.ThinkingLevel) (anthropic.ThinkingConfigParamUni
|
||||
}
|
||||
default:
|
||||
if tokens, err := strconv.ParseInt(lower, 10, 64); err == nil {
|
||||
return anthropic.ThinkingConfigParamOfEnabled(tokens), true
|
||||
if tokens >= 1 && tokens <= 10000 {
|
||||
return anthropic.ThinkingConfigParamOfEnabled(tokens), true
|
||||
}
|
||||
}
|
||||
}
|
||||
return anthropic.ThinkingConfigParamUnion{}, false
|
||||
|
||||
Reference in New Issue
Block a user