Skip to content

Commit

Permalink
Azure OpenAI: address custom deserialization issue for Choice.FinishR…
Browse files Browse the repository at this point in the history
…eason (#33833)

* Address OpenAI Choice.FinishReason deserialization issue

* Re-record; clean up test
  • Loading branch information
trrwilson committed Feb 8, 2023
1 parent 5509df5 commit 5cfd4af
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal static Choice DeserializeChoice(JsonElement element)
continue;
}
}
if (property.NameEquals("finishReason"))
if (property.NameEquals("finish_reason"))
{
finishReason = property.Value.GetString();
continue;
Expand Down
24 changes: 18 additions & 6 deletions sdk/openai/Azure.AI.OpenAI/tests/OpenAIInferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,25 @@ public void InstanceTest()
[RecordedTest]
public async Task CompletionTest()
{
var client = GetClient();
CompletionsOptions completionsRequest = new CompletionsOptions();
completionsRequest.Prompt.Add("Hello world");
completionsRequest.Prompt.Add("running over the same old ground");
Assert.That(completionsRequest, Is.InstanceOf<CompletionsOptions>());
var response = await client.GetCompletionsAsync(CompletionsDeploymentId, completionsRequest);
OpenAIClient client = GetClient();
CompletionsOptions requestOptions = new CompletionsOptions()
{
Prompt =
{
"Hello world",
"running over the same old ground",
},
};
Assert.That(requestOptions, Is.InstanceOf<CompletionsOptions>());
Response<Completions> response = await client.GetCompletionsAsync(
CompletionsDeploymentId,
requestOptions);
Assert.That(response, Is.Not.Null);
Assert.That(response, Is.InstanceOf<Response<Completions>>());
Assert.That(response.Value, Is.Not.Null);
Assert.That(response.Value.Choices, Is.Not.Null.Or.Empty);
Assert.That(response.Value.Choices.Count, Is.EqualTo(requestOptions.Prompt.Count));
Assert.That(response.Value.Choices[0].FinishReason, Is.Not.Null.Or.Empty);
}

/// <summary>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5cfd4af

Please sign in to comment.