avastmick / google-generative-ai-rs

An unofficial rust-based client library to interact with the Google Gemini generative AI API
https://docs.rs/google-generative-ai-rs/
MIT License
21 stars 7 forks source link

Support for v1beta features 1.5 model and system instructions. #33

Closed cpttripzz closed 4 months ago

cpttripzz commented 4 months ago

Support for v1beta features 1.5 model and system instructions.

avastmick commented 4 months ago

Thanks for the contribution. I'm pretty snowed under at work right now so will hopefully have a look t this at the weekend.

Question @cpttripzz why did you make the api v1beta? This was the original Gemini API but it then moved to v1.0. I'll test it but good to get your view.

Thanks again

cpttripzz commented 4 months ago

Thanks for the contribution. I'm pretty snowed under at work right now so will hopefully have a look t this at the weekend.

Question @cpttripzz why did you make the api v1beta? This was the original Gemini API but it then moved to v1.0. I'll test it but good to get your view.

Thanks again

Hey there. I have used v1beta because that is the only endpoint that supports gemini 1.5 and system instructions for now. Thanks alot for this great library, let me know if I can help with anything

avastmick commented 4 months ago

Hi @cpttripzz.

Once again, thanks for the PR and apologies for the delay in getting back to you.

Unfortunately, I must ask that more work be done before this PR can be accepted.

Creating a whole new tree in the code (v1beta) makes the code highly repetitious, and the user's compile size is almost doubled. The code duplication will make the library harder to maintain, and the compile size may limit usage where binary size is a concern.

I recommend merging your new code into the v1 code and using feature flags to turn on/off whether the new features will be used.

Have a look at the "Cargo Book" on the topic Features. Then, if the library user wants to use the new features, they can enable the functionality in their cargo.toml; if they don't, the functionality is not included.

Usage would be simple for the user, something like:

google-generative-ai-rs = { version = "0.3.0" features = ["beta"] }

In the code, the `beta' features would enabled using (something like):

[cfg(feature = “beta”)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct SystemInstructionContent {
    #[serde(default)]
    pub parts: Vec<SystemInstructionPart>,
}
...
        [cfg(feature = “beta”)]
        #[serde(skip_serializing_if = "Option::is_none")]
        #[serde(default, rename = "system_instruction")]
        pub system_instruction: Option<SystemInstructionContent>,

Don't forget to set rust-analyzer.cargo.features to see errors, etc.

Regardless, this may lead to breaking changes, so please bump the crate version to 0.3.0.

Thanks again.

avastmick commented 4 months ago

Hi @cpttripzz, I have some time this weekend and I need to update my client to have JSON mode. So I can take this on, as per my comments above.

Thanks again for the previous effort. 👍

avastmick commented 4 months ago

I am closing this as #35 supersedes. Thanks.