| 1 |
package openairesponses_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"encoding/json" |
| 6 |
"errors" |
| 7 |
"net/http" |
| 8 |
"net/http/httptest" |
| 9 |
"strings" |
| 10 |
"testing" |
| 11 |
|
| 12 |
"github.com/clnkr-ai/clnkr" |
| 13 |
"github.com/clnkr-ai/clnkr/internal/providers/openairesponses" |
| 14 |
) |
| 15 |
|
| 16 |
func TestModelQueryToolCalls(t *testing.T) { |
| 17 |
var gotBody map[string]any |
| 18 |
server := captureServer(t, &gotBody, func(w http.ResponseWriter, r *http.Request) { |
| 19 |
writeJSON(t, w, map[string]any{ |
| 20 |
"output": []map[string]any{ |
| 21 |
{"type": "reasoning", "id": "rs_1", "summary": []any{}}, |
| 22 |
{ |
| 23 |
"type": "function_call", |
| 24 |
"call_id": "call_1", |
| 25 |
"name": "bash", |
| 26 |
"arguments": `{"command":"pwd","workdir":null}`, |
| 27 |
"status": "completed", |
| 28 |
}, |
| 29 |
{ |
| 30 |
"type": "function_call", |
| 31 |
"call_id": "call_2", |
| 32 |
"name": "bash", |
| 33 |
"arguments": `{"command":"git status","workdir":null}`, |
| 34 |
"status": "completed", |
| 35 |
}, |
| 36 |
}, |
| 37 |
"usage": map[string]any{"input_tokens": 3, "output_tokens": 4}, |
| 38 |
}) |
| 39 |
}) |
| 40 |
defer server.Close() |
| 41 |
|
| 42 |
model := openairesponses.NewModelWithOptions( |
| 43 |
server.URL, |
| 44 |
"test-key", |
| 45 |
"gpt-5", |
| 46 |
"sys prompt", |
| 47 |
openairesponses.Options{UseBashToolCalls: true}, |
| 48 |
) |
| 49 |
resp, err := model.Query( |
| 50 |
context.Background(), |
| 51 |
[]clnkr.Message{{Role: "user", Content: "where"}}, |
| 52 |
) |
| 53 |
if err != nil { |
| 54 |
t.Fatalf("Query: %v", err) |
| 55 |
} |
| 56 |
|
| 57 |
if _, ok := gotBody["parallel_tool_calls"]; ok { |
| 58 |
t.Fatalf("parallel_tool_calls = %#v, want omitted", gotBody["parallel_tool_calls"]) |
| 59 |
} |
| 60 |
include, ok := gotBody["include"].([]any) |
| 61 |
if !ok || len(include) != 1 || include[0] != "reasoning.encrypted_content" { |
| 62 |
t.Fatalf("include = %#v, want reasoning.encrypted_content", gotBody["include"]) |
| 63 |
} |
| 64 |
tools, ok := gotBody["tools"].([]any) |
| 65 |
if !ok || len(tools) != 1 { |
| 66 |
t.Fatalf("tools = %#v, want one bash tool", gotBody["tools"]) |
| 67 |
} |
| 68 |
assertBashTool(t, tools[0]) |
| 69 |
|
| 70 |
act, ok := resp.Turn.(*clnkr.ActTurn) |
| 71 |
if !ok { |
| 72 |
t.Fatalf("Turn = %T, want *ActTurn", resp.Turn) |
| 73 |
} |
| 74 |
if got := len(act.Bash.Commands); got != 2 { |
| 75 |
t.Fatalf("commands = %d, want 2", got) |
| 76 |
} |
| 77 |
if got := act.Bash.Commands[0]; got.ID != "call_1" || got.Command != "pwd" { |
| 78 |
t.Fatalf("first command = %#v, want provider ID and command", got) |
| 79 |
} |
| 80 |
if got := act.Bash.Commands[1]; got.ID != "call_2" || got.Command != "git status" { |
| 81 |
t.Fatalf("second command = %#v, want provider ID and command", got) |
| 82 |
} |
| 83 |
if len(resp.BashToolCalls) != 2 || resp.BashToolCalls[0].ID != "call_1" || |
| 84 |
resp.BashToolCalls[1].ID != "call_2" { |
| 85 |
t.Fatalf("BashToolCalls = %#v", resp.BashToolCalls) |
| 86 |
} |
| 87 |
if len(resp.ProviderReplay) != 1 || resp.ProviderReplay[0].Type != "reasoning" { |
| 88 |
t.Fatalf("ProviderReplay = %#v", resp.ProviderReplay) |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
func TestModelQueryToolCallsPreservesWorkdir(t *testing.T) { |
| 93 |
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 94 |
writeJSON(t, w, map[string]any{ |
| 95 |
"output": []map[string]any{ |
| 96 |
{ |
| 97 |
"type": "function_call", |
| 98 |
"call_id": "call_1", |
| 99 |
"name": "bash", |
| 100 |
"arguments": `{"command":"pwd","workdir":"/tmp/project"}`, |
| 101 |
"status": "completed", |
| 102 |
}, |
| 103 |
}, |
| 104 |
"usage": map[string]any{"input_tokens": 3, "output_tokens": 4}, |
| 105 |
}) |
| 106 |
})) |
| 107 |
defer server.Close() |
| 108 |
|
| 109 |
model := openairesponses.NewModelWithOptions( |
| 110 |
server.URL, |
| 111 |
"test-key", |
| 112 |
"gpt-5", |
| 113 |
"sys prompt", |
| 114 |
openairesponses.Options{UseBashToolCalls: true}, |
| 115 |
) |
| 116 |
resp, err := model.Query( |
| 117 |
context.Background(), |
| 118 |
[]clnkr.Message{{Role: "user", Content: "where"}}, |
| 119 |
) |
| 120 |
if err != nil { |
| 121 |
t.Fatalf("Query: %v", err) |
| 122 |
} |
| 123 |
|
| 124 |
act, ok := resp.Turn.(*clnkr.ActTurn) |
| 125 |
if !ok { |
| 126 |
t.Fatalf("Turn = %T, want *ActTurn", resp.Turn) |
| 127 |
} |
| 128 |
if got := act.Bash.Commands[0]; got.Workdir != "/tmp/project" { |
| 129 |
t.Fatalf("command workdir = %q, want /tmp/project", got.Workdir) |
| 130 |
} |
| 131 |
if got := resp.BashToolCalls[0]; got.Workdir != "/tmp/project" { |
| 132 |
t.Fatalf("tool call workdir = %q, want /tmp/project", got.Workdir) |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
func TestModelQueryToolCallsRejectsInvalidFunctionCalls(t *testing.T) { |
| 137 |
tests := []struct { |
| 138 |
name string |
| 139 |
item map[string]any |
| 140 |
wantErr error |
| 141 |
wantError string |
| 142 |
}{ |
| 143 |
{ |
| 144 |
name: "missing call id", |
| 145 |
item: map[string]any{ |
| 146 |
"type": "function_call", |
| 147 |
"name": "bash", |
| 148 |
"arguments": `{"command":"pwd","workdir":null}`, |
| 149 |
"status": "completed", |
| 150 |
}, |
| 151 |
wantErr: clnkr.ErrInvalidJSON, |
| 152 |
wantError: "bash tool call missing call_id", |
| 153 |
}, |
| 154 |
{ |
| 155 |
name: "unsupported tool", |
| 156 |
item: map[string]any{ |
| 157 |
"type": "function_call", |
| 158 |
"call_id": "call_1", |
| 159 |
"name": "python", |
| 160 |
"arguments": `{"command":"pwd","workdir":null}`, |
| 161 |
"status": "completed", |
| 162 |
}, |
| 163 |
wantErr: clnkr.ErrInvalidJSON, |
| 164 |
wantError: `unsupported tool "python"`, |
| 165 |
}, |
| 166 |
{ |
| 167 |
name: "malformed arguments", |
| 168 |
item: map[string]any{ |
| 169 |
"type": "function_call", |
| 170 |
"call_id": "call_1", |
| 171 |
"name": "bash", |
| 172 |
"arguments": `{`, |
| 173 |
"status": "completed", |
| 174 |
}, |
| 175 |
wantErr: clnkr.ErrInvalidJSON, |
| 176 |
wantError: "malformed bash tool arguments", |
| 177 |
}, |
| 178 |
{ |
| 179 |
name: "unknown argument field", |
| 180 |
item: map[string]any{ |
| 181 |
"type": "function_call", |
| 182 |
"call_id": "call_1", |
| 183 |
"name": "bash", |
| 184 |
"arguments": `{"command":"pwd","workdir":null,"extra":true}`, |
| 185 |
"status": "completed", |
| 186 |
}, |
| 187 |
wantErr: clnkr.ErrInvalidJSON, |
| 188 |
wantError: "malformed bash tool arguments", |
| 189 |
}, |
| 190 |
{ |
| 191 |
name: "missing workdir", |
| 192 |
item: map[string]any{ |
| 193 |
"type": "function_call", |
| 194 |
"call_id": "call_1", |
| 195 |
"name": "bash", |
| 196 |
"arguments": `{"command":"pwd"}`, |
| 197 |
"status": "completed", |
| 198 |
}, |
| 199 |
wantErr: clnkr.ErrInvalidJSON, |
| 200 |
wantError: "bash tool arguments missing workdir", |
| 201 |
}, |
| 202 |
{ |
| 203 |
name: "empty command", |
| 204 |
item: map[string]any{ |
| 205 |
"type": "function_call", |
| 206 |
"call_id": "call_1", |
| 207 |
"name": "bash", |
| 208 |
"arguments": `{"command":" ","workdir":null}`, |
| 209 |
"status": "completed", |
| 210 |
}, |
| 211 |
wantErr: clnkr.ErrMissingCommand, |
| 212 |
wantError: clnkr.ErrMissingCommand.Error(), |
| 213 |
}, |
| 214 |
} |
| 215 |
|
| 216 |
for _, tt := range tests { |
| 217 |
t.Run(tt.name, func(t *testing.T) { |
| 218 |
server := httptest.NewServer( |
| 219 |
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 220 |
writeJSON(t, w, map[string]any{ |
| 221 |
"output": []map[string]any{tt.item}, |
| 222 |
"usage": map[string]any{"input_tokens": 3, "output_tokens": 4}, |
| 223 |
}) |
| 224 |
}), |
| 225 |
) |
| 226 |
defer server.Close() |
| 227 |
|
| 228 |
model := openairesponses.NewModelWithOptions( |
| 229 |
server.URL, |
| 230 |
"test-key", |
| 231 |
"gpt-5", |
| 232 |
"sys prompt", |
| 233 |
openairesponses.Options{UseBashToolCalls: true}, |
| 234 |
) |
| 235 |
resp, err := model.Query( |
| 236 |
context.Background(), |
| 237 |
[]clnkr.Message{{Role: "user", Content: "where"}}, |
| 238 |
) |
| 239 |
if err != nil { |
| 240 |
t.Fatalf("Query: %v", err) |
| 241 |
} |
| 242 |
if !errors.Is(resp.ProtocolErr, tt.wantErr) { |
| 243 |
t.Fatalf("ProtocolErr = %v, want %v", resp.ProtocolErr, tt.wantErr) |
| 244 |
} |
| 245 |
if !strings.Contains(resp.ProtocolErr.Error(), tt.wantError) { |
| 246 |
t.Fatalf( |
| 247 |
"ProtocolErr = %q, want containing %q", |
| 248 |
resp.ProtocolErr.Error(), |
| 249 |
tt.wantError, |
| 250 |
) |
| 251 |
} |
| 252 |
if resp.Usage.InputTokens != 3 || resp.Usage.OutputTokens != 4 { |
| 253 |
t.Fatalf("usage = %+v, want 3/4", resp.Usage) |
| 254 |
} |
| 255 |
}) |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
func TestModelQueryToolCallsRejectsInvalidOutputShape(t *testing.T) { |
| 260 |
tests := []struct { |
| 261 |
name string |
| 262 |
output []map[string]any |
| 263 |
wantQueryError string |
| 264 |
wantProtocolErr error |
| 265 |
wantProtocolText string |
| 266 |
}{ |
| 267 |
{ |
| 268 |
name: "mixed function call and text", |
| 269 |
output: []map[string]any{ |
| 270 |
{ |
| 271 |
"type": "function_call", |
| 272 |
"call_id": "call_1", |
| 273 |
"name": "bash", |
| 274 |
"arguments": `{"command":"pwd","workdir":null}`, |
| 275 |
"status": "completed", |
| 276 |
}, |
| 277 |
{ |
| 278 |
"type": "message", |
| 279 |
"role": "assistant", |
| 280 |
"content": []map[string]any{{"type": "output_text", "text": doneTurn("done")}}, |
| 281 |
}, |
| 282 |
}, |
| 283 |
wantProtocolErr: clnkr.ErrInvalidJSON, |
| 284 |
wantProtocolText: "mixed bash tool call and structured text", |
| 285 |
}, |
| 286 |
{ |
| 287 |
name: "missing output text and tool call", |
| 288 |
output: []map[string]any{ |
| 289 |
{"type": "message", "role": "assistant", "content": []map[string]any{}}, |
| 290 |
}, |
| 291 |
wantQueryError: "tool-call response: no usable output_text or bash tool call", |
| 292 |
}, |
| 293 |
{ |
| 294 |
name: "text act turn", |
| 295 |
output: []map[string]any{ |
| 296 |
{ |
| 297 |
"type": "message", |
| 298 |
"role": "assistant", |
| 299 |
"content": []map[string]any{ |
| 300 |
{ |
| 301 |
"type": "output_text", |
| 302 |
"text": `{"turn":{"type":"act","bash":{"commands":[{"command":"pwd","workdir":null}]},"question":null,"summary":null,"reasoning":null}}`, |
| 303 |
}, |
| 304 |
}, |
| 305 |
}, |
| 306 |
}, |
| 307 |
wantProtocolErr: clnkr.ErrInvalidJSON, |
| 308 |
wantProtocolText: "tool-call mode does not accept text act turns", |
| 309 |
}, |
| 310 |
{ |
| 311 |
name: "refusal", |
| 312 |
output: []map[string]any{ |
| 313 |
{ |
| 314 |
"type": "message", |
| 315 |
"role": "assistant", |
| 316 |
"content": []map[string]any{{"type": "refusal", "refusal": "refused"}}, |
| 317 |
}, |
| 318 |
}, |
| 319 |
wantQueryError: "tool-call refusal: refused", |
| 320 |
}, |
| 321 |
} |
| 322 |
|
| 323 |
for _, tt := range tests { |
| 324 |
t.Run(tt.name, func(t *testing.T) { |
| 325 |
server := httptest.NewServer( |
| 326 |
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 327 |
writeJSON(t, w, map[string]any{ |
| 328 |
"output": tt.output, |
| 329 |
"usage": map[string]any{"input_tokens": 3, "output_tokens": 4}, |
| 330 |
}) |
| 331 |
}), |
| 332 |
) |
| 333 |
defer server.Close() |
| 334 |
|
| 335 |
model := openairesponses.NewModelWithOptions( |
| 336 |
server.URL, |
| 337 |
"test-key", |
| 338 |
"gpt-5", |
| 339 |
"sys prompt", |
| 340 |
openairesponses.Options{UseBashToolCalls: true}, |
| 341 |
) |
| 342 |
resp, err := model.Query( |
| 343 |
context.Background(), |
| 344 |
[]clnkr.Message{{Role: "user", Content: "where"}}, |
| 345 |
) |
| 346 |
if tt.wantQueryError != "" { |
| 347 |
if err == nil || err.Error() != tt.wantQueryError { |
| 348 |
t.Fatalf("Query error = %v, want %q", err, tt.wantQueryError) |
| 349 |
} |
| 350 |
return |
| 351 |
} |
| 352 |
if err != nil { |
| 353 |
t.Fatalf("Query: %v", err) |
| 354 |
} |
| 355 |
if !errors.Is(resp.ProtocolErr, tt.wantProtocolErr) { |
| 356 |
t.Fatalf("ProtocolErr = %v, want %v", resp.ProtocolErr, tt.wantProtocolErr) |
| 357 |
} |
| 358 |
if !strings.Contains(resp.ProtocolErr.Error(), tt.wantProtocolText) { |
| 359 |
t.Fatalf( |
| 360 |
"ProtocolErr = %q, want containing %q", |
| 361 |
resp.ProtocolErr.Error(), |
| 362 |
tt.wantProtocolText, |
| 363 |
) |
| 364 |
} |
| 365 |
if resp.Usage.InputTokens != 3 || resp.Usage.OutputTokens != 4 { |
| 366 |
t.Fatalf("usage = %+v, want 3/4", resp.Usage) |
| 367 |
} |
| 368 |
}) |
| 369 |
} |
| 370 |
} |
| 371 |
|
| 372 |
func TestToolCallModelClassifiesFailedResponseContextLengthError(t *testing.T) { |
| 373 |
server := httptest.NewServer( |
| 374 |
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 375 |
writeJSON(t, w, map[string]any{ |
| 376 |
"status": "failed", |
| 377 |
"error": map[string]any{ |
| 378 |
"code": "context_length_exceeded", |
| 379 |
"message": "Your input exceeds the context window of this model.", |
| 380 |
}, |
| 381 |
}) |
| 382 |
}), |
| 383 |
) |
| 384 |
defer server.Close() |
| 385 |
|
| 386 |
model := openairesponses.NewModelWithOptions( |
| 387 |
server.URL, |
| 388 |
"test-key", |
| 389 |
"gpt-test", |
| 390 |
"sys", |
| 391 |
openairesponses.Options{UseBashToolCalls: true}, |
| 392 |
) |
| 393 |
_, err := model.Query(context.Background(), []clnkr.Message{{Role: "user", Content: "hi"}}) |
| 394 |
if !errors.Is(err, clnkr.ErrContextLengthExceeded) { |
| 395 |
t.Fatalf("Query error = %v, want ErrContextLengthExceeded", err) |
| 396 |
} |
| 397 |
if err == nil || !strings.Contains(err.Error(), "context_length_exceeded") { |
| 398 |
t.Fatalf("Query error = %v, want error code", err) |
| 399 |
} |
| 400 |
} |
| 401 |
|
| 402 |
func TestModelQueryToolCallsReplayToolMessagesWithoutDuplicateText(t *testing.T) { |
| 403 |
tests := []struct { |
| 404 |
name string |
| 405 |
replay json.RawMessage |
| 406 |
wantTypes []string |
| 407 |
wantReasonID string |
| 408 |
}{ |
| 409 |
{ |
| 410 |
name: "keeps encrypted reasoning", |
| 411 |
replay: json.RawMessage( |
| 412 |
`{"type":"reasoning","id":"rs_1","summary":[],"encrypted_content":"opaque"}`, |
| 413 |
), |
| 414 |
wantTypes: []string{"reasoning", "function_call", "function_call_output"}, |
| 415 |
wantReasonID: "rs_1", |
| 416 |
}, |
| 417 |
{ |
| 418 |
name: "skips reasoning without encrypted content", |
| 419 |
replay: json.RawMessage(`{"type":"reasoning","id":"rs_1","summary":[]}`), |
| 420 |
wantTypes: []string{"function_call", "function_call_output"}, |
| 421 |
}, |
| 422 |
} |
| 423 |
|
| 424 |
for _, tt := range tests { |
| 425 |
t.Run(tt.name, func(t *testing.T) { |
| 426 |
var gotBody map[string]any |
| 427 |
server := captureServer(t, &gotBody, func(w http.ResponseWriter, r *http.Request) { |
| 428 |
writeJSON(t, w, responseWithText(0, 0, doneTurn("ok"))) |
| 429 |
}) |
| 430 |
defer server.Close() |
| 431 |
|
| 432 |
model := openairesponses.NewModelWithOptions( |
| 433 |
server.URL, |
| 434 |
"test-key", |
| 435 |
"gpt-5", |
| 436 |
"sys prompt", |
| 437 |
openairesponses.Options{UseBashToolCalls: true}, |
| 438 |
) |
| 439 |
resp, err := model.Query(context.Background(), []clnkr.Message{ |
| 440 |
{ |
| 441 |
Role: "assistant", |
| 442 |
Content: `{"type":"act","bash":{"commands":[{"command":"pwd","workdir":"/tmp/project"}]}}`, |
| 443 |
BashToolCalls: []clnkr.BashToolCall{ |
| 444 |
{ID: "call_1", Command: "pwd", Workdir: "/tmp/project"}, |
| 445 |
}, |
| 446 |
ProviderReplay: []clnkr.ProviderReplayItem{ |
| 447 |
{ |
| 448 |
Provider: "openai", |
| 449 |
ProviderAPI: "openai-responses", |
| 450 |
Type: "reasoning", |
| 451 |
JSON: tt.replay, |
| 452 |
}, |
| 453 |
}, |
| 454 |
}, |
| 455 |
{ |
| 456 |
Role: "user", |
| 457 |
Content: "payload", |
| 458 |
BashToolResult: &clnkr.BashToolResult{ID: "call_1", Content: "payload"}, |
| 459 |
}, |
| 460 |
}) |
| 461 |
if err != nil { |
| 462 |
t.Fatalf("Query: %v", err) |
| 463 |
} |
| 464 |
if got, want := mustCanonicalTurn( |
| 465 |
t, |
| 466 |
resp.Turn, |
| 467 |
), canonicalDoneWithSummary( |
| 468 |
"ok", |
| 469 |
); got != want { |
| 470 |
t.Fatalf("canonical turn = %q, want %q", got, want) |
| 471 |
} |
| 472 |
if resp.ProtocolErr != nil { |
| 473 |
t.Fatalf("ProtocolErr = %v, want nil", resp.ProtocolErr) |
| 474 |
} |
| 475 |
gotInput := input(t, gotBody) |
| 476 |
if len(gotInput) != len(tt.wantTypes) { |
| 477 |
t.Fatalf("input = %#v, want %d items", gotInput, len(tt.wantTypes)) |
| 478 |
} |
| 479 |
for i, wantType := range tt.wantTypes { |
| 480 |
item := gotInput[i].(map[string]any) |
| 481 |
if item["type"] != wantType { |
| 482 |
t.Fatalf("input[%d] = %#v, want type %q", i, item, wantType) |
| 483 |
} |
| 484 |
} |
| 485 |
lastTwo := gotInput[len(gotInput)-2:] |
| 486 |
functionCall := lastTwo[0].(map[string]any) |
| 487 |
if functionCall["call_id"] != "call_1" { |
| 488 |
t.Fatalf("function_call = %#v, want call_1", functionCall) |
| 489 |
} |
| 490 |
var arguments struct { |
| 491 |
Command string `json:"command"` |
| 492 |
Workdir *string `json:"workdir"` |
| 493 |
} |
| 494 |
if err := json.Unmarshal( |
| 495 |
[]byte(functionCall["arguments"].(string)), |
| 496 |
&arguments, |
| 497 |
); err != nil { |
| 498 |
t.Fatalf("unmarshal function_call arguments: %v", err) |
| 499 |
} |
| 500 |
if arguments.Command != "pwd" || arguments.Workdir == nil || |
| 501 |
*arguments.Workdir != "/tmp/project" { |
| 502 |
t.Fatalf("function_call arguments = %#v, want command and workdir", arguments) |
| 503 |
} |
| 504 |
output := lastTwo[1].(map[string]any) |
| 505 |
if output["call_id"] != "call_1" || output["output"] != "payload" { |
| 506 |
t.Fatalf("function_call_output = %#v, want payload for call_1", output) |
| 507 |
} |
| 508 |
if tt.wantReasonID != "" { |
| 509 |
reasoning := gotInput[0].(map[string]any) |
| 510 |
if reasoning["id"] != tt.wantReasonID || |
| 511 |
reasoning["encrypted_content"] != "opaque" { |
| 512 |
t.Fatalf("reasoning = %#v, want opaque replay", reasoning) |
| 513 |
} |
| 514 |
} |
| 515 |
}) |
| 516 |
} |
| 517 |
} |
| 518 |
|
| 519 |
func TestModelQueryFinalOmitsBashTool(t *testing.T) { |
| 520 |
var gotBody map[string]any |
| 521 |
server := captureServer(t, &gotBody, func(w http.ResponseWriter, r *http.Request) { |
| 522 |
writeJSON(t, w, responseWithText(0, 0, doneTurn("final"))) |
| 523 |
}) |
| 524 |
defer server.Close() |
| 525 |
|
| 526 |
model := openairesponses.NewModelWithOptions( |
| 527 |
server.URL, |
| 528 |
"test-key", |
| 529 |
"gpt-5", |
| 530 |
"sys prompt", |
| 531 |
openairesponses.Options{UseBashToolCalls: true}, |
| 532 |
) |
| 533 |
if _, err := model.QueryFinal( |
| 534 |
context.Background(), |
| 535 |
[]clnkr.Message{{Role: "user", Content: "summarize"}}, |
| 536 |
); err != nil { |
| 537 |
t.Fatalf("QueryFinal: %v", err) |
| 538 |
} |
| 539 |
if _, ok := gotBody["tools"]; ok { |
| 540 |
t.Fatalf("tools = %#v, want omitted", gotBody["tools"]) |
| 541 |
} |
| 542 |
schema := gotBody["text"].(map[string]any)["format"].(map[string]any)["schema"].(map[string]any) |
| 543 |
choices := schema["properties"].(map[string]any)["turn"].(map[string]any)["anyOf"].([]any) |
| 544 |
if len(choices) != 1 { |
| 545 |
t.Fatalf("final schema choices = %#v, want done only", choices) |
| 546 |
} |
| 547 |
} |