jeremychone / rust-genai

Rust multiprovider generative AI client (Ollama, OpenAi, Anthropic, Groq, Gemini, Cohere, ...)
Apache License 2.0
164 stars 35 forks source link

printer Error type #21

Closed liamwh closed 1 week ago

liamwh commented 1 week ago

I'm on mobile so please forgive the lack of formatting or examples, however I was getting issues with the error type from print_chat_stream being Box<dyn std::Error. Due to the fact that Box is used, the size of the error can not be known at compile time, meaning that the result of print_chat_stream is no longer Send + Sync, limiting its usage considerably. For example, I'd like to be able to use anyhow's Context trait on the result of print_chat_stream and propoagate it up the call stack using anyhow's Result type, but I believe that requires the error to be Send + Senc, though as I said I'm on mobile and not 100% certain there.

I'm not sure of the best practice solution here but I do know that most libraries use thiserror to which resolves this problem.

Would you please remove the Box from the error returned from print_chat_stream and perhaps anywhere else Box is used for errors?

jeremychone commented 1 week ago

@liamwh Ho yes, good one. I am going to fix that. It should not be Box<dyn..., it was a left over from before.

Good timing, I was going to do the 0.1.8 release.

Doing the commit now.

jeremychone commented 1 week ago

@liamwh Just pushed it. I am going to do the release today or tomorrow.

liamwh commented 1 week ago

Super fast, awesome stuff, thanks very much 🙏! I dropped another issue here btw that might be good for the next release also?

jeremychone commented 1 week ago

@liamwh release made.