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

Method Apply

internal/thinking/provider/codex/apply.go:44–85  ·  view source on GitHub ↗

Apply applies thinking configuration to Codex request body. Expected output format: { "reasoning": { "effort": "high" } }

(body []byte, config thinking.ThinkingConfig, modelInfo *registry.ModelInfo)

Source from the content-addressed store, hash-verified

42// }
43// }
44func (a *Applier) Apply(body []byte, config thinking.ThinkingConfig, modelInfo *registry.ModelInfo) ([]byte, error) {
45 if thinking.IsUserDefinedModel(modelInfo) {
46 return applyCompatibleCodex(body, config)
47 }
48 if modelInfo.Thinking == nil {
49 return body, nil
50 }
51
52 // Only handle ModeLevel and ModeNone; other modes pass through unchanged.
53 if config.Mode != thinking.ModeLevel && config.Mode != thinking.ModeNone {
54 return body, nil
55 }
56
57 if len(body) == 0 || !gjson.ValidBytes(body) {
58 body = []byte(`{}`)
59 }
60
61 if config.Mode == thinking.ModeLevel {
62 result, _ := sjson.SetBytes(body, "reasoning.effort", string(config.Level))
63 return result, nil
64 }
65
66 effort := ""
67 support := modelInfo.Thinking
68 if config.Budget == 0 {
69 if support.ZeroAllowed || thinking.HasLevel(support.Levels, string(thinking.LevelNone)) {
70 effort = string(thinking.LevelNone)
71 }
72 }
73 if effort == "" && config.Level != "" {
74 effort = string(config.Level)
75 }
76 if effort == "" && len(support.Levels) > 0 {
77 effort = support.Levels[0]
78 }
79 if effort == "" {
80 return body, nil
81 }
82
83 result, _ := sjson.SetBytes(body, "reasoning.effort", effort)
84 return result, nil
85}
86
87func applyCompatibleCodex(body []byte, config thinking.ThinkingConfig) ([]byte, error) {
88 if len(body) == 0 || !gjson.ValidBytes(body) {

Callers

nothing calls this directly

Calls 3

IsUserDefinedModelFunction · 0.92
HasLevelFunction · 0.92
applyCompatibleCodexFunction · 0.85

Tested by

no test coverage detected