Repository navigation
Expand file tree
/
Copy pathmain_test.go
More file actions
132 lines (121 loc) · 3.44 KB
/
Copy pathmain_test.go
File metadata and controls
132 lines (121 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"testing"
openai "github.com/sashabaranov/go-openai"
)
func TestIsReasoningModel(t *testing.T) {
tests := []struct {
model string
expected bool
}{
{"gpt-4o", false},
{"gpt-4.1-mini", false},
{"gpt-5", true},
{"gpt-5.6-luna", true},
{"o1-preview", true},
{"o3-mini", true},
{"o4-mini", true},
{"llama3", false},
{"claude-sonnet-4-5", false},
{"", false},
}
for _, tt := range tests {
t.Run(tt.model, func(t *testing.T) {
if got := isReasoningModel(tt.model); got != tt.expected {
t.Errorf("isReasoningModel(%q) = %v, want %v", tt.model, got, tt.expected)
}
})
}
}
func TestBuildChatRequest(t *testing.T) {
messages := []openai.ChatCompletionMessage{
{Role: openai.ChatMessageRoleUser, Content: "Hello"},
}
tests := []struct {
name string
config *Config
expectedMaxTokens int
expectedMaxCompletionTokens int
expectedTemperature float32
}{
{
name: "Standard model uses max_tokens and temperature",
config: &Config{Model: "gpt-4o", MaxTokens: 1000, Temperature: 0.7},
expectedMaxTokens: 1000,
expectedTemperature: 0.7,
},
{
name: "Reasoning model remaps max_tokens",
config: &Config{
Model: "gpt-5.6-luna",
MaxTokens: 1000,
Temperature: 0.7,
},
expectedMaxCompletionTokens: 1000,
expectedTemperature: 0,
},
{
name: "Explicit max_completion_tokens takes precedence",
config: &Config{
Model: "gpt-4o",
MaxTokens: 1000,
MaxCompletionTokens: 2000,
Temperature: 0.7,
},
expectedMaxCompletionTokens: 2000,
expectedTemperature: 0.7,
},
{
name: "Reasoning model with explicit max_completion_tokens",
config: &Config{
Model: "o3-mini",
MaxTokens: 1000,
MaxCompletionTokens: 2000,
Temperature: 1,
},
expectedMaxCompletionTokens: 2000,
expectedTemperature: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req := buildChatRequest(tt.config, messages, nil)
if req.MaxTokens != tt.expectedMaxTokens { //nolint:staticcheck // Verify legacy max_tokens compatibility.
//nolint:staticcheck // Report the legacy field.
t.Errorf("MaxTokens = %d, want %d", req.MaxTokens, tt.expectedMaxTokens)
}
if req.MaxCompletionTokens != tt.expectedMaxCompletionTokens {
t.Errorf(
"MaxCompletionTokens = %d, want %d",
req.MaxCompletionTokens,
tt.expectedMaxCompletionTokens,
)
}
if req.Temperature != tt.expectedTemperature {
t.Errorf("Temperature = %f, want %f", req.Temperature, tt.expectedTemperature)
}
if req.Model != tt.config.Model {
t.Errorf("Model = %q, want %q", req.Model, tt.config.Model)
}
})
}
}
func TestBuildChatRequestWithTool(t *testing.T) {
messages := []openai.ChatCompletionMessage{
{Role: openai.ChatMessageRoleUser, Content: "Hello"},
}
toolMeta, err := ParseToolSchema(
`{"name": "test_tool", "parameters": {"type": "object", "properties": {"result": {"type": "string"}}}}`,
)
if err != nil {
t.Fatalf("failed to parse tool schema: %v", err)
}
config := &Config{Model: "gpt-4o", MaxTokens: 1000, Temperature: 0.7}
req := buildChatRequest(config, messages, toolMeta)
if len(req.Tools) != 1 {
t.Fatalf("expected 1 tool, got %d", len(req.Tools))
}
if req.ToolChoice == nil {
t.Fatal("expected ToolChoice to be set")
}
}