Skip to content

Commit 2824ff8

Browse files
committed
Migrate to github.com/openai/openai-go
Signed-off-by: David Gageot <[email protected]>
1 parent 8846feb commit 2824ff8

26 files changed

+624
-426
lines changed

e2e/cagent_exec_test.go

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,28 @@ import (
1212
"github.com/docker/cagent/cmd/root"
1313
)
1414

15-
func TestExec_BasicOpenAI(t *testing.T) {
16-
out := cagentExec(t, "testdata/basic.yaml", "Who's djordje?")
15+
func TestExec_OpenAI(t *testing.T) {
16+
out := cagentExec(t, "testdata/basic.yaml", "What's 2+2?")
1717

18-
require.Equal(t, `
19-
--- Agent: root ---
20-
21-
Djordje is a common Serbian given name. It may refer to different individuals depending on the context. If you provide more information or details, I can help you identify the specific Djordje you are referring to.`,
22-
out)
18+
require.Equal(t, "\n--- Agent: root ---\n\n2 + 2 equals 4.", out)
2319
}
2420

25-
func TestExec_BasicAnthropic(t *testing.T) {
26-
out := cagentExec(t, "testdata/basic.yaml", "--model=anthropic/claude-sonnet-4-0", "Who's djordje?. Be super concise.")
27-
28-
require.Equal(t, `
29-
--- Agent: root ---
21+
func TestExec_OpenAI_gpt5(t *testing.T) {
22+
out := cagentExec(t, "testdata/basic.yaml", "--model=openai/gpt-5", "What's 2+2?")
3023

31-
I need more context. There are many people named Djordje (a Serbian name). Could you specify which Djordje you're asking about?`,
32-
out)
24+
require.Equal(t, "\n--- Agent: root ---\n\n4", out)
3325
}
3426

35-
func TestExec_BasicGemini(t *testing.T) {
36-
out := cagentExec(t, "testdata/basic.yaml", "--model=google/gemini-2.5-flash", "Who's djordje?. Be super concise.")
27+
func TestExec_Anthropic(t *testing.T) {
28+
out := cagentExec(t, "testdata/basic.yaml", "--model=anthropic/claude-sonnet-4-0", "What's 2+2?")
29+
30+
require.Equal(t, "\n--- Agent: root ---\n\n2 + 2 = 4", out)
31+
}
3732

38-
require.Equal(t, `
39-
--- Agent: root ---
33+
func TestExec_Gemini(t *testing.T) {
34+
out := cagentExec(t, "testdata/basic.yaml", "--model=google/gemini-2.5-flash", "What's 2+2?")
4035

41-
Serbian equivalent of the name George.`,
42-
out)
36+
require.Equal(t, "\n--- Agent: root ---\n\n2+2=4", out)
4337
}
4438

4539
func TestExec_ToolCallsNeedAcceptance(t *testing.T) {

e2e/mcp_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestMCP_SingleAgent(t *testing.T) {
2828
})
2929

3030
require.NoError(t, err)
31-
assert.Equal(t, "2+2 equals 4.", output.Response)
31+
assert.Equal(t, "2 + 2 equals 4.", output.Response)
3232
}
3333

3434
func TestMCP_MultiAgent(t *testing.T) {
@@ -49,5 +49,5 @@ func TestMCP_MultiAgent(t *testing.T) {
4949
})
5050

5151
require.NoError(t, err)
52-
assert.Equal(t, "Hello, nice to meet you.", output.Response)
52+
assert.Equal(t, "Hello! How can I assist you today?", output.Response)
5353
}

e2e/runtime_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ func TestRuntime_OpenAI_Basic(t *testing.T) {
2323
rt, err := runtime.New(team)
2424
require.NoError(t, err)
2525

26-
sess := session.New(session.WithUserMessage("", "Who's djordje?"))
26+
sess := session.New(session.WithUserMessage("", "What's 2+2?"))
2727
_, err = rt.Run(ctx, sess)
2828
require.NoError(t, err)
2929

3030
response := sess.GetLastAssistantMessageContent()
31-
assert.Equal(t, "Djordje is a popular given name in some Eastern European countries, such as Serbia. If you have more specific information or context, I'd be happy to help further.", response)
32-
assert.Equal(t, "Understanding identity: Who is Djordje?", sess.Title)
31+
assert.Equal(t, "2 + 2 equals 4.", response)
32+
assert.Equal(t, "Basic Arithmetic: Addition of 2 and 2", sess.Title)
3333
}
3434

