Expand description
ยง๐ Gems
๐ง Linux (Recommended) | ๐ช Windows |
---|---|
Download Executable File | Download .exe File |
cargo install gems --all-features | cargo install gems --all-features |
๐ GEMS: A cli, tui, and sdk for interacting with the Gemini API, allowing you to generate creative content, perform text-related tasks, and get information about supported models.
ยง๐ Table of Contents
ยง๐ Installation
To install the gems
cli, use the following Cargo command:
cargo install --locked gems --all-features
ยงโจ Features
- Interact with the Gemini API from the terminal.
- Generate creative content with ease.
- Stream generation of content for continuous output.
- Count the number of tokens in a text.
- Generate images.
- Embed content into a specified model.
- Batch embed multiple contents efficiently.
- Get information about the current model and list available models.
ยงUsage
Before using the gems
CLI, make sure to set the following environment variables:
export GEMINI_API_KEY=<your_gemini_api_key>
export GEMINI_MODEL=<your_gemini_model>
Generate an api key from Google AI Studio.
ยงโจ Usage as CLI
ยงGenerate creative content:
gems generate -t "Hello"
ยงAnalyze an image and generate content from text:
curl -o image.jpg https://storage.googleapis.com/generativeai-downloads/images/scones.jpg
gems vision -i image.jpg
gems vision -i image.jpg -t "What's in the image?"
ยงStream generation of content:
gems stream -t "Generate a short fictional story"
ยงCount the number of tokens in a text:
gems count -t "Hello There!"
ยงEmbed content into a specified model:
gems embed -t "Write a story about a magic backpack."
ยงBatch embed multiple contents:
gems batch -t "Write a story about a magic backpack.","Generate a poem about nature."
ยงGet information about the current model:
gems info
ยงList available models:
gems list
ยงGenerate an Image
gems imagen -t "Hi, can you create a 3d rendered image of a pig with wings and a top hat flying over a happy futuristic scifi city with lots of greenery?"
ยงTUI mode
gems
ยง๐จ Options
Option | Description |
---|---|
`` | TUI mode. |
--api-key | Specify the API key for accessing the Gemini API. |
--model | Specify the model to use for generating content. |
ยง๐ Subcommands
Subcommand | Description |
---|---|
generate | Generate creative content. |
vision | Analyze an image and generate content from text. |
stream | Stream the generation of content. |
imagen | Generate an image. |
count | Count the number of tokens in a text. |
embed | Embed content into a specified model. |
batch | Batch embed multiple contents. |
info | Get information about the current model. |
list | List available models. |
ยงโจ Usage as Dependency
-
Add the
gems
crate:[dependencies] gems = "0.1.3"
-
Use the
Client
struct to interact with the Gemini API:use gems::Client; use gems::traits::CTrait; use gems::messages::Content; use gems::messages::Message; use gems::models::Model; use gems::chat::ChatBuilder; use anyhow::Result; #[tokio::main] async fn main() -> Result<()> { let mut gemini_client = Client::builder().model("your-model").build()?; gemini_client.set_api_key("your-api-key".to_string()); let parameters = ChatBuilder::default() .model(Model::Flash20) .messages(vec![Message::User { content: Content::Text("Hello".to_string()), name: None, }]) .build()?; match gemini_client.chat().generate(parameters).await { Ok(response) => { println!("{}", response); } Err(err) => { eprintln!("Error: {:?}", err); } } Ok(()) }
ยง๐ Examples
This repository contains a list of notebooks examples on how to use the sdk and or the cli. To use the notebooks in this repository, you need to set up your environment. Follow these steps to get started:
-
Clone the repository to your local machine:
git clone https://github.com/kevin-rs/gems.git
-
Install the required dependencies and libraries. Make sure you have
Rust
,Jupyter Notebook
, andevcxr_jupyter
installed on your system.# Install a Rust toolchain (e.g. nightly): curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly # Install Jupyter Notebook pip install notebook # Install evcxr_jupyter cargo install evcxr_jupyter evcxr_jupyter --install
-
Navigate to the cloned repository and build the project:
cd gems cargo build --release --all-features
-
Start Jupyter Notebook:
jupyter notebook
-
Access the notebooks in your web browser by clicking on the notebook file you want to explore.
ยง๐ค Contributing
Contributions and feedback are welcome! If youโd like to contribute, report an issue, or suggest an enhancement, please engage with the project on GitHub. Your contributions help improve this crate for the community.
ยง๐ License
This project is licensed under the MIT License.
Re-exportsยง
pub use client::Client;