From 582a0114c97e9f5e640d42288fb48eccb50e4bd1 Mon Sep 17 00:00:00 2001 From: Jorge de los Santos Date: Thu, 16 May 2024 11:50:51 -0300 Subject: [PATCH] fix: error with undefined choices in new conversations (closes #202) -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,