3535
func TestRuntime_Mistral_Basic(t *testing.T) {
@@ -44,11 +44,11 @@ func TestRuntime_Mistral_Basic(t *testing.T) {
4444
rt, err := runtime.New(team)
4545
require.NoError(t, err)
4646

47-
sess := session.New(session.WithUserMessage("", "Who's djordje?"))
47+
sess := session.New(session.WithUserMessage("", "What's 2+2?"))
4848
_, err = rt.Run(ctx, sess)
4949
require.NoError(t, err)
5050

5151
response := sess.GetLastAssistantMessageContent()
52-
assert.Equal(t, `It seems like "djordje" is a name, most likely of Slavic origin. It is commonly spelled as "Đorđe" in Serbian language, and it means "farmer" or "earthworker". It is a masculine given name, and it is quite popular in Serbia, Montenegro, and other countries in the region. Without more context, it's hard to say exactly who "djordje" is, as it could refer to any person by that name.`, response)
53-
assert.Equal(t, `"Inquiry About the Identity of 'Djordje'"`, sess.Title)
52+
assert.Equal(t, "The sum of 2 + 2 is 4.", response)
53+
assert.Equal(t, "Math Basics: Simple Addition", sess.Title)
5454
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
version: 2
3+
interactions:
4+
- id: 0
5+
request:
6+
proto: HTTP/1.1
7+
proto_major: 1
8+
proto_minor: 1
9+
content_length: 0
10+
host: api.anthropic.com
11+
body: "{\"messages\":[{\"content\":[{\"text\":\"What's 2+2?\",\"type\":\"text\"}],\"role\":\"user\"}],\"model\":\"claude-sonnet-4-0\",\"system\":[{\"text\":\"You are a knowledgeable assistant that helps users with various tasks.\\nBe helpful, accurate, and concise in your responses.\",\"type\":\"text\"}]}"
12+
url: https://api.anthropic.com/v1/messages/count_tokens
13+
method: POST
14+
response:
15+
proto: HTTP/2.0
16+
proto_major: 2
17+
proto_minor: 0
18+
content_length: 19
19+
body: "{\"input_tokens\":42}"
20+
headers: {}
21+
status: 200 OK
22+
code: 200
23+
duration: 230.075958ms
24+
- id: 1
25+
request:
26+
proto: HTTP/1.1
27+
proto_major: 1
28+
proto_minor: 1
29+
content_length: 0
30+
host: api.anthropic.com
31+
body: "{\"max_tokens\":8192,\"messages\":[{\"content\":[{\"text\":\"What's 2+2?\",\"type\":\"text\"}],\"role\":\"user\"}],\"model\":\"claude-sonnet-4-0\",\"system\":[{\"text\":\"You are a knowledgeable assistant that helps users with various tasks.\\nBe helpful, accurate, and concise in your responses.\",\"type\":\"text\"}],\"tools\":[],\"stream\":true}"
32+
url: https://api.anthropic.com/v1/messages
33+
method: POST
34+
response:
35+
proto: HTTP/2.0
36+
proto_major: 2
37+
proto_minor: 0
38+
content_length: -1
39+
body: "event: message_start\ndata: {\"type\":\"message_start\",\"message\":{\"model\":\"claude-sonnet-4-20250514\",\"id\":\"msg_01DR37NtN4R23L1CbJQqUshY\",\"type\":\"message\",\"role\":\"assistant\",\"content\":[],\"stop_reason\":null,\"stop_sequence\":null,\"usage\":{\"input_tokens\":42,\"cache_creation_input_tokens\":0,\"cache_read_input_tokens\":0,\"cache_creation\":{\"ephemeral_5m_input_tokens\":0,\"ephemeral_1h_input_tokens\":0},\"output_tokens\":1,\"service_tier\":\"standard\"}} }\n\nevent: content_block_start\ndata: {\"type\":\"content_block_start\",\"index\":0,\"content_block\":{\"type\":\"text\",\"text\":\"\"}}\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\"2 + 2 = 4\"} }\n\nevent: ping\ndata: {\"type\": \"ping\"}\n\nevent: content_block_stop\ndata: {\"type\":\"content_block_stop\",\"index\":0 }\n\nevent: ping\ndata: {\"type\": \"ping\"}\n\nevent: ping\ndata: {\"type\": \"ping\"}\n\nevent: message_delta\ndata: {\"type\":\"message_delta\",\"delta\":{\"stop_reason\":\"end_turn\",\"stop_sequence\":null},\"usage\":{\"input_tokens\":42,\"cache_creation_input_tokens\":0,\"cache_read_input_tokens\":0,\"output_tokens\":13} }\n\nevent: message_stop\ndata: {\"type\":\"message_stop\" }\n\n"
40+
headers: {}
41+
status: 200 OK
42+
code: 200
43+
duration: 1.904056709s

e2e/testdata/cassettes/TestExec_BasicAnthropic.yaml

Lines changed: 0 additions & 43 deletions
This file was deleted.

e2e/testdata/cassettes/TestExec_BasicOpenAI.yaml

Lines changed: 0 additions & 23 deletions
This file was deleted.

e2e/testdata/cassettes/TestExec_BasicGemini.yaml renamed to e2e/testdata/cassettes/TestExec_Gemini.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interactions:
88
proto_minor: 1
99
content_length: 0
1010
host: generativelanguage.googleapis.com
11-
body: "{\"contents\":[{\"parts\":[{\"text\":\"You are a knowledgeable assistant that helps users with various tasks.\\nBe helpful, accurate, and concise in your responses.\\n\"}],\"role\":\"user\"},{\"parts\":[{\"text\":\"Who's djordje?. Be super concise.\"}],\"role\":\"user\"}],\"generationConfig\":{\"frequencyPenalty\":0,\"presencePenalty\":0,\"temperature\":0,\"topP\":0}}\n"
11+
body: "{\"contents\":[{\"parts\":[{\"text\":\"You are a knowledgeable assistant that helps users with various tasks.\\nBe helpful, accurate, and concise in your responses.\\n\"}],\"role\":\"user\"},{\"parts\":[{\"text\":\"What's 2+2?\"}],\"role\":\"user\"}],\"generationConfig\":{}}\n"
1212
form:
1313
alt:
1414
- sse
@@ -19,8 +19,8 @@ interactions:
1919
proto_major: 2
2020
proto_minor: 0
2121
content_length: -1
22-
body: "data: {\"candidates\": [{\"content\": {\"parts\": [{\"text\": \"Serbian equivalent of the name George.\"}],\"role\": \"model\"},\"finishReason\": \"STOP\",\"index\": 0}],\"usageMetadata\": {\"promptTokenCount\": 38,\"candidatesTokenCount\": 8,\"totalTokenCount\": 105,\"promptTokensDetails\": [{\"modality\": \"TEXT\",\"tokenCount\": 38}],\"thoughtsTokenCount\": 59},\"modelVersion\": \"gemini-2.5-flash\",\"responseId\": \"Z7wIadPPD73BnsEPk-SmgAU\"}\r\n\r\n"
22+
body: "data: {\"candidates\": [{\"content\": {\"parts\": [{\"text\": \"2+2=4\"}],\"role\": \"model\"},\"finishReason\": \"STOP\",\"index\": 0}],\"usageMetadata\": {\"promptTokenCount\": 35,\"candidatesTokenCount\": 5,\"totalTokenCount\": 86,\"promptTokensDetails\": [{\"modality\": \"TEXT\",\"tokenCount\": 35}],\"thoughtsTokenCount\": 46},\"modelVersion\": \"gemini-2.5-flash\",\"responseId\": \"WM4NaY27K_fqkdUP3_q7iA8\"}\r\n\r\n"
2323
headers: {}
2424
status: 200 OK
2525
code: 200
26-
duration: 692.427375ms
26+
duration: 700.886458ms
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
version: 2
3+
interactions:
4+
- id: 0
5+
request:
6+
proto: HTTP/1.1
7+
proto_major: 1
8+
proto_minor: 1
9+
content_length: 0
10+
host: api.openai.com
11+
body: "{\"messages\":[{\"content\":\"You are a knowledgeable assistant that helps users with various tasks.\\nBe helpful, accurate, and concise in your responses.\\n\",\"role\":\"system\"},{\"content\":\"What's 2+2?\",\"role\":\"user\"}],\"model\":\"gpt-3.5-turbo\",\"stream_options\":{\"include_usage\":true},\"stream\":true}"
12+
url: https://api.openai.com/v1/chat/completions
13+
method: POST
14+
response:
15+
proto: HTTP/2.0
16+
proto_major: 2
17+
proto_minor: 0
18+
content_length: -1
19+
body: "data: {\"id\":\"chatcmpl-CZEIJqJbOML9fooYQTOSrJOZ2aJj5\",\"object\":\"chat.completion.chunk\",\"created\":1762512463,\"model\":\"gpt-3.5-turbo-0125\",\"service_tier\":\"default\",\"system_fingerprint\":null,\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"\",\"refusal\":null},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null,\"obfuscation\":\"MfhikzAX\"}\n\ndata: {\"id\":\"chatcmpl-CZEIJqJbOML9fooYQTOSrJOZ2aJj5\",\"object\":\"chat.completion.chunk\",\"created\":1762512463,\"model\":\"gpt-3.5-turbo-0125\",\"service_tier\":\"default\",\"system_fingerprint\":null,\"choices\":[{\"index\":0,\"delta\":{\"content\":\"2\"},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null,\"obfuscation\":\"fC37t4UAx\"}\n\ndata: {\"id\":\"chatcmpl-CZEIJqJbOML9fooYQTOSrJOZ2aJj5\",\"object\":\"chat.completion.chunk\",\"created\":1762512463,\"model\":\"gpt-3.5-turbo-0125\",\"service_tier\":\"default\",\"system_fingerprint\":null,\"choices\":[{\"index\":0,\"delta\":{\"content\":\" +\"},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null,\"obfuscation\":\"PfLRw4oY\"}\n\ndata: {\"id\":\"chatcmpl-CZEIJqJbOML9fooYQTOSrJOZ2aJj5\",\"object\":\"chat.completion.chunk\",\"created\":1762512463,\"model\":\"gpt-3.5-turbo-0125\",\"service_tier\":\"default\",\"system_fingerprint\":null,\"choices\":[{\"index\":0,\"delta\":{\"content\":\" \"},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null,\"obfuscation\":\"1q5rpQiCb\"}\n\ndata: {\"id\":\"chatcmpl-CZEIJqJbOML9fooYQTOSrJOZ2aJj5\",\"object\":\"chat.completion.chunk\",\"created\":1762512463,\"model\":\"gpt-3.5-turbo-0125\",\"service_tier\":\"default\",\"system_fingerprint\":null,\"choices\":[{\"index\":0,\"delta\":{\"content\":\"2\"},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null,\"obfuscation\":\"v05gclnta\"}\n\ndata: {\"id\":\"chatcmpl-CZEIJqJbOML9fooYQTOSrJOZ2aJj5\",\"object\":\"chat.completion.chunk\",\"created\":1762512463,\"model\":\"gpt-3.5-turbo-0125\",\"service_tier\":\"default\",\"system_fingerprint\":null,\"choices\":[{\"index\":0,\"delta\":{\"content\":\" equals\"},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null,\"obfuscation\":\"aAa\"}\n\ndata: {\"id\":\"chatcmpl-CZEIJqJbOML9fooYQTOSrJOZ2aJj5\",\"object\":\"chat.completion.chunk\",\"created\":1762512463,\"model\":\"gpt-3.5-turbo-0125\",\"service_tier\":\"default\",\"system_fingerprint\":null,\"choices\":[{\"index\":0,\"delta\":{\"content\":\" \"},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null,\"obfuscation\":\"jTM4v8YZ7\"}\n\ndata: {\"id\":\"chatcmpl-CZEIJqJbOML9fooYQTOSrJOZ2aJj5\",\"object\":\"chat.completion.chunk\",\"created\":1762512463,\"model\":\"gpt-3.5-turbo-0125\",\"service_tier\":\"default\",\"system_fingerprint\":null,\"choices\":[{\"index\":0,\"delta\":{\"content\":\"4\"},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null,\"obfuscation\":\"N12COihd5\"}\n\ndata: {\"id\":\"chatcmpl-CZEIJqJbOML9fooYQTOSrJOZ2aJj5\",\"object\":\"chat.completion.chunk\",\"created\":1762512463,\"model\":\"gpt-3.5-turbo-0125\",\"service_tier\":\"default\",\"system_fingerprint\":null,\"choices\":[{\"index\":0,\"delta\":{\"content\":\".\"},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null,\"obfuscation\":\"cERVljx9R\"}\n\ndata: {\"id\":\"chatcmpl-CZEIJqJbOML9fooYQTOSrJOZ2aJj5\",\"object\":\"chat.completion.chunk\",\"created\":1762512463,\"model\":\"gpt-3.5-turbo-0125\",\"service_tier\":\"default\",\"system_fingerprint\":null,\"choices\":[{\"index\":0,\"delta\":{},\"logprobs\":null,\"finish_reason\":\"stop\"}],\"usage\":null,\"obfuscation\":\"UnnX\"}\n\ndata: {\"id\":\"chatcmpl-CZEIJqJbOML9fooYQTOSrJOZ2aJj5\",\"object\":\"chat.completion.chunk\",\"created\":1762512463,\"model\":\"gpt-3.5-turbo-0125\",\"service_tier\":\"default\",\"system_fingerprint\":null,\"choices\":[],\"usage\":{\"prompt_tokens\":41,\"completion_tokens\":8,\"total_tokens\":49,\"prompt_tokens_details\":{\"cached_tokens\":0,\"audio_tokens\":0},\"completion_tokens_details\":{\"reasoning_tokens\":0,\"audio_tokens\":0,\"accepted_prediction_tokens\":0,\"rejected_prediction_tokens\":0}},\"obfuscation\":\"sRPYvSflJj\"}\n\ndata: [DONE]\n\n"
20+
headers: {}
21+
status: 200 OK
22+
code: 200
23+
duration: 931.787875ms
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
version: 2
3+
interactions:
4+
- id: 0
5+
request:
6+
proto: HTTP/1.1
7+
proto_major: 1
8+
proto_minor: 1
9+
content_length: 0
10+
host: api.openai.com
11+
body: "{\"messages\":[{\"content\":\"You are a knowledgeable assistant that helps users with various tasks.\\nBe helpful, accurate, and concise in your responses.\\n\",\"role\":\"system\"},{\"content\":\"What's 2+2?\",\"role\":\"user\"}],\"model\":\"gpt-5\",\"stream_options\":{\"include_usage\":true},\"stream\":true}"
12+
url: https://api.openai.com/v1/chat/completions
13+
method: POST
14+
response:
15+
proto: HTTP/2.0
16+
proto_major: 2
17+
proto_minor: 0
18+
content_length: -1
19+
body: "data: {\"id\":\"chatcmpl-CZEIM0llqf375Rns0C5Z4jkatmFvv\",\"object\":\"chat.completion.chunk\",\"created\":1762512466,\"model\":\"gpt-5-2025-08-07\",\"service_tier\":\"default\",\"system_fingerprint\":null,\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"\",\"refusal\":null},\"finish_reason\":null}],\"usage\":null,\"obfuscation\":\"BrPWUDKRvM\"}\n\ndata: {\"id\":\"chatcmpl-CZEIM0llqf375Rns0C5Z4jkatmFvv\",\"object\":\"chat.completion.chunk\",\"created\":1762512466,\"model\":\"gpt-5-2025-08-07\",\"service_tier\":\"default\",\"system_fingerprint\":null,\"choices\":[{\"index\":0,\"delta\":{\"content\":\"4\"},\"finish_reason\":null}],\"usage\":null,\"obfuscation\":\"svsI0HB4ryx\"}\n\ndata: {\"id\":\"chatcmpl-CZEIM0llqf375Rns0C5Z4jkatmFvv\",\"object\":\"chat.completion.chunk\",\"created\":1762512466,\"model\":\"gpt-5-2025-08-07\",\"service_tier\":\"default\",\"system_fingerprint\":null,\"choices\":[{\"index\":0,\"delta\":{},\"finish_reason\":\"stop\"}],\"usage\":null,\"obfuscation\":\"nk6dep\"}\n\ndata: {\"id\":\"chatcmpl-CZEIM0llqf375Rns0C5Z4jkatmFvv\",\"object\":\"chat.completion.chunk\",\"created\":1762512466,\"model\":\"gpt-5-2025-08-07\",\"service_tier\":\"default\",\"system_fingerprint\":null,\"choices\":[],\"usage\":{\"prompt_tokens\":39,\"completion_tokens\":10,\"total_tokens\":49,\"prompt_tokens_details\":{\"cached_tokens\":0,\"audio_tokens\":0},\"completion_tokens_details\":{\"reasoning_tokens\":0,\"audio_tokens\":0,\"accepted_prediction_tokens\":0,\"rejected_prediction_tokens\":0}},\"obfuscation\":\"BAuo50K34JH\"}\n\ndata: [DONE]\n\n"
20+
headers: {}
21+
status: 200 OK
22+
code: 200
23+
duration: 1.868136792s

0 commit comments

Comments
 (0)