MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / clampBudget

Function clampBudget

internal/thinking/validate.go:262–310  ·  view source on GitHub ↗

clampBudget clamps a budget value to the model's supported range.

(value int, modelInfo *registry.ModelInfo, provider string)

Source from the content-addressed store, hash-verified

260
261// clampBudget clamps a budget value to the model's supported range.
262func clampBudget(value int, modelInfo *registry.ModelInfo, provider string) int {
263 model := "unknown"
264 support := (*registry.ThinkingSupport)(nil)
265 if modelInfo != nil {
266 if modelInfo.ID != "" {
267 model = modelInfo.ID
268 }
269 support = modelInfo.Thinking
270 }
271 if support == nil {
272 return value
273 }
274
275 // Auto value (-1) passes through without clamping.
276 if value == -1 {
277 return value
278 }
279
280 min, max := support.Min, support.Max
281 if value == 0 && !support.ZeroAllowed {
282 log.WithFields(log.Fields{
283 "provider": provider,
284 "model": model,
285 "original_value": value,
286 "clamped_to": min,
287 "min": min,
288 "max": max,
289 }).Warn("thinking: budget zero not allowed |")
290 return min
291 }
292
293 // Some models are level-only and do not define numeric budget ranges.
294 if min == 0 && max == 0 {
295 return value
296 }
297
298 if value < min {
299 if value == 0 && support.ZeroAllowed {
300 return 0
301 }
302 logClamp(provider, model, value, min, min, max)
303 return min
304 }
305 if value > max {
306 logClamp(provider, model, value, max, min, max)
307 return max
308 }
309 return value
310}
311
312func isLevelSupported(level string, supported []string) bool {
313 for _, s := range supported {

Callers 1

ValidateConfigFunction · 0.85

Calls 1

logClampFunction · 0.85

Tested by

no test coverage detected