⚡️ abort ollama request on cancel

This commit is contained in:
Nate Sesti 2024-02-07 22:52:15 -08:00
parent 6db74a8b27
commit c12ffde939
2 changed files with 11 additions and 6 deletions

View file

@ -183,12 +183,16 @@ class Ollama extends BaseLLM {
stream: true,
});
for await (const chunk of response) {
if (!chunk?.message?.content) continue;
yield {
role: "assistant",
content: chunk.message.content,
};
try {
for await (const chunk of response) {
if (!chunk?.message?.content) continue;
yield {
role: "assistant",
content: chunk.message.content,
};
}
} finally {
client.abort();
}
}

1
gui/package-lock.json generated
View file

@ -84,6 +84,7 @@
"llm-code-highlighter": "^0.0.3",
"node-fetch": "^3.3.2",
"node-html-markdown": "^1.3.0",
"ollama": "^0.4.6",
"openai": "^4.20.1",
"replicate": "^0.23.0",
"socket.io-client": "^4.7.3",