Skip to content

Commit 010745b

Browse files
committed
Update versions and react to breaking changes
1 parent 766d03f commit 010745b

File tree

5 files changed

+83
-82
lines changed

5 files changed

+83
-82
lines changed

eng/packages/General.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageVersion Include="Microsoft.CodeAnalysis" Version="$(MicrosoftCodeAnalysisVersion)" />
1212
<PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.0" />
1313
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
14-
<PackageVersion Include="OpenAI" Version="2.1.0" />
14+
<PackageVersion Include="OpenAI" Version="2.2.0-beta.1" />
1515
<PackageVersion Include="Polly" Version="8.4.2" />
1616
<PackageVersion Include="Polly.Core" Version="8.4.2" />
1717
<PackageVersion Include="Polly.Extensions" Version="8.4.2" />

eng/packages/TestOnly.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup>
44
<PackageVersion Include="AutoFixture.AutoMoq" Version="4.17.0" />
5-
<PackageVersion Include="Azure.AI.OpenAI" Version="2.1.0" />
5+
<PackageVersion Include="Azure.AI.OpenAI" Version="2.2.0-beta.1" />
66
<PackageVersion Include="autofixture" Version="4.17.0" />
77
<PackageVersion Include="BenchmarkDotNet" Version="0.13.5" />
88
<PackageVersion Include="FluentAssertions" Version="6.11.0" />

