feat: add chat completion without streaming
This commit is contained in:
107
README.md
Normal file
107
README.md
Normal file
@@ -0,0 +1,107 @@
|
||||
# Mistral AI Rust Client
|
||||
|
||||
[](https://crates.io/crates/mistralai-client-rs)
|
||||
[](https://docs.rs/mistralai-client-rs/latest/mistralai-client-rs)
|
||||
[](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.
|
||||
|
||||
---
|
||||
|
||||
- [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)
|
||||
- [Chat without streaming](#chat-without-streaming)
|
||||
- [Chat with streaming](#chat-with-streaming)
|
||||
- [Embeddings](#embeddings)
|
||||
- [List models](#list-models)
|
||||
|
||||
---
|
||||
|
||||
## Supported APIs
|
||||
|
||||
- [x] Chat without streaming
|
||||
- [ ] Chat with streaming
|
||||
- [ ] Embedding
|
||||
- [ ] List models
|
||||
- [ ] Function Calling
|
||||
|
||||
## 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.
|
||||
|
||||
#### As a client argument
|
||||
|
||||
```rs
|
||||
use mistralai_client::v1::client::Client;
|
||||
|
||||
fn main() {
|
||||
let api_key = "your_api_key";
|
||||
|
||||
let client = Client::new(Some(api_key), None, None, None);
|
||||
}
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Chat without streaming
|
||||
|
||||
```rs
|
||||
use mistralai::v1::{
|
||||
chat_completion::{
|
||||
ChatCompletionMessage, ChatCompletionMessageRole, ChatCompletionRequest,
|
||||
ChatCompletionRequestOptions,
|
||||
},
|
||||
client::Client,
|
||||
constants::OPEN_MISTRAL_7B,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
// This example suppose you have set the `MISTRAL_API_KEY` environment variable.
|
||||
let client = Client::new(None, None, None, None);
|
||||
|
||||
let model = OPEN_MISTRAL_7B.to_string();
|
||||
let messages = vec![ChatCompletionMessage {
|
||||
role: ChatCompletionMessageRole::user,
|
||||
content: "Just guess the next word: \"Eiffel ...\"?".to_string(),
|
||||
}];
|
||||
let options = ChatCompletionRequestOptions {
|
||||
temperature: Some(0.0),
|
||||
random_seed: Some(42),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let chat_completion_request = ChatCompletionRequest::new(model, messages, Some(options));
|
||||
let result = client.chat(chat_completion_request).unwrap();
|
||||
println!("Assistant: {}", result.choices[0].message.content);
|
||||
// => "Assistant: Tower. [...]"
|
||||
}
|
||||
```
|
||||
|
||||
### Chat with streaming
|
||||
|
||||
_In progress._
|
||||
|
||||
### Embeddings
|
||||
|
||||
_In progress._
|
||||
|
||||
### List models
|
||||
|
||||
_In progress._
|
||||
Reference in New Issue
Block a user