Skip to content

Commit

Permalink
fix(openai): do not throw "Generation failed" when finish_reason="len…
Browse files Browse the repository at this point in the history
…gth" (#1429)

Co-authored-by: Nathan Sarrazin <[email protected]>
  • Loading branch information
llllvvuu and nsarrazin authored Aug 25, 2024
1 parent f7fd25b commit 403e040
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function* openAIChatToTextGenerationStream(
for await (const completion of completionStream) {
const { choices } = completion;
const content = choices[0]?.delta?.content ?? "";
const last = choices[0]?.finish_reason === "stop";
const last = choices[0]?.finish_reason === "stop" || choices[0]?.finish_reason === "length";
if (content) {
generatedText = generatedText + content;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function* openAICompletionToTextGenerationStream(
for await (const completion of completionStream) {
const { choices } = completion;
const text = choices[0]?.text ?? "";
const last = choices[0]?.finish_reason === "stop";
const last = choices[0]?.finish_reason === "stop" || choices[0]?.finish_reason === "length";
if (text) {
generatedText = generatedText + text;
}
Expand Down

0 comments on commit 403e040

Please sign in to comment.