hkfires commited on
Commit
d43abb5
·
1 Parent(s): b01fb05

Revert "Merge pull request #1627 from thebtf/fix/reasoning-effort-clamping"

Browse files
internal/thinking/provider/openai/apply.go CHANGED
@@ -10,53 +10,10 @@ import (
10
 
11
  "github.com/router-for-me/CLIProxyAPI/v6/internal/registry"
12
  "github.com/router-for-me/CLIProxyAPI/v6/internal/thinking"
13
- log "github.com/sirupsen/logrus"
14
  "github.com/tidwall/gjson"
15
  "github.com/tidwall/sjson"
16
  )
17
 
18
- // validReasoningEffortLevels contains the standard values accepted by the
19
- // OpenAI reasoning_effort field. Provider-specific extensions (xhigh, minimal,
20
- // auto) are NOT in this set and must be clamped before use.
21
- var validReasoningEffortLevels = map[string]struct{}{
22
- "none": {},
23
- "low": {},
24
- "medium": {},
25
- "high": {},
26
- }
27
-
28
- // clampReasoningEffort maps any thinking level string to a value that is safe
29
- // to send as OpenAI reasoning_effort. Non-standard CPA-internal values are
30
- // mapped to the nearest standard equivalent.
31
- //
32
- // Mapping rules:
33
- // - none / low / medium / high → returned as-is (already valid)
34
- // - xhigh → "high" (nearest lower standard level)
35
- // - minimal → "low" (nearest higher standard level)
36
- // - auto → "medium" (reasonable default)
37
- // - anything else → "medium" (safe default)
38
- func clampReasoningEffort(level string) string {
39
- if _, ok := validReasoningEffortLevels[level]; ok {
40
- return level
41
- }
42
- var clamped string
43
- switch level {
44
- case string(thinking.LevelXHigh):
45
- clamped = string(thinking.LevelHigh)
46
- case string(thinking.LevelMinimal):
47
- clamped = string(thinking.LevelLow)
48
- case string(thinking.LevelAuto):
49
- clamped = string(thinking.LevelMedium)
50
- default:
51
- clamped = string(thinking.LevelMedium)
52
- }
53
- log.WithFields(log.Fields{
54
- "original": level,
55
- "clamped": clamped,
56
- }).Debug("openai: reasoning_effort clamped to nearest valid standard value")
57
- return clamped
58
- }
59
-
60
  // Applier implements thinking.ProviderApplier for OpenAI models.
61
  //
62
  // OpenAI-specific behavior:
@@ -101,7 +58,7 @@ func (a *Applier) Apply(body []byte, config thinking.ThinkingConfig, modelInfo *
101
  }
102
 
103
  if config.Mode == thinking.ModeLevel {
104
- result, _ := sjson.SetBytes(body, "reasoning_effort", clampReasoningEffort(string(config.Level)))
105
  return result, nil
106
  }
107
 
@@ -122,7 +79,7 @@ func (a *Applier) Apply(body []byte, config thinking.ThinkingConfig, modelInfo *
122
  return body, nil
123
  }
124
 
125
- result, _ := sjson.SetBytes(body, "reasoning_effort", clampReasoningEffort(effort))
126
  return result, nil
127
  }
128
 
@@ -157,7 +114,7 @@ func applyCompatibleOpenAI(body []byte, config thinking.ThinkingConfig) ([]byte,
157
  return body, nil
158
  }
159
 
160
- result, _ := sjson.SetBytes(body, "reasoning_effort", clampReasoningEffort(effort))
161
  return result, nil
162
  }
163
 
 
10
 
11
  "github.com/router-for-me/CLIProxyAPI/v6/internal/registry"
12
  "github.com/router-for-me/CLIProxyAPI/v6/internal/thinking"
 
13
  "github.com/tidwall/gjson"
14
  "github.com/tidwall/sjson"
15
  )
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  // Applier implements thinking.ProviderApplier for OpenAI models.
18
  //
19
  // OpenAI-specific behavior:
 
58
  }
59
 
60
  if config.Mode == thinking.ModeLevel {
61
+ result, _ := sjson.SetBytes(body, "reasoning_effort", string(config.Level))
62
  return result, nil
63
  }
64
 
 
79
  return body, nil
80
  }
81
 
82
+ result, _ := sjson.SetBytes(body, "reasoning_effort", effort)
83
  return result, nil
84
  }
85
 
 
114
  return body, nil
115
  }
116
 
117
+ result, _ := sjson.SetBytes(body, "reasoning_effort", effort)
118
  return result, nil
119
  }
120