2024-03-03 15:20:30 +01:00
|
|
|
# Mistral AI Rust Client
|
|
|
|
|
|
2024-03-03 15:35:57 +01:00
|
|
|
[](https://crates.io/crates/mistralai-client)
|
|
|
|
|
[](https://docs.rs/mistralai-client/latest/mistralai-client)
|
2024-03-03 15:20:30 +01:00
|
|
|
[](https://github.com/ivangabriele/mistralai-client-rs/actions?query=branch%3Amain+workflow%3ATest++)
|
|
|
|
|
[](https://app.codecov.io/github/ivangabriele/mistralai-client-rs)
|
|
|
|
|
|
|
|
|
|
Rust client for the Mistral AI API.
|
|
|
|
|
|
2024-06-07 15:53:25 +02:00
|
|
|
> [!IMPORTANT]
|
|
|
|
|
> While we are in v0, minor versions may introduce breaking changes.
|
|
|
|
|
> Please, refer to the [CHANGELOG.md](./CHANGELOG.md) for more information.
|
|
|
|
|
|
2024-03-03 15:20:30 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
|
|
- [Supported APIs](#supported-apis)
|
|
|
|
|
- [Installation](#installation)
|
|
|
|
|
- [Mistral API Key](#mistral-api-key)
|
|
|
|
|
- [As an environment variable](#as-an-environment-variable)
|
|
|
|
|
- [As a client argument](#as-a-client-argument)
|
|
|
|
|
- [Usage](#usage)
|
2024-03-09 11:28:50 +01:00
|
|
|
- [Chat](#chat)
|
|
|
|
|
- [Chat (async)](#chat-async)
|
2024-03-04 08:16:06 +01:00
|
|
|
- [Chat with streaming (async)](#chat-with-streaming-async)
|
2024-03-09 11:28:50 +01:00
|
|
|
- [Chat with Function Calling](#chat-with-function-calling)
|
|
|
|
|
- [Chat with Function Calling (async)](#chat-with-function-calling-async)
|
2024-03-03 15:20:30 +01:00
|
|
|
- [Embeddings](#embeddings)
|
2024-03-04 04:57:48 +01:00
|
|
|
- [Embeddings (async)](#embeddings-async)
|
2024-03-03 15:20:30 +01:00
|
|
|
- [List models](#list-models)
|
2024-03-04 04:57:48 +01:00
|
|
|
- [List models (async)](#list-models-async)
|
2024-03-09 11:28:50 +01:00
|
|
|
- [Contributing](#contributing)
|
2024-03-03 15:20:30 +01:00
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Supported APIs
|
|
|
|
|
|
|
|
|
|
- [x] Chat without streaming
|
2024-03-04 04:57:48 +01:00
|
|
|
- [x] Chat without streaming (async)
|
2024-03-04 08:16:06 +01:00
|
|
|
- [x] Chat with streaming
|
2024-03-04 03:14:23 +01:00
|
|
|
- [x] Embedding
|
2024-03-04 06:39:21 +01:00
|
|
|
- [x] Embedding (async)
|
2024-03-03 19:38:34 +01:00
|
|
|
- [x] List models
|
2024-03-04 06:32:01 +01:00
|
|
|
- [x] List models (async)
|
2024-03-09 11:28:50 +01:00
|
|
|
- [x] Function Calling
|
|
|
|
|
- [x] Function Calling (async)
|
2024-03-03 15:20:30 +01:00
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
|
|
You can install the library in your project using:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
cargo add mistralai-client
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Mistral API Key
|
|
|
|
|
|
|
|
|
|
You can get your Mistral API Key there: <https://docs.mistral.ai/#api-access>.
|
|
|
|
|
|
|
|
|
|
#### As an environment variable
|
|
|
|
|
|
|
|
|
|
Just set the `MISTRAL_API_KEY` environment variable.
|
|
|
|
|
|
2024-03-09 11:28:50 +01:00
|
|
|
```rs
|
|
|
|
|
use mistralai_client::v1::client::Client;
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
let client = Client::new(None, None, None, None);
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
MISTRAL_API_KEY=your_api_key cargo run
|
|
|
|
|
```
|
|
|
|
|
|
2024-03-03 15:20:30 +01:00
|
|
|
#### As a client argument
|
|
|
|
|
|
|
|
|
|
```rs
|
|
|
|
|
use mistralai_client::v1::client::Client;
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
let api_key = "your_api_key";
|
|
|
|
|
|
2024-03-04 04:43:16 +01:00
|
|
|
let client = Client::new(Some(api_key), None, None, None).unwrap();
|
2024-03-03 15:20:30 +01:00
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
2024-03-09 11:28:50 +01:00
|
|
|
### Chat
|
2024-03-03 15:20:30 +01:00
|
|
|
|
|
|
|
|
```rs
|
2024-03-03 19:38:34 +01:00
|
|
|
use mistralai_client::v1::{
|
2024-03-09 11:28:50 +01:00
|
|
|
chat::{ChatMessage, ChatMessageRole, ChatParams},
|
2024-03-03 15:20:30 +01:00
|
|
|
client::Client,
|
2024-03-04 03:14:23 +01:00
|
|
|
constants::Model,
|
2024-03-03 15:20:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
// This example suppose you have set the `MISTRAL_API_KEY` environment variable.
|
2024-03-04 04:43:16 +01:00
|
|
|
let client = Client::new(None, None, None, None).unwrap();
|
2024-03-03 15:20:30 +01:00
|
|
|
|
2024-03-04 03:14:23 +01:00
|
|
|
let model = Model::OpenMistral7b;
|
2024-03-04 08:16:06 +01:00
|
|
|
let messages = vec![ChatMessage {
|
2024-03-09 11:28:50 +01:00
|
|
|
role: ChatMessageRole::User,
|
2024-03-03 15:20:30 +01:00
|
|
|
content: "Just guess the next word: \"Eiffel ...\"?".to_string(),
|
2024-03-09 11:28:50 +01:00
|
|
|
tool_calls: None,
|
2024-03-03 15:20:30 +01:00
|
|
|
}];
|
2024-03-09 11:28:50 +01:00
|
|
|
let options = ChatParams {
|
2024-06-07 15:53:25 +02:00
|
|
|
temperature: 0.0,
|
2024-03-03 15:20:30 +01:00
|
|
|
random_seed: Some(42),
|
|
|
|
|
..Default::default()
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-03 19:10:25 +01:00
|
|
|
let result = client.chat(model, messages, Some(options)).unwrap();
|
2024-03-03 15:20:30 +01:00
|
|
|
println!("Assistant: {}", result.choices[0].message.content);
|
2024-03-09 11:28:50 +01:00
|
|
|
// => "Assistant: Tower. The Eiffel Tower is a famous landmark in Paris, France."
|
2024-03-03 15:20:30 +01:00
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2024-03-09 11:28:50 +01:00
|
|
|
### Chat (async)
|
2024-03-04 04:57:48 +01:00
|
|
|
|
|
|
|
|
```rs
|
|
|
|
|
use mistralai_client::v1::{
|
2024-03-09 11:28:50 +01:00
|
|
|
chat::{ChatMessage, ChatMessageRole, ChatParams},
|
2024-03-04 04:57:48 +01:00
|
|
|
client::Client,
|
|
|
|
|
constants::Model,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
|
async fn main() {
|
|
|
|
|
// This example suppose you have set the `MISTRAL_API_KEY` environment variable.
|
|
|
|
|
let client = Client::new(None, None, None, None).unwrap();
|
|
|
|
|
|
|
|
|
|
let model = Model::OpenMistral7b;
|
2024-03-04 08:16:06 +01:00
|
|
|
let messages = vec![ChatMessage {
|
2024-03-09 11:28:50 +01:00
|
|
|
role: ChatMessageRole::User,
|
2024-03-04 04:57:48 +01:00
|
|
|
content: "Just guess the next word: \"Eiffel ...\"?".to_string(),
|
2024-03-09 11:28:50 +01:00
|
|
|
tool_calls: None,
|
2024-03-04 04:57:48 +01:00
|
|
|
}];
|
2024-03-09 11:28:50 +01:00
|
|
|
let options = ChatParams {
|
2024-06-07 15:53:25 +02:00
|
|
|
temperature: 0.0,
|
2024-03-04 04:57:48 +01:00
|
|
|
random_seed: Some(42),
|
|
|
|
|
..Default::default()
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-09 11:28:50 +01:00
|
|
|
let result = client
|
|
|
|
|
.chat_async(model, messages, Some(options))
|
|
|
|
|
.await
|
|
|
|
|
.unwrap();
|
|
|
|
|
println!(
|
|
|
|
|
"{:?}: {}",
|
|
|
|
|
result.choices[0].message.role, result.choices[0].message.content
|
|
|
|
|
);
|
|
|
|
|
// => "Assistant: Tower. The Eiffel Tower is a famous landmark in Paris, France."
|
2024-03-04 04:57:48 +01:00
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2024-03-04 08:16:06 +01:00
|
|
|
### Chat with streaming (async)
|
2024-03-03 15:20:30 +01:00
|
|
|
|
2024-03-04 08:16:06 +01:00
|
|
|
```rs
|
|
|
|
|
use futures::stream::StreamExt;
|
|
|
|
|
use mistralai_client::v1::{
|
2024-03-09 11:28:50 +01:00
|
|
|
chat::{ChatMessage, ChatMessageRole, ChatParams},
|
2024-03-04 08:16:06 +01:00
|
|
|
client::Client,
|
|
|
|
|
constants::Model,
|
|
|
|
|
};
|
2024-03-09 11:28:50 +01:00
|
|
|
use std::io::{self, Write};
|
2024-03-04 08:16:06 +01:00
|
|
|
|
2024-03-09 11:28:50 +01:00
|
|
|
#[tokio::main]
|
2024-03-04 08:16:06 +01:00
|
|
|
async fn main() {
|
|
|
|
|
// This example suppose you have set the `MISTRAL_API_KEY` environment variable.
|
2024-03-09 11:28:50 +01:00
|
|
|
let client = Client::new(None, None, None, None).unwrap();
|
2024-03-04 08:16:06 +01:00
|
|
|
|
|
|
|
|
let model = Model::OpenMistral7b;
|
|
|
|
|
let messages = vec![ChatMessage {
|
2024-03-09 11:28:50 +01:00
|
|
|
role: ChatMessageRole::User,
|
|
|
|
|
content: "Tell me a short happy story.".to_string(),
|
|
|
|
|
tool_calls: None,
|
2024-03-04 08:16:06 +01:00
|
|
|
}];
|
2024-03-09 11:28:50 +01:00
|
|
|
let options = ChatParams {
|
2024-06-07 15:53:25 +02:00
|
|
|
temperature: 0.0,
|
2024-03-04 08:16:06 +01:00
|
|
|
random_seed: Some(42),
|
|
|
|
|
..Default::default()
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-09 11:28:50 +01:00
|
|
|
let stream_result = client
|
|
|
|
|
.chat_stream(model, messages, Some(options))
|
|
|
|
|
.await
|
2024-03-09 11:41:39 +01:00
|
|
|
.unwrap();
|
2024-03-09 11:28:50 +01:00
|
|
|
stream_result
|
|
|
|
|
.for_each(|chunk_result| async {
|
|
|
|
|
match chunk_result {
|
|
|
|
|
Ok(chunks) => chunks.iter().for_each(|chunk| {
|
|
|
|
|
print!("{}", chunk.choices[0].delta.content);
|
|
|
|
|
io::stdout().flush().unwrap();
|
|
|
|
|
// => "Once upon a time, [...]"
|
|
|
|
|
}),
|
|
|
|
|
Err(error) => {
|
|
|
|
|
eprintln!("Error processing chunk: {:?}", error)
|
|
|
|
|
}
|
2024-03-04 08:16:06 +01:00
|
|
|
}
|
2024-03-09 11:28:50 +01:00
|
|
|
})
|
|
|
|
|
.await;
|
|
|
|
|
print!("\n") // To persist the last chunk output.
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Chat with Function Calling
|
|
|
|
|
|
|
|
|
|
```rs
|
|
|
|
|
use mistralai_client::v1::{
|
|
|
|
|
chat::{ChatMessage, ChatMessageRole, ChatParams},
|
|
|
|
|
client::Client,
|
|
|
|
|
constants::Model,
|
|
|
|
|
tool::{Function, Tool, ToolChoice, ToolFunctionParameter, ToolFunctionParameterType},
|
|
|
|
|
};
|
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
use std::any::Any;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
|
struct GetCityTemperatureArguments {
|
|
|
|
|
city: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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() {
|
|
|
|
|
"Paris" => "20°C",
|
|
|
|
|
_ => "Unknown city",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Box::new(temperature.to_string())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
)],
|
|
|
|
|
)];
|
|
|
|
|
|
|
|
|
|
// This example suppose you have set the `MISTRAL_API_KEY` environment variable.
|
|
|
|
|
let mut client = Client::new(None, None, None, None).unwrap();
|
|
|
|
|
client.register_function(
|
|
|
|
|
"get_city_temperature".to_string(),
|
|
|
|
|
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 options = ChatParams {
|
2024-06-07 15:53:25 +02:00
|
|
|
temperature: 0.0,
|
2024-03-09 11:28:50 +01:00
|
|
|
random_seed: Some(42),
|
|
|
|
|
tool_choice: Some(ToolChoice::Auto),
|
|
|
|
|
tools: Some(tools),
|
|
|
|
|
..Default::default()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
client.chat(model, messages, Some(options)).unwrap();
|
|
|
|
|
let temperature = client
|
|
|
|
|
.get_last_function_call_result()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.downcast::<String>()
|
|
|
|
|
.unwrap();
|
|
|
|
|
println!("The temperature in Paris is: {}.", temperature);
|
|
|
|
|
// => "The temperature in Paris is: 20°C."
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Chat with Function Calling (async)
|
|
|
|
|
|
|
|
|
|
```rs
|
|
|
|
|
use mistralai_client::v1::{
|
|
|
|
|
chat::{ChatMessage, ChatMessageRole, ChatParams},
|
|
|
|
|
client::Client,
|
|
|
|
|
constants::Model,
|
|
|
|
|
tool::{Function, Tool, ToolChoice, ToolFunctionParameter, ToolFunctionParameterType},
|
|
|
|
|
};
|
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
use std::any::Any;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
|
struct GetCityTemperatureArguments {
|
|
|
|
|
city: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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() {
|
|
|
|
|
"Paris" => "20°C",
|
|
|
|
|
_ => "Unknown city",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Box::new(temperature.to_string())
|
2024-03-04 08:16:06 +01:00
|
|
|
}
|
|
|
|
|
}
|
2024-03-09 11:28:50 +01:00
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
|
async 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,
|
|
|
|
|
)],
|
|
|
|
|
)];
|
|
|
|
|
|
|
|
|
|
// This example suppose you have set the `MISTRAL_API_KEY` environment variable.
|
|
|
|
|
let mut client = Client::new(None, None, None, None).unwrap();
|
|
|
|
|
client.register_function(
|
|
|
|
|
"get_city_temperature".to_string(),
|
|
|
|
|
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 options = ChatParams {
|
2024-06-07 15:53:25 +02:00
|
|
|
temperature: 0.0,
|
2024-03-09 11:28:50 +01:00
|
|
|
random_seed: Some(42),
|
|
|
|
|
tool_choice: Some(ToolChoice::Auto),
|
|
|
|
|
tools: Some(tools),
|
|
|
|
|
..Default::default()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
client
|
|
|
|
|
.chat_async(model, messages, Some(options))
|
|
|
|
|
.await
|
|
|
|
|
.unwrap();
|
|
|
|
|
let temperature = client
|
|
|
|
|
.get_last_function_call_result()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.downcast::<String>()
|
|
|
|
|
.unwrap();
|
|
|
|
|
println!("The temperature in Paris is: {}.", temperature);
|
|
|
|
|
// => "The temperature in Paris is: 20°C."
|
|
|
|
|
}
|
2024-03-04 08:16:06 +01:00
|
|
|
```
|
2024-03-03 15:20:30 +01:00
|
|
|
|
|
|
|
|
### Embeddings
|
|
|
|
|
|
2024-03-04 03:14:23 +01:00
|
|
|
```rs
|
|
|
|
|
use mistralai_client::v1::{client::Client, constants::EmbedModel};
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
// This example suppose you have set the `MISTRAL_API_KEY` environment variable.
|
2024-03-09 11:28:50 +01:00
|
|
|
let client: Client = Client::new(None, None, None, None).unwrap();
|
|
|
|
|
|
|
|
|
|
let model = EmbedModel::MistralEmbed;
|
|
|
|
|
let input = vec!["Embed this sentence.", "As well as this one."]
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|s| s.to_string())
|
|
|
|
|
.collect();
|
|
|
|
|
let options = None;
|
|
|
|
|
|
|
|
|
|
let response = client.embeddings(model, input, options).unwrap();
|
|
|
|
|
println!("First Embedding: {:?}", response.data[0]);
|
|
|
|
|
// => "First Embedding: {...}"
|
2024-03-04 03:14:23 +01:00
|
|
|
}
|
|
|
|
|
```
|
2024-03-03 15:20:30 +01:00
|
|
|
|
2024-03-04 04:57:48 +01:00
|
|
|
### Embeddings (async)
|
|
|
|
|
|
2024-03-04 06:39:21 +01:00
|
|
|
```rs
|
|
|
|
|
use mistralai_client::v1::{client::Client, constants::EmbedModel};
|
|
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
|
async fn main() {
|
|
|
|
|
// This example suppose you have set the `MISTRAL_API_KEY` environment variable.
|
2024-03-09 11:28:50 +01:00
|
|
|
let client: Client = Client::new(None, None, None, None).unwrap();
|
|
|
|
|
|
|
|
|
|
let model = EmbedModel::MistralEmbed;
|
|
|
|
|
let input = vec!["Embed this sentence.", "As well as this one."]
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|s| s.to_string())
|
|
|
|
|
.collect();
|
|
|
|
|
let options = None;
|
|
|
|
|
|
|
|
|
|
let response = client
|
|
|
|
|
.embeddings_async(model, input, options)
|
|
|
|
|
.await
|
|
|
|
|
.unwrap();
|
|
|
|
|
println!("First Embedding: {:?}", response.data[0]);
|
|
|
|
|
// => "First Embedding: {...}"
|
2024-03-04 06:39:21 +01:00
|
|
|
}
|
|
|
|
|
```
|
2024-03-04 04:57:48 +01:00
|
|
|
|
2024-03-03 15:20:30 +01:00
|
|
|
### List models
|
|
|
|
|
|
2024-03-03 19:38:34 +01:00
|
|
|
```rs
|
|
|
|
|
use mistralai_client::v1::client::Client;
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
// This example suppose you have set the `MISTRAL_API_KEY` environment variable.
|
2024-03-04 04:43:16 +01:00
|
|
|
let client = Client::new(None, None, None, None).unwrap();
|
2024-03-03 19:38:34 +01:00
|
|
|
|
2024-03-04 03:27:20 +01:00
|
|
|
let result = client.list_models().unwrap();
|
2024-03-03 19:38:34 +01:00
|
|
|
println!("First Model ID: {:?}", result.data[0].id);
|
|
|
|
|
// => "First Model ID: open-mistral-7b"
|
|
|
|
|
}
|
|
|
|
|
```
|
2024-03-04 04:57:48 +01:00
|
|
|
|
|
|
|
|
### List models (async)
|
|
|
|
|
|
2024-03-04 06:32:01 +01:00
|
|
|
```rs
|
|
|
|
|
use mistralai_client::v1::client::Client;
|
|
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
|
async fn main() {
|
|
|
|
|
// This example suppose you have set the `MISTRAL_API_KEY` environment variable.
|
2024-03-09 11:28:50 +01:00
|
|
|
let client = Client::new(None, None, None, None).unwrap();
|
2024-03-04 06:32:01 +01:00
|
|
|
|
2024-03-09 11:28:50 +01:00
|
|
|
let result = client.list_models_async().await.unwrap();
|
2024-03-04 06:32:01 +01:00
|
|
|
println!("First Model ID: {:?}", result.data[0].id);
|
|
|
|
|
// => "First Model ID: open-mistral-7b"
|
|
|
|
|
}
|
|
|
|
|
```
|
2024-03-09 11:28:50 +01:00
|
|
|
|
|
|
|
|
## Contributing
|
|
|
|
|
|
|
|
|
|
Please read [CONTRIBUTING.md](./CONTRIBUTING.md) for details on how to contribute to this library.
|