Fix crash when delta in openai api handling could be empty in some cases.

Fixes #641
This commit is contained in:
Piotr Rogowski
2025-01-29 19:41:00 +01:00
parent 449b9ef610
commit 60cb550db7

View File

@@ -62,13 +62,15 @@ export class OpenAiHandler implements ApiHandler, SingleCompletionHandler {
const stream = await this.client.chat.completions.create(requestOptions)
for await (const chunk of stream) {
const delta = chunk.choices[0]?.delta
if (delta?.content) {
const delta = chunk.choices[0]?.delta ?? {}
if (delta.content) {
yield {
type: "text",
text: delta.content,
}
}
if ("reasoning_content" in delta && delta.reasoning_content) {
yield {
type: "reasoning",