mirror of
https://github.com/laoxong/nofx.git
synced 2026-06-04 09:58:22 +08:00
feat: enhance token estimation and context limit handling in strategy configurations
This commit is contained in:
+25
-1
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
// Hard limits to prevent token explosion in AI requests
|
||||
const (
|
||||
MaxCandidateCoins = 3
|
||||
MaxCandidateCoins = 50
|
||||
MaxPositions = 3
|
||||
MaxTimeframes = 4
|
||||
MinKlineCount = 10
|
||||
@@ -622,6 +622,30 @@ func GetContextLimit(provider string) int {
|
||||
return 131072 // safe default
|
||||
}
|
||||
|
||||
// GetContextLimitForClient returns context limit for a provider+model pair.
|
||||
// For claw402, the underlying model is inferred from the model name prefix.
|
||||
func GetContextLimitForClient(provider, model string) int {
|
||||
if provider == "claw402" {
|
||||
switch {
|
||||
case strings.HasPrefix(model, "claude"):
|
||||
return ModelContextLimits["claude"]
|
||||
case strings.HasPrefix(model, "gpt"), strings.HasPrefix(model, "o1"), strings.HasPrefix(model, "o3"):
|
||||
return ModelContextLimits["openai"]
|
||||
case strings.HasPrefix(model, "gemini"):
|
||||
return ModelContextLimits["gemini"]
|
||||
case strings.HasPrefix(model, "grok"):
|
||||
return ModelContextLimits["grok"]
|
||||
case strings.HasPrefix(model, "kimi"):
|
||||
return ModelContextLimits["kimi"]
|
||||
case strings.HasPrefix(model, "qwen"):
|
||||
return ModelContextLimits["qwen"]
|
||||
default:
|
||||
return ModelContextLimits["deepseek"]
|
||||
}
|
||||
}
|
||||
return GetContextLimit(provider)
|
||||
}
|
||||
|
||||
// EstimateTokens estimates the total token count for a strategy configuration.
|
||||
// This is a pure computation based on config fields — no network calls.
|
||||
func (c *StrategyConfig) EstimateTokens() TokenEstimate {
|
||||
|
||||
Reference in New Issue
Block a user