docs: update README and examples for v1.0.0

- Rewrite README with all new endpoints and current model names
- Add available models table with constructors
- Add FIM and OCR examples
- Update all examples for string-based Model type
- Update streaming example for Option<String> delta content
- Use serde_json::json!() for tool schemas in examples
- Add .envrc to .gitignore
This commit is contained in:
2026-03-20 18:00:51 +00:00
parent ce96bcfeeb
commit 63f0edf574
11 changed files with 229 additions and 358 deletions

View File

@@ -1,8 +1,8 @@
use mistralai_client::v1::{
chat::{ChatMessage, ChatMessageRole, ChatParams},
chat::{ChatMessage, ChatParams},
client::Client,
constants::Model,
tool::{Function, Tool, ToolChoice, ToolFunctionParameter, ToolFunctionParameterType},
tool::{Function, Tool, ToolChoice},
};
use serde::Deserialize;
use std::any::Any;
@@ -16,7 +16,6 @@ struct GetCityTemperatureFunction;
#[async_trait::async_trait]
impl Function for GetCityTemperatureFunction {
async fn execute(&self, arguments: String) -> Box<dyn Any + Send> {
// Deserialize arguments, perform the logic, and return the result
let GetCityTemperatureArguments { city } = serde_json::from_str(&arguments).unwrap();
let temperature = match city.as_str() {
@@ -32,11 +31,16 @@ fn main() {
let tools = vec![Tool::new(
"get_city_temperature".to_string(),
"Get the current temperature in a city.".to_string(),
vec![ToolFunctionParameter::new(
"city".to_string(),
"The name of the city.".to_string(),
ToolFunctionParameterType::String,
)],
serde_json::json!({
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "The name of the city."
}
},
"required": ["city"]
}),
)];
// This example suppose you have set the `MISTRAL_API_KEY` environment variable.
@@ -46,14 +50,12 @@ fn main() {
Box::new(GetCityTemperatureFunction),
);
let model = Model::MistralSmallLatest;
let messages = vec![ChatMessage {
role: ChatMessageRole::User,
content: "What's the temperature in Paris?".to_string(),
tool_calls: None,
}];
let model = Model::mistral_small_latest();
let messages = vec![ChatMessage::new_user_message(
"What's the temperature in Paris?",
)];
let options = ChatParams {
temperature: 0.0,
temperature: Some(0.0),
random_seed: Some(42),
tool_choice: Some(ToolChoice::Auto),
tools: Some(tools),