gemini_bridge 0.1.10

Types and functions to interact with Gemini AI API
Documentation

Gemini Bridge

Gemini Bridge is a Rust crate designed to interact with the Gemini API. This crate aims to provide a seamless and efficient way to communicate with Gemini API.

Features

  • Easy-to-use interface for interacting with the Gemini API
  • Asynchronous support for non-blocking operations
  • Comprehensive error handling

Installation

Add gemini_bridge to your Cargo.toml:

[dependencies]
gemini_bridge = "0.1.4"
# example version

Usage

Text Generation

extern crate gemini_rs;

async fn main() {
    let gen = GeminiRs::new_text_generator("api_key_xxxxxxx", "gemini-1.5-flash-latest".to_owned());
    let res = gen
        .generate_content(RequestBody {
            contents: vec![Content {
                parts: vec![Part {
                    text: "send me a test response".to_owned(),
                }],
            }],
            safety_settings: None,
            generation_config: None,
        })
        .await;
}

Streaming

You can also use the generate_content_stream method to generate a conversation between the user and the model. The role field in the Content struct is used to determine the speaker of the text. The role field can be set to user or model.

let res = gen
    .generate_content_stream(RequestBody {
        contents: vec![
            Content {
                role: Some(String::from("user")),
                parts: vec![Part {
                    text: "Hello".to_owned(),
                }],
            },
            Content {
                role: Some(String::from("model")),
                parts: vec![Part {
                    text: "Great to meet you. What would you like to know?".to_owned(),
                }],
            },
            Content {
                role: Some(String::from("user")),
                parts: vec![Part {
                    text: "I have two dogs in my house. How many paws are in my house?"
                        .to_owned(),
                }],
            },
            Content {
                role: Some(String::from("model")),
                parts: vec![Part {
                    text: "That's a fun question!  You have a total of **8 paws** in your house. 🐶🐾 \n"
                        .to_owned(),
                }],
            },
            Content {
                role: Some(String::from("user")),
                parts: vec![Part {
                    text: "Thank you! How did you calculate that? Are you sure?"
                        .to_owned(),
                }],
            },                
        ],
        safety_settings: None,
        generation_config: None,
    })
    .await;

Not tested yet with other models.

TODO

  • Implement Content Generation Method
  • Implement Conversation
  • Implement Embeddings
  • Add examples and documentation
  • Write tests