mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58: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
|
// Mistral
|
||||||
export const sendMistralMsg: _InternalSendLLMMessageFnType = async ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter }) => {
|
export const sendMistralMsg: _InternalSendLLMMessageFnType = async ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter }) => {
|
||||||
let fullText = '';
|
let fullText = '';
|
||||||
|
let aborted = false;
|
||||||
|
|
||||||
const thisConfig = settingsOfProvider.mistral;
|
const thisConfig = settingsOfProvider.mistral;
|
||||||
|
|
||||||
|
|
@ -44,6 +45,11 @@ export const sendMistralMsg: _InternalSendLLMMessageFnType = async ({ messages,
|
||||||
apiKey: thisConfig.apiKey
|
apiKey: thisConfig.apiKey
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Définir l'aborter avant de commencer le streaming
|
||||||
|
_setAborter(() => {
|
||||||
|
aborted = true;
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Check if there are messages to process
|
// Check if there are messages to process
|
||||||
if (!messages || messages.length === 0) {
|
if (!messages || messages.length === 0) {
|
||||||
|
|
@ -80,9 +86,12 @@ export const sendMistralMsg: _InternalSendLLMMessageFnType = async ({ messages,
|
||||||
maxTokens: 2048
|
maxTokens: 2048
|
||||||
});
|
});
|
||||||
|
|
||||||
_setAborter(() => { }); // Mistral does not provide an abort method
|
|
||||||
|
|
||||||
for await (const chunk of stream) {
|
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) {
|
if (typeof chunk === 'object' && chunk && 'data' in chunk) {
|
||||||
const { data } = chunk as MistralChunk;
|
const { data } = chunk as MistralChunk;
|
||||||
if (data.choices?.[0]?.delta?.content) {
|
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) {
|
if (!fullText) {
|
||||||
onError({ message: 'No response received from Mistral.', fullError: new Error('No response content') });
|
onError({ message: 'No response received from Mistral.', fullError: new Error('No response content') });
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue