pub struct GeminiClient { /* private fields */ }Expand description
Gemini client for generating completions
Implementations§
Source§impl GeminiClient
impl GeminiClient
Sourcepub fn model<M: Into<Model>>(self, model: M) -> Self
pub fn model<M: Into<Model>>(self, model: M) -> Self
Set the model to use. Accepts either a Model enum variant or a string.
When a string is provided, it will be converted to a Model enum. If the string
matches a known model variant, that variant is used; otherwise, it becomes Custom(name).
This allows using any model name, including new models or local LLMs, without needing
to update the enum.
Sourcepub fn temperature(self, temp: f32) -> Self
pub fn temperature(self, temp: f32) -> Self
Set the temperature (0.0 to 1.0, lower = more deterministic)
Sourcepub fn max_tokens(self, max: u32) -> Self
pub fn max_tokens(self, max: u32) -> Self
Set the maximum tokens to generate
Sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Set the timeout for HTTP requests.
This sets the total timeout for each HTTP request made by the
client (connection + response). The connect phase additionally
keeps the default connect timeout of 30 seconds
(DEFAULT_CONNECT_TIMEOUT).
If not called, requests use the default timeout of 5 minutes
(DEFAULT_REQUEST_TIMEOUT).
§Arguments
timeout- Timeout duration (e.g.,Duration::from_secs(30)for 30 seconds)
Sourcepub fn max_retries(self, max_retries: usize) -> Self
pub fn max_retries(self, max_retries: usize) -> Self
Set the maximum number of retry attempts for validation errors.
When materialize encounters a validation error, it will automatically
retry up to this many times, including the validation error message in subsequent attempts.
The default is 3 retries. Use .no_retries() to disable retries entirely.
§Arguments
max_retries- Maximum number of retry attempts (0 = no retries, only single attempt)
§Examples
let client = OpenAIClient::new("api-key")?
.max_retries(5); // Increase to 5 retries (default is 3)Sourcepub fn no_retries(self) -> Self
pub fn no_retries(self) -> Self
Disable automatic retries on validation errors.
By default, the client retries up to 3 times when validation errors occur. Use this method to disable retries and fail immediately on the first error.
§Examples
let client = OpenAIClient::new("api-key")?
.no_retries(); // Fail immediately on validation errorsSource§impl GeminiClient
impl GeminiClient
Sourcepub fn base_url(self, base_url: impl Into<String>) -> Self
pub fn base_url(self, base_url: impl Into<String>) -> Self
Set a custom base URL for Gemini-compatible APIs.
§Arguments
base_url- Base URL without trailing slash (e.g., “http://localhost:1234/v1beta” or “https://api.example.com/v1beta”)
Sourcepub fn thinking_level(self, level: ThinkingLevel) -> Self
pub fn thinking_level(self, level: ThinkingLevel) -> Self
Set the thinking level for Gemini 3.x models.
Controls the depth of reasoning the model applies to prompts. Higher thinking levels provide deeper reasoning but increase latency.
§Thinking Levels for Gemini 3 Flash
Minimal: Engages in minimal reasoning, ideal for high-throughput applicationsLow: Reduces latency and cost, appropriate for straightforward tasks (default)Medium: Provides balanced reasoning for most tasksHigh: Offers deep reasoning, suitable for complex problem-solving
§Thinking Levels for Gemini 3.1 Pro
Low: Minimizes latency and cost, suitable for simple tasksHigh: Maximizes reasoning depth for complex tasks
§Example
use rstructor::{GeminiClient, ThinkingLevel};
let client = GeminiClient::from_env()?
.thinking_level(ThinkingLevel::High);Trait Implementations§
Source§impl Clone for GeminiClient
impl Clone for GeminiClient
Source§fn clone(&self) -> GeminiClient
fn clone(&self) -> GeminiClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl From<GeminiClient> for AnyClient
Available on crate feature gemini only.
impl From<GeminiClient> for AnyClient
gemini only.Source§fn from(client: GeminiClient) -> Self
fn from(client: GeminiClient) -> Self
Source§impl LLMClient for GeminiClient
impl LLMClient for GeminiClient
Source§fn list_models<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<ModelInfo>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_models<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<ModelInfo>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Fetch available models from Gemini’s API.
Returns a list of Gemini models that support content generation.