Skip to content

Commit

Permalink
Fix finish_reason for chat model for non-streaming case. (#7)
Browse files Browse the repository at this point in the history
@asklar - I just copy/pasted the fix from

d41216a
but haven't tested it - hopefully you have an easy way to do that.
  • Loading branch information
davidmatson committed Apr 13, 2023
1 parent d41216a commit 46fb78d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion OpenAI.WinRT.nuspec
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>OpenAI.WinRT</id>
<version>0.0.12</version>
<version>0.0.13</version>
<title>OpenAI.WinRT</title>
<authors>Alexander Sklar</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand Down
19 changes: 12 additions & 7 deletions OpenAIClient.cpp
Expand Up @@ -477,13 +477,18 @@ namespace winrt::OpenAI::implementation
auto msg = choice.GetNamedObject(L"message");
retChoiceImpl->m_text = msg.GetNamedString(L"content");
}
auto finish_reason = choice.GetNamedString(L"finish_reason");
if (finish_reason == L"stop") {
retChoiceImpl->m_finishReason = FinishReason::Stop;
} else if (finish_reason == L"length") {
retChoiceImpl->m_finishReason = FinishReason::Length;
} else {
throw winrt::hresult_invalid_argument{};
if (choice.HasKey(L"finish_reason")) {
auto fr = choice.GetNamedValue(L"finish_reason");
auto finish_reason = fr.ValueType() == JsonValueType::String ? fr.GetString() : L"stop";
if (finish_reason == L"stop") {
retChoiceImpl->m_finishReason = FinishReason::Stop;
}
else if (finish_reason == L"length") {
retChoiceImpl->m_finishReason = FinishReason::Length;
}
else {
throw winrt::hresult_invalid_argument{};
}
}
retChoices.push_back(retChoice);
}
Expand Down

0 comments on commit 46fb78d

Please sign in to comment.