From f12bbf47c80c51c61001ea450cd2e68c493e30c0 Mon Sep 17 00:00:00 2001 From: HugoCasa Date: Thu, 3 Apr 2025 16:32:11 +0200 Subject: [PATCH] fix: prevent invalid returned ai completion object errors (#5564) --- frontend/src/lib/components/copilot/lib.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/components/copilot/lib.ts b/frontend/src/lib/components/copilot/lib.ts index 9aa8c80d29..5e7f263dca 100644 --- a/frontend/src/lib/components/copilot/lib.ts +++ b/frontend/src/lib/components/copilot/lib.ts @@ -443,7 +443,7 @@ export async function getNonStreamingCompletion( }) : workspaceAIClients.getOpenaiClient() const completion = await openaiClient.chat.completions.create(config, fetchOptions) - response = completion.choices[0]?.message.content || '' + response = completion.choices?.[0]?.message.content || '' return response } @@ -464,7 +464,7 @@ export async function getCompletion( } export function getResponseFromEvent(part: OpenAI.Chat.Completions.ChatCompletionChunk): string { - return part.choices[0]?.delta?.content || '' + return part.choices?.[0]?.delta?.content || '' } export async function copilot(