Skip to content

Commit 5cfd4af

Browse files
authored
Azure OpenAI: address custom deserialization issue for Choice.FinishReason (Azure#33833)
* Address OpenAI Choice.FinishReason deserialization issue * Re-record; clean up test
1 parent 5509df5 commit 5cfd4af

File tree

4 files changed

+52
-40
lines changed

4 files changed

+52
-40
lines changed

sdk/openai/Azure.AI.OpenAI/src/Custom/Choice.Serialization.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ internal static Choice DeserializeChoice(JsonElement element)
4949
continue;
5050
}
5151
}
52-
if (property.NameEquals("finishReason"))
52+
if (property.NameEquals("finish_reason"))
5353
{
5454
finishReason = property.Value.GetString();
5555
continue;

sdk/openai/Azure.AI.OpenAI/tests/OpenAIInferenceTests.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,25 @@ public void InstanceTest()
3232
[RecordedTest]
3333
public async Task CompletionTest()
3434
{
35-
var client = GetClient();
36-
CompletionsOptions completionsRequest = new CompletionsOptions();
37-
completionsRequest.Prompt.Add("Hello world");
38-
completionsRequest.Prompt.Add("running over the same old ground");
39-
Assert.That(completionsRequest, Is.InstanceOf<CompletionsOptions>());
40-
var response = await client.GetCompletionsAsync(CompletionsDeploymentId, completionsRequest);
35+
OpenAIClient client = GetClient();
36+
CompletionsOptions requestOptions = new CompletionsOptions()
37+
{
38+
Prompt =
39+
{
40+
"Hello world",
41+
"running over the same old ground",
42+
},
43+
};
44+
Assert.That(requestOptions, Is.InstanceOf<CompletionsOptions>());
45+
Response<Completions> response = await client.GetCompletionsAsync(
46+
CompletionsDeploymentId,
47+
requestOptions);
48+
Assert.That(response, Is.Not.Null);
4149
Assert.That(response, Is.InstanceOf<Response<Completions>>());
50+
Assert.That(response.Value, Is.Not.Null);
51+
Assert.That(response.Value.Choices, Is.Not.Null.Or.Empty);
52+
Assert.That(response.Value.Choices.Count, Is.EqualTo(requestOptions.Prompt.Count));
53+
Assert.That(response.Value.Choices[0].FinishReason, Is.Not.Null.Or.Empty);
4254
}
4355

4456
/// <summary>

sdk/openai/Azure.AI.OpenAI/tests/SessionRecords/OpenAIInferenceTests/CompletionTest.json

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/openai/Azure.AI.OpenAI/tests/SessionRecords/OpenAIInferenceTests/CompletionTestAsync.json

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)