From 7ba34368b9194ba78c7f942da18c1de2a0706c36 Mon Sep 17 00:00:00 2001 From: Jorge de los Santos Date: Thu, 16 May 2024 12:22:03 +0000 Subject: [PATCH] Fix error with undefined choices in new conversations -Added safe navigation to an object that might be undefined on an empty conversation. -Fixes #201 --- packages/search/src/lib/approaches/chat-read-retrieve-read.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/search/src/lib/approaches/chat-read-retrieve-read.ts b/packages/search/src/lib/approaches/chat-read-retrieve-read.ts index a8e395d2..ca694338 100644 --- a/packages/search/src/lib/approaches/chat-read-retrieve-read.ts +++ b/packages/search/src/lib/approaches/chat-read-retrieve-read.ts @@ -107,14 +107,14 @@ export class ChatReadRetrieveRead extends ApproachBase implements ChatApproach { { index: 0, delta: { - content: chunk.choices[0].delta.content ?? '', + content: chunk.choices[0]?.delta.content ?? '', role: 'assistant' as const, context: { data_points: id === 0 ? { text: dataPoints } : undefined, thoughts: id === 0 ? thoughts : undefined, }, }, - finish_reason: chunk.choices[0].finish_reason, + finish_reason: chunk.choices[0]?.finish_reason, }, ], object: 'chat.completion.chunk' as const,