ollama-js icon indicating copy to clipboard operation
ollama-js copied to clipboard

AbortableAsyncIterator have proprieties undefined when doing stream.abort()

Open ZaMeR12 opened this issue 1 year ago • 4 comments

In brief, i want to stop the request the user just made while ollama is responding to them. The problem is that i followed the example given by this lib but my console tell that the property abort is undefined. And my code editor them something similar. So i guess i have to create a new variable from the constructor of AbortableAsyncIterator when i declare the stream variable, but i don't know how to do that. Can someone help me? I use typescript and React.

There is a screenshot that the web console show me when i try to stream.abort() like the example show:

image

ZaMeR12 avatar Oct 09 '24 18:10 ZaMeR12

Could you show your code?

hopperelec avatar Oct 10 '24 00:10 hopperelec

Just experienced this same issue. The stream doesn't get created until Ollama starts responding to the request (which could be a while if you're loading a large model), so you will get this error if you try to abort before that. Just add an if (stream) check before trying to abort it. I'll modify the example to demonstrate this!

hopperelec avatar Oct 18 '24 13:10 hopperelec

Nevermind, there's already a PR to fix this! https://github.com/ollama/ollama-js/pull/146

hopperelec avatar Oct 18 '24 13:10 hopperelec

Just experienced this same issue. The stream doesn't get created until Ollama starts responding to the request (which could be a while if you're loading a large model), so you will get this error if you try to abort before that. Just add an if (stream) check before trying to abort it. I'll modify the example to demonstrate this!

This is probably the easiest fix for the time being while we figure something out for long term :)

ParthSareen avatar Nov 05 '24 23:11 ParthSareen