Skip to content

Commit 4837c8f

Browse files
authored
Merge pull request #1321 from Portkey-AI/fix/together-ai-undefined-choice
fix: handle undefined choice in together ai finish reason transform
2 parents e25810b + 5596876 commit 4837c8f

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/handlers/streamHandler.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,16 @@ export function handleStreamingMode(
321321
await writer.write(encoder.encode(chunk));
322322
}
323323
} catch (error) {
324-
console.error('Error during stream processing:', error);
324+
console.error('Error during stream processing:', proxyProvider, error);
325325
} finally {
326326
try {
327327
await writer.close();
328328
} catch (closeError) {
329-
console.error('Failed to close the writer:', closeError);
329+
console.error(
330+
'Failed to close the writer:',
331+
proxyProvider,
332+
closeError
333+
);
330334
}
331335
}
332336
})();
@@ -345,12 +349,16 @@ export function handleStreamingMode(
345349
await writer.write(encoder.encode(chunk));
346350
}
347351
} catch (error) {
348-
console.error('Error during stream processing:', error);
352+
console.error('Error during stream processing:', proxyProvider, error);
349353
} finally {
350354
try {
351355
await writer.close();
352356
} catch (closeError) {
353-
console.error('Failed to close the writer:', closeError);
357+
console.error(
358+
'Failed to close the writer:',
359+
proxyProvider,
360+
closeError
361+
);
354362
}
355363
}
356364
})();

src/providers/together-ai/chatComplete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export const TogetherAIChatCompleteStreamChunkTransform: (
230230
return `data: ${chunk}\n\n`;
231231
}
232232
const parsedChunk: TogetherAIChatCompletionStreamChunk = JSON.parse(chunk);
233-
const finishReason = parsedChunk.choices[0].finish_reason
233+
const finishReason = parsedChunk.choices[0]?.finish_reason
234234
? transformFinishReason(
235235
parsedChunk.choices[0].finish_reason,
236236
strictOpenAiCompliance

0 commit comments

Comments
 (0)