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

Different interfaces for an un-streamed "streamable" response, a streamed response and the final (done) response from a stream

Open hopperelec opened this issue 1 month ago • 0 comments

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 when done is truthy. This would still allow for if (done), since objects are considered truthy and undefined 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

hopperelec avatar May 25 '24 10:05 hopperelec