test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIChatClientTests.cs

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ public void GetService_ChatClient_SuccessfullyReturnsUnderlyingClient()
142142
public async Task BasicRequestResponse_NonStreaming()
143143
{
144144
const string Input = """
145-
{"messages":[{"role":"user","content":"hello"}],"model":"gpt-4o-mini","max_completion_tokens":10,"temperature":0.5}
145+
{
146+
"temperature":0.5,
147+
"messages":[{"role":"user","content":"hello"}],
148+
"model":"gpt-4o-mini",
149+
"max_completion_tokens":10
150+
}
146151
""";
147152

148153
const string Output = """
@@ -217,7 +222,14 @@ public async Task BasicRequestResponse_NonStreaming()
217222
public async Task BasicRequestResponse_Streaming()
218223
{
219224
const string Input = """
220-
{"messages":[{"role":"user","content":"hello"}],"model":"gpt-4o-mini","max_completion_tokens":20,"stream":true,"stream_options":{"include_usage":true},"temperature":0.5}
225+
{
226+
"temperature":0.5,
227+
"messages":[{"role":"user","content":"hello"}],
228+
"model":"gpt-4o-mini",
229+
"stream":true,
230+
"stream_options":{"include_usage":true},
231+
"max_completion_tokens":20
232+
}
221233
""";
222234

223235
const string Output = """
@@ -297,15 +309,17 @@ public async Task BasicRequestResponse_Streaming()
297309
public async Task NonStronglyTypedOptions_AllSent()
298310
{
299311
const string Input = """
300-
{"messages":[{"role":"user","content":"hello"}],
301-
"model":"gpt-4o-mini",
302-
"store":true,
303-
"metadata":{"something":"else"},
304-
"logit_bias":{"12":34},
305-
"logprobs":true,
306-
"top_logprobs":42,
307-
"parallel_tool_calls":false,
308-
"user":"12345"}
312+
{
313+
"messages":[{"role":"user","content":"hello"}],
314+
"model":"gpt-4o-mini",
315+
"logprobs":true,
316+
"top_logprobs":42,
317+
"logit_bias":{"12":34},
318+
"parallel_tool_calls":false,
319+
"user":"12345",
320+
"metadata":{"something":"else"},
321+
"store":true
322+
}
309323
""";
310324

311325
const string Output = """
@@ -352,6 +366,9 @@ public async Task MultipleMessages_NonStreaming()
352366
{
353367
const string Input = """
354368
{
369+
"frequency_penalty": 0.75,
370+
"presence_penalty": 0.5,
371+
"temperature": 0.25,
355372
"messages": [
356373
{
357374
"role": "system",
@@ -371,13 +388,8 @@ public async Task MultipleMessages_NonStreaming()
371388
}
372389
],
373390
"model": "gpt-4o-mini",
374-
"frequency_penalty": 0.75,
375-
"presence_penalty": 0.5,
376-
"seed":42,
377-
"stop": [
378-
"great"
379-
],
380-
"temperature": 0.25
391+
"stop": ["great"],
392+
"seed": 42
381393
}
382394
""";
383395

@@ -664,16 +676,8 @@ public async Task FunctionCallContent_NonStreaming()
664676
{
665677
const string Input = """
666678
{
667-
"messages": [
668-
{
669-
"role": "user",
670-
"content": "How old is Alice?"
671-
}
672-
],
673-
"model": "gpt-4o-mini",
674679
"tools": [
675680
{
676-
"type": "function",
677681
"function": {
678682
"description": "Gets the age of the specified person.",
679683
"name": "GetPersonAge",
@@ -689,9 +693,17 @@ public async Task FunctionCallContent_NonStreaming()
689693
}
690694
}
691695
}
692-
}
696+
},
697+
"type": "function"
693698
}
694699
],
700+
"messages": [
701+
{
702+
"role": "user",
703+
"content": "How old is Alice?"
704+
}
705+
],
706+
"model": "gpt-4o-mini",
695707
"tool_choice": "auto"
696708
}
697709
""";
@@ -782,20 +794,8 @@ public async Task FunctionCallContent_Streaming()
782794
{
783795
const string Input = """
784796
{
785-
"messages": [
786-
{
787-
"role": "user",
788-
"content": "How old is Alice?"
789-
}
790-
],
791-
"model": "gpt-4o-mini",
792-
"stream": true,
793-
"stream_options": {
794-
"include_usage": true
795-
},
796797
"tools": [
797798
{
798-
"type": "function",
799799
"function": {
800800
"description": "Gets the age of the specified person.",
801801
"name": "GetPersonAge",
@@ -811,9 +811,21 @@ public async Task FunctionCallContent_Streaming()
811811
}
812812
}
813813
}
814-
}
814+
},
815+
"type": "function"
815816
}
816817
],
818+
"messages": [
819+
{
820+
"role": "user",
821+
"content": "How old is Alice?"
822+
}
823+
],
824+
"model": "gpt-4o-mini",
825+
"stream": true,
826+
"stream_options": {
827+
"include_usage": true
828+
},
817829
"tool_choice": "auto"
818830
}
819831
""";
@@ -908,19 +920,19 @@ public async Task AssistantMessageWithBothToolsAndContent_NonStreaming()
908920
"tool_calls": [
909921
{
910922
"id": "12345",
911-
"type": "function",
912923
"function": {
913924
"name": "SayHello",
914925
"arguments": "null"
915-
}
926+
},
927+
"type": "function"
916928
},
917929
{
918930
"id": "12346",
919-
"type": "function",
920931
"function": {
921932
"name": "SayHi",
922933
"arguments": "null"
923-
}
934+
},
935+
"type": "function"
924936
}
925937
]
926938
},

test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIRealtimeTests.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,13 @@ public async Task HandleToolCallsAsync_RejectsNulls()
7272
{
7373
var conversationSession = (RealtimeConversationSession)default!;
7474

75-
// Null RealtimeConversationSession
76-
await Assert.ThrowsAsync<ArgumentNullException>(() => conversationSession.HandleToolCallsAsync(
77-
new TestConversationUpdate(), []));
75+
// There's currently no way to create a ConversationUpdate instance from outside of the OpenAI
76+
// library, so we can't validate behavior when a valid ConversationUpdate instance is passed in.
7877

7978
// Null ConversationUpdate
8079
using var session = TestRealtimeConversationSession.CreateTestInstance();
8180
await Assert.ThrowsAsync<ArgumentNullException>(() => conversationSession.HandleToolCallsAsync(
8281
null!, []));
83-
84-
// Null tools
85-
await Assert.ThrowsAsync<ArgumentNullException>(() => conversationSession.HandleToolCallsAsync(
86-
new TestConversationUpdate(), null!));
8782
}
8883

8984
[Description("This is a description")]
@@ -110,12 +105,4 @@ public static TestRealtimeConversationSession CreateTestInstance()
110105
new Uri("http://endpoint"), credential);
111106
}
112107
}
113-
114-
private class TestConversationUpdate : ConversationUpdate
115-
{
116-
public TestConversationUpdate()
117-
: base("eventId")
118-
{
119-
}
120-
}
121108
}

test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAISerializationTests.cs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,23 @@ public static async Task SerializeCompletion_SingleChoice()
514514
AssertJsonEqual("""
515515
{
516516
"id": "chatcmpl-ADx3PvAnCwJg0woha4pYsBTi3ZpOI",
517+
"model": "gpt-4o-mini-2024-07-18",
518+
"system_fingerprint": "fp_f85bea6784",
519+
"usage": {
520+
"completion_tokens": 9,
521+
"prompt_tokens": 8,
522+
"total_tokens": 17,
523+
"completion_tokens_details": {
524+
"reasoning_tokens": 90,
525+
"audio_tokens": 2,
526+
"accepted_prediction_tokens": 0,
527+
"rejected_prediction_tokens": 0
528+
},
529+
"prompt_tokens_details": {
530+
"audio_tokens": 1,
531+
"cached_tokens": 13
532+
}
533+
},
517534
"choices": [
518535
{
519536
"finish_reason": "stop",
@@ -540,22 +557,7 @@ public static async Task SerializeCompletion_SingleChoice()
540557
}
541558
],
542559
"created": 1727888631,
543-
"model": "gpt-4o-mini-2024-07-18",
544-
"system_fingerprint": "fp_f85bea6784",
545-
"object": "chat.completion",
546-
"usage": {
547-
"completion_tokens": 9,
548-
"prompt_tokens": 8,
549-
"total_tokens": 17,
550-
"completion_tokens_details": {
551-
"audio_tokens": 2,
552-
"reasoning_tokens": 90
553-
},
554-
"prompt_tokens_details": {
555-
"audio_tokens": 1,
556-
"cached_tokens": 13
557-
}
558-
}
560+
"object": "chat.completion"
559561
}
560562
""", result);
561563
}
@@ -647,15 +649,15 @@ static async IAsyncEnumerable<StreamingChatCompletionUpdate> CreateStreamingComp
647649
string result = Encoding.UTF8.GetString(stream.ToArray());
648650

649651
AssertSseEqual("""
650-
data: {"id":"chatcmpl-ADymNiWWeqCJqHNFXiI1QtRcLuXcl","choices":[{"delta":{"content":"Streaming update 0","tool_calls":[],"role":"assistant"},"logprobs":{"content":[],"refusal":[]},"index":0}],"created":1727888631,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_f85bea6784","object":"chat.completion.chunk"}
652+
data: {"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_f85bea6784","object":"chat.completion.chunk","id":"chatcmpl-ADymNiWWeqCJqHNFXiI1QtRcLuXcl","choices":[{"delta":{"tool_calls":[],"role":"assistant","content":"Streaming update 0"},"logprobs":{"content":[],"refusal":[]},"index":0}],"created":1727888631}
651653
652-
data: {"id":"chatcmpl-ADymNiWWeqCJqHNFXiI1QtRcLuXcl","choices":[{"delta":{"content":"Streaming update 1","tool_calls":[],"role":"assistant"},"logprobs":{"content":[],"refusal":[]},"index":0}],"created":1727888631,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_f85bea6784","object":"chat.completion.chunk"}
654+
data: {"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_f85bea6784","object":"chat.completion.chunk","id":"chatcmpl-ADymNiWWeqCJqHNFXiI1QtRcLuXcl","choices":[{"delta":{"tool_calls":[],"role":"assistant","content":"Streaming update 1"},"logprobs":{"content":[],"refusal":[]},"index":0}],"created":1727888631}
653655
654-
data: {"id":"chatcmpl-ADymNiWWeqCJqHNFXiI1QtRcLuXcl","choices":[{"delta":{"content":"Streaming update 2","tool_calls":[{"index":0,"id":"callId","type":"function","function":{"name":"MyCoolFunc","arguments":"{\r\n \u0022arg1\u0022: 42,\r\n \u0022arg2\u0022: \u0022str\u0022\r\n}"}}],"role":"assistant"},"logprobs":{"content":[],"refusal":[]},"index":0}],"created":1727888631,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_f85bea6784","object":"chat.completion.chunk"}
656+
data: {"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_f85bea6784","object":"chat.completion.chunk","id":"chatcmpl-ADymNiWWeqCJqHNFXiI1QtRcLuXcl","choices":[{"delta":{"tool_calls":[{"index":0,"function":{"name":"MyCoolFunc","arguments":"{\r\n \u0022arg1\u0022: 42,\r\n \u0022arg2\u0022: \u0022str\u0022\r\n}"},"type":"function","id":"callId"}],"role":"assistant","content":"Streaming update 2"},"logprobs":{"content":[],"refusal":[]},"index":0}],"created":1727888631}
655657
656-
data: {"id":"chatcmpl-ADymNiWWeqCJqHNFXiI1QtRcLuXcl","choices":[{"delta":{"content":"Streaming update 3","tool_calls":[],"role":"assistant"},"logprobs":{"content":[],"refusal":[]},"index":0}],"created":1727888631,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_f85bea6784","object":"chat.completion.chunk"}
658+
data: {"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_f85bea6784","object":"chat.completion.chunk","id":"chatcmpl-ADymNiWWeqCJqHNFXiI1QtRcLuXcl","choices":[{"delta":{"tool_calls":[],"role":"assistant","content":"Streaming update 3"},"logprobs":{"content":[],"refusal":[]},"index":0}],"created":1727888631}
657659
658-
data: {"id":"chatcmpl-ADymNiWWeqCJqHNFXiI1QtRcLuXcl","choices":[{"delta":{"content":"Streaming update 4","tool_calls":[],"role":"assistant"},"logprobs":{"content":[],"refusal":[]},"finish_reason":"stop","index":0}],"created":1727888631,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_f85bea6784","object":"chat.completion.chunk","usage":{"completion_tokens":9,"prompt_tokens":8,"total_tokens":17,"completion_tokens_details":{"audio_tokens":2,"reasoning_tokens":90},"prompt_tokens_details":{"audio_tokens":1,"cached_tokens":13}}}
660+
data: {"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_f85bea6784","object":"chat.completion.chunk","id":"chatcmpl-ADymNiWWeqCJqHNFXiI1QtRcLuXcl","choices":[{"delta":{"tool_calls":[],"role":"assistant","content":"Streaming update 4"},"logprobs":{"content":[],"refusal":[]},"finish_reason":"stop","index":0}],"created":1727888631,"usage":{"completion_tokens":9,"prompt_tokens":8,"total_tokens":17,"completion_tokens_details":{"reasoning_tokens":90,"audio_tokens":2,"accepted_prediction_tokens":0,"rejected_prediction_tokens":0},"prompt_tokens_details":{"audio_tokens":1,"cached_tokens":13}}}
659661
660662
data: [DONE]
661663

0 commit comments

Comments
 (0)