mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-15 02:50:10 +01:00
Merge branch 'master' of github.com:Mintplex-Labs/anything-llm
This commit is contained in:
commit
8cfe855bc8
@ -254,35 +254,48 @@ class OpenRouterLLM {
|
|||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
for await (const chunk of stream) {
|
try {
|
||||||
const message = chunk?.choices?.[0];
|
for await (const chunk of stream) {
|
||||||
const token = message?.delta?.content;
|
const message = chunk?.choices?.[0];
|
||||||
lastChunkTime = Number(new Date());
|
const token = message?.delta?.content;
|
||||||
|
lastChunkTime = Number(new Date());
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
fullText += token;
|
fullText += token;
|
||||||
writeResponseChunk(response, {
|
writeResponseChunk(response, {
|
||||||
uuid,
|
uuid,
|
||||||
sources: [],
|
sources: [],
|
||||||
type: "textResponseChunk",
|
type: "textResponseChunk",
|
||||||
textResponse: token,
|
textResponse: token,
|
||||||
close: false,
|
close: false,
|
||||||
error: false,
|
error: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.finish_reason !== null) {
|
if (message.finish_reason !== null) {
|
||||||
writeResponseChunk(response, {
|
writeResponseChunk(response, {
|
||||||
uuid,
|
uuid,
|
||||||
sources,
|
sources,
|
||||||
type: "textResponseChunk",
|
type: "textResponseChunk",
|
||||||
textResponse: "",
|
textResponse: "",
|
||||||
close: true,
|
close: true,
|
||||||
error: false,
|
error: false,
|
||||||
});
|
});
|
||||||
response.removeListener("close", handleAbort);
|
response.removeListener("close", handleAbort);
|
||||||
resolve(fullText);
|
resolve(fullText);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
writeResponseChunk(response, {
|
||||||
|
uuid,
|
||||||
|
sources,
|
||||||
|
type: "abort",
|
||||||
|
textResponse: null,
|
||||||
|
close: true,
|
||||||
|
error: e.message,
|
||||||
|
});
|
||||||
|
response.removeListener("close", handleAbort);
|
||||||
|
resolve(fullText);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user