L nsarrazin HF Staff commited on
Commit
1f8ab3d
·
unverified ·
1 Parent(s): 4c2254d

fix(openai): do not throw "Generation failed" when finish_reason="length" (#1429)

Browse files
src/lib/server/endpoints/openai/openAIChatToTextGenerationStream.ts CHANGED
@@ -13,7 +13,7 @@ export async function* openAIChatToTextGenerationStream(
13
  for await (const completion of completionStream) {
14
  const { choices } = completion;
15
  const content = choices[0]?.delta?.content ?? "";
16
- const last = choices[0]?.finish_reason === "stop";
17
  if (content) {
18
  generatedText = generatedText + content;
19
  }
 
13
  for await (const completion of completionStream) {
14
  const { choices } = completion;
15
  const content = choices[0]?.delta?.content ?? "";
16
+ const last = choices[0]?.finish_reason === "stop" || choices[0]?.finish_reason === "length";
17
  if (content) {
18
  generatedText = generatedText + content;
19
  }
src/lib/server/endpoints/openai/openAICompletionToTextGenerationStream.ts CHANGED
@@ -13,7 +13,7 @@ export async function* openAICompletionToTextGenerationStream(
13
  for await (const completion of completionStream) {
14
  const { choices } = completion;
15
  const text = choices[0]?.text ?? "";
16
- const last = choices[0]?.finish_reason === "stop";
17
  if (text) {
18
  generatedText = generatedText + text;
19
  }
 
13
  for await (const completion of completionStream) {
14
  const { choices } = completion;
15
  const text = choices[0]?.text ?? "";
16
+ const last = choices[0]?.finish_reason === "stop" || choices[0]?.finish_reason === "length";
17
  if (text) {
18
  generatedText = generatedText + text;
19
  }