pub struct XAI {Show 18 fields
pub api_key: String,
pub model: String,
pub max_tokens: Option<u32>,
pub temperature: Option<f32>,
pub system: Option<String>,
pub timeout_seconds: Option<u64>,
pub stream: Option<bool>,
pub top_p: Option<f32>,
pub top_k: Option<u32>,
pub embedding_encoding_format: Option<String>,
pub embedding_dimensions: Option<u32>,
pub json_schema: Option<StructuredOutputFormat>,
pub xai_search_mode: Option<String>,
pub xai_search_source_type: Option<String>,
pub xai_search_excluded_websites: Option<Vec<String>>,
pub xai_search_max_results: Option<u32>,
pub xai_search_from_date: Option<String>,
pub xai_search_to_date: Option<String>,
/* private fields */
}
Expand description
Client for interacting with X.AI’s API.
This struct provides methods for making chat and completion requests to X.AI’s language models. It handles authentication, request configuration, and response parsing.
Fields§
§api_key: String
API key for authentication with X.AI services
model: String
Model identifier to use for requests (e.g. “grok-2-latest”)
max_tokens: Option<u32>
Maximum number of tokens to generate in responses
temperature: Option<f32>
Temperature parameter for controlling response randomness (0.0 to 1.0)
system: Option<String>
Optional system prompt to provide context
timeout_seconds: Option<u64>
Request timeout duration in seconds
stream: Option<bool>
Whether to enable streaming responses
top_p: Option<f32>
Top-p sampling parameter for controlling response diversity
top_k: Option<u32>
Top-k sampling parameter for controlling response diversity
embedding_encoding_format: Option<String>
Embedding encoding format
embedding_dimensions: Option<u32>
Embedding dimensions
json_schema: Option<StructuredOutputFormat>
JSON schema for structured output
xai_search_mode: Option<String>
XAI search parameters
xai_search_source_type: Option<String>
XAI search sources
xai_search_excluded_websites: Option<Vec<String>>
XAI search excluded websites
xai_search_max_results: Option<u32>
XAI search max results
xai_search_from_date: Option<String>
XAI search from date
xai_search_to_date: Option<String>
XAI search to date
Implementations§
Source§impl XAI
impl XAI
Sourcepub fn new(
api_key: impl Into<String>,
model: Option<String>,
max_tokens: Option<u32>,
temperature: Option<f32>,
timeout_seconds: Option<u64>,
system: Option<String>,
stream: Option<bool>,
top_p: Option<f32>,
top_k: Option<u32>,
embedding_encoding_format: Option<String>,
embedding_dimensions: Option<u32>,
json_schema: Option<StructuredOutputFormat>,
xai_search_mode: Option<String>,
xai_search_source_type: Option<String>,
xai_search_excluded_websites: Option<Vec<String>>,
xai_search_max_results: Option<u32>,
xai_search_from_date: Option<String>,
xai_search_to_date: Option<String>,
) -> Self
pub fn new( api_key: impl Into<String>, model: Option<String>, max_tokens: Option<u32>, temperature: Option<f32>, timeout_seconds: Option<u64>, system: Option<String>, stream: Option<bool>, top_p: Option<f32>, top_k: Option<u32>, embedding_encoding_format: Option<String>, embedding_dimensions: Option<u32>, json_schema: Option<StructuredOutputFormat>, xai_search_mode: Option<String>, xai_search_source_type: Option<String>, xai_search_excluded_websites: Option<Vec<String>>, xai_search_max_results: Option<u32>, xai_search_from_date: Option<String>, xai_search_to_date: Option<String>, ) -> Self
Creates a new X.AI client with the specified configuration.
§Arguments
api_key
- Authentication key for X.AI API accessmodel
- Model identifier (defaults to “grok-2-latest” if None)max_tokens
- Maximum number of tokens to generate in responsestemperature
- Sampling temperature for controlling randomnesstimeout_seconds
- Request timeout duration in secondssystem
- System prompt for providing contextstream
- Whether to enable streaming responsestop_p
- Top-p sampling parametertop_k
- Top-k sampling parameterjson_schema
- JSON schema for structured outputsearch_parameters
- Search parameters for search functionality
§Returns
A configured X.AI client instance ready to make API requests.
Trait Implementations§
Source§impl ChatProvider for XAI
impl ChatProvider for XAI
Source§fn chat<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 [ChatMessage],
) -> Pin<Box<dyn Future<Output = Result<Box<dyn ChatResponse>, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn chat<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 [ChatMessage],
) -> Pin<Box<dyn Future<Output = Result<Box<dyn ChatResponse>, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn chat_with_tools<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [ChatMessage],
_tools: Option<&'life2 [Tool]>,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn ChatResponse>, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn chat_with_tools<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [ChatMessage],
_tools: Option<&'life2 [Tool]>,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn ChatResponse>, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn chat_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 [ChatMessage],
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<String, LLMError>> + Send>>, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn chat_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 [ChatMessage],
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<String, LLMError>> + Send>>, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn memory_contents<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Option<Vec<ChatMessage>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn memory_contents<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Option<Vec<ChatMessage>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn summarize_history<'life0, 'life1, 'async_trait>(
&'life0 self,
msgs: &'life1 [ChatMessage],
) -> Pin<Box<dyn Future<Output = Result<String, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn summarize_history<'life0, 'life1, 'async_trait>(
&'life0 self,
msgs: &'life1 [ChatMessage],
) -> Pin<Box<dyn Future<Output = Result<String, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§impl CompletionProvider for XAI
impl CompletionProvider for XAI
Source§impl EmbeddingProvider for XAI
impl EmbeddingProvider for XAI
Source§impl SpeechToTextProvider for XAI
impl SpeechToTextProvider for XAI
Source§fn transcribe<'life0, 'async_trait>(
&'life0 self,
_audio: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<String, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn transcribe<'life0, 'async_trait>(
&'life0 self,
_audio: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<String, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn transcribe_file<'life0, 'life1, 'async_trait>(
&'life0 self,
file_path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<String, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§impl TextToSpeechProvider for XAI
impl TextToSpeechProvider for XAI
Auto Trait Implementations§
impl Freeze for XAI
impl !RefUnwindSafe for XAI
impl Send for XAI
impl Sync for XAI
impl Unpin for XAI
impl !UnwindSafe for XAI
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more