ollama-js
ollama-js copied to clipboard
Different interfaces for an un-streamed "streamable" response, a streamed response and the final (done) response from a stream
While using ollama-js, I've found myself referring to the Ollama API docs to see exactly when certain fields are provided in the response, but I believe ollama-js should be aiming to abstract away the API. Currently, the types for optional fields aren't actually optional. While documentation on the response interfaces would help with this, I think it would be even better if they were treated as different types of responses altogether.
There's three ways I think the final response could be handled
- Alongside https://github.com/ollama/ollama-js/issues/95, these responses could be taken using different parts of that class
-
done
could be an object instead of a boolean, where the object contains all the fields which are only accessible whendone
is truthy. This would still allow forif (done)
, since objects are considered truthy andundefined
is not. This would require restructuring the response received from the API, though. - Using a type along the lines of
partField & ({ done: false} | { done: true, ... )
. This would not require any changes outside of the interface