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

Function clampLevel

internal/thinking/validate.go:218–259  ·  view source on GitHub ↗

clampLevel clamps the given level to the nearest supported level. On tie, prefers the lower level.

(level ThinkingLevel, modelInfo *registry.ModelInfo, provider string)

Source from the content-addressed store, hash-verified

216// clampLevel clamps the given level to the nearest supported level.
217// On tie, prefers the lower level.
218func clampLevel(level ThinkingLevel, modelInfo *registry.ModelInfo, provider string) ThinkingLevel {
219 model := "unknown"
220 var supported []string
221 if modelInfo != nil {
222 if modelInfo.ID != "" {
223 model = modelInfo.ID
224 }
225 if modelInfo.Thinking != nil {
226 supported = modelInfo.Thinking.Levels
227 }
228 }
229
230 if len(supported) == 0 || isLevelSupported(string(level), supported) {
231 return level
232 }
233
234 pos := levelIndex(string(level))
235 if pos == -1 {
236 return level
237 }
238 bestIdx, bestDist := -1, len(standardLevelOrder)+1
239
240 for _, s := range supported {
241 if idx := levelIndex(strings.TrimSpace(s)); idx != -1 {
242 if dist := abs(pos - idx); dist < bestDist || (dist == bestDist && idx < bestIdx) {
243 bestIdx, bestDist = idx, dist
244 }
245 }
246 }
247
248 if bestIdx >= 0 {
249 clamped := standardLevelOrder[bestIdx]
250 log.WithFields(log.Fields{
251 "provider": provider,
252 "model": model,
253 "original_value": string(level),
254 "clamped_to": string(clamped),
255 }).Debug("thinking: level clamped |")
256 return clamped
257 }
258 return level
259}
260
261// clampBudget clamps a budget value to the model's supported range.
262func clampBudget(value int, modelInfo *registry.ModelInfo, provider string) int {

Callers 1

ValidateConfigFunction · 0.85

Calls 3

isLevelSupportedFunction · 0.85
levelIndexFunction · 0.85
absFunction · 0.85

Tested by

no test coverage detected