From 5b3a6d240eba16bc211178212f2f241124f16190 Mon Sep 17 00:00:00 2001 From: Piyu-Pika Date: Wed, 6 Nov 2024 22:04:46 +0530 Subject: [PATCH] minor bug fix --- extensions/void/src/common/sendLLMMessage.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/extensions/void/src/common/sendLLMMessage.ts b/extensions/void/src/common/sendLLMMessage.ts index b7c8004d..361e8011 100644 --- a/extensions/void/src/common/sendLLMMessage.ts +++ b/extensions/void/src/common/sendLLMMessage.ts @@ -355,7 +355,7 @@ const sendGroqMsg: SendLLMMessageFnTypeInternal = async ({ messages, onText, onF }); try { - const completion = await groq.chat.completions.create({ + const stream = await groq.chat.completions.create({ messages: messages, model: voidConfig.groq.model, stream: true, @@ -363,8 +363,10 @@ const sendGroqMsg: SendLLMMessageFnTypeInternal = async ({ messages, onText, onF max_tokens: parseMaxTokensStr(voidConfig.default.maxTokens), }); - for await (const chunk of completion) { - if (didAbort) return; + for await (const chunk of stream) { + if (didAbort) { + break; + } const newText = chunk.choices[0]?.delta?.content || ''; if (newText) { @@ -373,9 +375,10 @@ const sendGroqMsg: SendLLMMessageFnTypeInternal = async ({ messages, onText, onF } } - onFinalMessage(fullText); + if (!didAbort) { + onFinalMessage(fullText); + } } catch (error: any) { - console.error('Groq error:', error); if (error?.status === 401) { onError('Invalid API key.'); } else {