improve dispatch cancellation and token estimates

This commit is contained in:
lpf
2026-05-11 12:43:41 +08:00
parent 97df340960
commit eb781cef25
6 changed files with 435 additions and 11 deletions

View File

@@ -202,14 +202,5 @@ func applyAttemptFailure(base *HTTPProvider, attempt authAttempt, reason oauthFa
}
func estimateOpenAICompatTokenCount(body map[string]interface{}) (int, error) {
data, err := json.Marshal(body)
if err != nil {
return 0, fmt.Errorf("failed to encode request for token count: %w", err)
}
const charsPerToken = 4
count := (len(data) + charsPerToken - 1) / charsPerToken
if count < 1 {
count = 1
}
return count, nil
return EstimateOpenAICompatRequestTokens(body)
}