pub struct XAI { /* private fields */ }
Implementations§
Source§impl XAI
impl XAI
Sourcepub fn new(api_key: String) -> Self
pub fn new(api_key: String) -> Self
Examples found in repository?
examples/xai.rs (line 11)
8async fn main() {
9 let api_key = std::env::var("XAI_API_KEY").expect("XAI_API_KEY environment variable not set");
10
11 let client = XAI::new(api_key);
12
13 let request = ChatCompletionRequest {
14 model: "grok-2-latest".to_string(),
15 messages: vec![
16 ChatMessage {
17 role: "system".to_string(),
18 content: "You are a helpful assistant.".to_string(),
19 },
20 ChatMessage {
21 role: "user".to_string(),
22 content: "Hello!".to_string(),
23 },
24 ],
25 temperature: Some(0.7),
26 max_tokens: Some(50),
27 };
28
29 match client.chat_completion(request).await {
30 Ok(response) => {
31 for choice in response.choices {
32 println!("Response: {}", choice.message.content);
33 }
34 }
35 Err(e) => eprintln!("Error: {}", e),
36 }
37}
Trait Implementations§
Source§impl LlmProvider for XAI
impl LlmProvider for XAI
fn chat_completion<'life0, 'async_trait>(
&'life0 self,
request: ChatCompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatCompletionResponse, LlmApiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
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
Mutably borrows from an owned value. Read more