pub struct Client { /* private fields */ }Implementations§
Source§impl Client
impl Client
pub fn new(api_key: &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(&self, model: &str) -> EmbeddingsBuilder<EmbeddingModel>
pub fn embeddings(&self, model: &str) -> EmbeddingsBuilder<EmbeddingModel>
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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)