forked from graniet/llm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmistral_example.rs
More file actions
38 lines (38 loc) · 1.17 KB
/
mistral_example.rs
File metadata and controls
38 lines (38 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use llm::{
builder::{LLMBackend, LLMBuilder},
chat::ChatMessage,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = std::env::var("MISTRAL_API_KEY").unwrap_or("your-mistral-api-key".into());
// Configure Mistral LLM client
let llm = LLMBuilder::new()
.backend(LLMBackend::Mistral)
.api_key(api_key)
.model("mistral-small-latest") // default model
.max_tokens(512)
.temperature(0.7)
.build()
.expect("Failed to build LLM (Mistral)");
// Prepare conversation
let messages = vec![
ChatMessage::user()
.content("Hello, what is Mistral AI?")
.build(),
ChatMessage::assistant()
.content("Mistral AI is ...")
.build(),
ChatMessage::user()
.content("Does it support function calling?")
.build(),
];
// Send chat request
match llm.chat(&messages).await {
Ok(response) => {
println!("Chat response:\n{response}");
println!("Chat response:\n{:?}", response.usage())
}
Err(e) => eprintln!("Chat error: {e}"),
}
Ok(())
}