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;