pub struct Client { /* private fields */ }Implementations§
Source§impl Client
impl Client
pub fn new(api_key: &str) -> Self
pub fn from_url(api_key: &str, base_url: &str) -> Self
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Create a new Google Gemini client from the GEMINI_API_KEY environment variable.
Panics if the environment variable is not set.
pub fn post(&self, path: &str) -> RequestBuilder
Sourcepub fn embedding_model(&self, model: &str) -> EmbeddingModel
pub fn embedding_model(&self, model: &str) -> EmbeddingModel
Create an embedding model with the given name.
Note: default embedding dimension of 0 will be used if model is not known.
If this is the case, it’s better to use function embedding_model_with_ndims
§Example
use rig::providers::gemini::{Client, self};
// Initialize the Google Gemini client
let gemini = Client::new("your-google-gemini-api-key");
let embedding_model = gemini.embedding_model(gemini::embedding::EMBEDDING_GECKO_001);Sourcepub fn embedding_model_with_ndims(
&self,
model: &str,
ndims: usize,
) -> EmbeddingModel
pub fn embedding_model_with_ndims( &self, model: &str, ndims: usize, ) -> EmbeddingModel
Create an embedding model with the given name and the number of dimensions in the embedding generated by the model.
§Example
use rig::providers::gemini::{Client, self};
// Initialize the Google Gemini client
let gemini = Client::new("your-google-gemini-api-key");
let embedding_model = gemini.embedding_model_with_ndims("model-unknown-to-rig", 1024);Sourcepub fn embeddings<D: Embed>(
&self,
model: &str,
) -> EmbeddingsBuilder<EmbeddingModel, D>
pub fn embeddings<D: Embed>( &self, model: &str, ) -> EmbeddingsBuilder<EmbeddingModel, D>
Create an embedding builder with the given embedding model.
§Example
use rig::providers::gemini::{Client, self};
// Initialize the Google Gemini client
let gemini = Client::new("your-google-gemini-api-key");
let embeddings = gemini.embeddings(gemini::embedding::EMBEDDING_GECKO_001)
.simple_document("doc0", "Hello, world!")
.simple_document("doc1", "Goodbye, world!")
.build()
.await
.expect("Failed to embed documents");Sourcepub fn completion_model(&self, model: &str) -> CompletionModel
pub fn completion_model(&self, model: &str) -> CompletionModel
Create a completion model with the given name. Gemini-specific parameters can be set using the GenerationConfig struct. Gemini API Reference
Sourcepub fn agent(&self, model: &str) -> AgentBuilder<CompletionModel>
pub fn agent(&self, model: &str) -> AgentBuilder<CompletionModel>
Create an agent builder with the given completion model. Gemini-specific parameters can be set using the GenerationConfig struct. Gemini API Reference
§Example
use rig::providers::gemini::{Client, self};
// Initialize the Google Gemini client
let gemini = Client::new("your-google-gemini-api-key");
let agent = gemini.agent(gemini::completion::GEMINI_1_5_PRO)
.preamble("You are comedian AI with a mission to make people laugh.")
.temperature(0.0)
.build();Sourcepub fn extractor<T: JsonSchema + for<'a> Deserialize<'a> + Serialize + Send + Sync>(
&self,
model: &str,
) -> ExtractorBuilder<T, CompletionModel>
pub fn extractor<T: JsonSchema + for<'a> Deserialize<'a> + Serialize + Send + Sync>( &self, model: &str, ) -> ExtractorBuilder<T, CompletionModel>
Create an extractor builder with the given completion model.