pub struct GrokClient { /* private fields */ }Expand description
Grok client for generating completions
Implementations§
Source§impl GrokClient
impl GrokClient
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 errorsTrait Implementations§
Source§impl Clone for GrokClient
impl Clone for GrokClient
Source§fn clone(&self) -> GrokClient
fn clone(&self) -> GrokClient
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<GrokClient> for AnyClient
Available on crate feature grok only.
impl From<GrokClient> for AnyClient
grok only.Source§fn from(client: GrokClient) -> Self
fn from(client: GrokClient) -> Self
Source§impl LLMClient for GrokClient
impl LLMClient for GrokClient
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 Grok’s API.
Returns a list of Grok models available for chat completions.