Skip to content

Commit 3c3a32e

Browse files
sirozhaclaude
andcommitted
test(openai): assert xhigh/max reach the request body
Wire-level regression guard for the GetEffort clamp removal: a re-clamp to high would send "high" on the openai-compatible path. Covers both the legacy reasoning_effort string and the modern reasoning.effort object. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 12b63aa commit 3c3a32e

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package openai
2+
3+
import (
4+
"context"
5+
"io"
6+
"net/http"
7+
"net/http/httptest"
8+
"strings"
9+
"testing"
10+
11+
"github.com/vxcontrol/langchaingo/llms"
12+
)
13+
14+
// Guards the GetEffort clamp removal at the wire level: xhigh/max must reach the
15+
// request body, not be downgraded to high (legacy reasoning_effort and modern reasoning.effort).
16+
func TestReasoningEffortPassthroughToWire(t *testing.T) {
17+
t.Parallel()
18+
19+
const completion = `{"id":"x","object":"chat.completion","created":1,"model":"m",` +
20+
`"choices":[{"index":0,"message":{"role":"assistant","content":"ok"},"finish_reason":"stop"}],` +
21+
`"usage":{"prompt_tokens":1,"completion_tokens":1,"total_tokens":2}}`
22+
23+
cases := []struct {
24+
name string
25+
effort llms.ReasoningEffort
26+
modern bool
27+
want string
28+
}{
29+
{"legacy xhigh", llms.ReasoningXHigh, false, `"reasoning_effort":"xhigh"`},
30+
{"legacy max", llms.ReasoningMax, false, `"reasoning_effort":"max"`},
31+
{"modern xhigh", llms.ReasoningXHigh, true, `"effort":"xhigh"`},
32+
{"modern max", llms.ReasoningMax, true, `"effort":"max"`},
33+
}
34+
35+
for _, tc := range cases {
36+
t.Run(tc.name, func(t *testing.T) {
37+
var body string
38+
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
39+
b, _ := io.ReadAll(r.Body)
40+
body = string(b)
41+
w.Header().Set("Content-Type", "application/json")
42+
_, _ = io.WriteString(w, completion)
43+
}))
44+
defer srv.Close()
45+
46+
opts := []Option{WithBaseURL(srv.URL), WithToken("test"), WithModel("reasoning-model")}
47+
if tc.modern {
48+
opts = append(opts, WithModernReasoningFormat())
49+
}
50+
llm, err := New(opts...)
51+
if err != nil {
52+
t.Fatalf("New() error: %v", err)
53+
}
54+
55+
if _, err := llm.GenerateContent(
56+
context.Background(),
57+
[]llms.MessageContent{llms.TextParts(llms.ChatMessageTypeHuman, "hi")},
58+
llms.WithReasoning(tc.effort, 0),
59+
); err != nil {
60+
t.Fatalf("GenerateContent() error: %v", err)
61+
}
62+
63+
if !strings.Contains(body, tc.want) {
64+
t.Fatalf("wire body missing %s\nbody: %s", tc.want, body)
65+
}
66+
})
67+
}
68+
}

0 commit comments

Comments
 (0)