From 9abc3ad3dcfdd9867f2b4df7bb1c3bdc63df20ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Commaret?= Date: Fri, 10 Jan 2025 23:46:58 +0100 Subject: [PATCH] _aborter set --- .../void/electron-main/llmMessage/mistral.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/vs/platform/void/electron-main/llmMessage/mistral.ts b/src/vs/platform/void/electron-main/llmMessage/mistral.ts index 9a32e2b3..6d59b6a2 100644 --- a/src/vs/platform/void/electron-main/llmMessage/mistral.ts +++ b/src/vs/platform/void/electron-main/llmMessage/mistral.ts @@ -32,6 +32,7 @@ interface MistralChunk { // Mistral export const sendMistralMsg: _InternalSendLLMMessageFnType = async ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter }) => { let fullText = ''; + let aborted = false; const thisConfig = settingsOfProvider.mistral; @@ -44,6 +45,11 @@ export const sendMistralMsg: _InternalSendLLMMessageFnType = async ({ messages, apiKey: thisConfig.apiKey }); + // Définir l'aborter avant de commencer le streaming + _setAborter(() => { + aborted = true; + }); + try { // Check if there are messages to process if (!messages || messages.length === 0) { @@ -80,9 +86,12 @@ export const sendMistralMsg: _InternalSendLLMMessageFnType = async ({ messages, maxTokens: 2048 }); - _setAborter(() => { }); // Mistral does not provide an abort method - for await (const chunk of stream) { + // Vérifier si la requête a été abandonnée + if (aborted) { + return; + } + if (typeof chunk === 'object' && chunk && 'data' in chunk) { const { data } = chunk as MistralChunk; if (data.choices?.[0]?.delta?.content) { @@ -93,6 +102,11 @@ export const sendMistralMsg: _InternalSendLLMMessageFnType = async ({ messages, } } + // Vérifier une dernière fois si la requête a été abandonnée + if (aborted) { + return; + } + if (!fullText) { onError({ message: 'No response received from Mistral.', fullError: new Error('No response content') }); return;