mirror of
https://github.com/voideditor/void
synced 2026-05-23 17:38:23 +00:00
_aborter set
This commit is contained in:
parent
af85949561
commit
9abc3ad3dc
1 changed files with 16 additions and 2 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue