12 Commits

Author SHA1 Message Date
renovate[bot]
678c1983e9 fix(deps): update rust crate thiserror to v2 2024-12-01 00:57:06 +00:00
Ivan Gabriele
9ad6a1dc84 ci(release): v0.14.0 2024-08-27 09:28:58 +02:00
Ivan Gabriele
7c464830ee docs(changelog): update 2024-08-27 09:28:50 +02:00
francois-caddet
161b33c725 feat(constants): update model constants (#17)
* feat(Model)!: Update model constants

- Add new models Mistral Nemo and Codestral Mamba
- Add aliases to models constant to be deserialized seemlessly from the versioned forme (e.g.: "mistral-large-2407")
- The commonly named Mistral Large 2 is now `constants::Model::MistralLargeLatest` when the old one is `Model::MistralLarge`

* tests(Model): Update the tests to check the new model variants.
2024-08-27 09:25:59 +02:00
Ivan Gabriele
79a410b298 ci(release): v0.13.0 2024-08-22 01:15:08 +02:00
Ivan Gabriele
4a45ad337f docs(changelog): update 2024-08-22 01:15:00 +02:00
Ivan Gabriele
2114916941 fix(client)!: update ModelListData struct following API changes
BREAKING CHANGE: `v1::model_list::ModelListData` struct has been updated.
2024-08-22 01:09:27 +02:00
francois-caddet
9bfbf2e9dc fix(client): remove the Content-Type from the headers of the reqwest builders. (#14)
They apparently are conflicting with reqwest internal stufs.

fix #13
2024-08-22 00:45:06 +02:00
Ivan Gabriele
67aa5bbaef ci(release): v0.12.0 2024-07-24 20:23:22 +02:00
Ivan Gabriele
415fd98167 docs(changelog): update 2024-07-24 20:23:01 +02:00
Federico G. Schwindt
8e9f7a5386 feat: mark Function trait as Send (#12)
Allow to use Client in places that are also Send.
2024-07-24 20:16:11 +02:00
Federico G. Schwindt
3afeec1d58 feat: implement the Debug trait for Client (#11)
This is useful if you want to include client::Client in your own
implementation and derive Debug.
2024-07-24 20:08:25 +02:00
9 changed files with 72 additions and 31 deletions

View File

@@ -1,3 +1,24 @@
## [0.14.0](https://github.com/ivangabriele/mistralai-client-rs/compare/v0.13.0...v) (2024-08-27)
### Features
* **constants:** update model constants ([#17](https://github.com/ivangabriele/mistralai-client-rs/issues/17)) ([161b33c](https://github.com/ivangabriele/mistralai-client-rs/commit/161b33c72539a6e982207349942a436df95399b7))
## [0.13.0](https://github.com/ivangabriele/mistralai-client-rs/compare/v0.12.0...v) (2024-08-21)
### ⚠ BREAKING CHANGES
* **client:** `v1::model_list::ModelListData` struct has been updated.
### Bug Fixes
* **client:** remove the `Content-Type` from the headers of the reqwest builders. ([#14](https://github.com/ivangabriele/mistralai-client-rs/issues/14)) ([9bfbf2e](https://github.com/ivangabriele/mistralai-client-rs/commit/9bfbf2e9dc7b48103ac56923fb8b3ac9a5e2d9cf)), closes [#13](https://github.com/ivangabriele/mistralai-client-rs/issues/13)
* **client:** update ModelListData struct following API changes ([2114916](https://github.com/ivangabriele/mistralai-client-rs/commit/2114916941e1ff5aa242290df5f092c0d4954afc))
## [0.12.0](https://github.com/ivangabriele/mistralai-client-rs/compare/v0.11.0...v) (2024-07-24)
### Features
* implement the Debug trait for Client ([#11](https://github.com/ivangabriele/mistralai-client-rs/issues/11)) ([3afeec1](https://github.com/ivangabriele/mistralai-client-rs/commit/3afeec1d586022e43c7b10906acec5e65927ba7d))
* mark Function trait as Send ([#12](https://github.com/ivangabriele/mistralai-client-rs/issues/12)) ([8e9f7a5](https://github.com/ivangabriele/mistralai-client-rs/commit/8e9f7a53863879b2ad618e9e5707b198e4f3b135))
## [0.11.0](https://github.com/ivangabriele/mistralai-client-rs/compare/v0.10.0...v) (2024-06-22) ## [0.11.0](https://github.com/ivangabriele/mistralai-client-rs/compare/v0.10.0...v) (2024-06-22)
### Features ### Features

View File

@@ -2,7 +2,7 @@
name = "mistralai-client" name = "mistralai-client"
description = "Mistral AI API client library for Rust (unofficial)." description = "Mistral AI API client library for Rust (unofficial)."
license = "Apache-2.0" license = "Apache-2.0"
version = "0.11.0" version = "0.14.0"
edition = "2021" edition = "2021"
rust-version = "1.76.0" rust-version = "1.76.0"
@@ -24,7 +24,7 @@ reqwest = { version = "0.12.0", features = ["json", "blocking", "stream"] }
serde = { version = "1.0.197", features = ["derive"] } serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.114" serde_json = "1.0.114"
strum = "0.26.1" strum = "0.26.1"
thiserror = "1.0.57" thiserror = "2.0.0"
tokio = { version = "1.36.0", features = ["full"] } tokio = { version = "1.36.0", features = ["full"] }
tokio-stream = "0.1.14" tokio-stream = "0.1.14"

View File

@@ -10,6 +10,7 @@ use std::{
use crate::v1::{chat, chat_stream, constants, embedding, error, model_list, tool, utils}; use crate::v1::{chat, chat_stream, constants, embedding, error, model_list, tool, utils};
#[derive(Debug)]
pub struct Client { pub struct Client {
pub api_key: String, pub api_key: String,
pub endpoint: String, pub endpoint: String,
@@ -383,7 +384,6 @@ impl Client {
let request_builder = request let request_builder = request
.bearer_auth(&self.api_key) .bearer_auth(&self.api_key)
.header("Accept", "application/json") .header("Accept", "application/json")
.header("Content-Type", "application/json")
.header("User-Agent", user_agent); .header("User-Agent", user_agent);
request_builder request_builder
@@ -398,7 +398,6 @@ impl Client {
let request_builder = request let request_builder = request
.bearer_auth(&self.api_key) .bearer_auth(&self.api_key)
.header("Accept", "application/json") .header("Accept", "application/json")
.header("Content-Type", "application/json")
.header("User-Agent", user_agent); .header("User-Agent", user_agent);
request_builder request_builder
@@ -413,7 +412,6 @@ impl Client {
let request_builder = request let request_builder = request
.bearer_auth(&self.api_key) .bearer_auth(&self.api_key)
.header("Accept", "text/event-stream") .header("Accept", "text/event-stream")
.header("Content-Type", "application/json")
.header("User-Agent", user_agent); .header("User-Agent", user_agent);
request_builder request_builder

View File

@@ -10,16 +10,22 @@ pub enum Model {
OpenMixtral8x7b, OpenMixtral8x7b,
#[serde(rename = "open-mixtral-8x22b")] #[serde(rename = "open-mixtral-8x22b")]
OpenMixtral8x22b, OpenMixtral8x22b,
#[serde(rename = "open-mistral-nemo", alias = "open-mistral-nemo-2407")]
OpenMistralNemo,
#[serde(rename = "mistral-tiny")] #[serde(rename = "mistral-tiny")]
MistralTiny, MistralTiny,
#[serde(rename = "mistral-small-latest")] #[serde(rename = "mistral-small-latest", alias = "mistral-small-2402")]
MistralSmallLatest, MistralSmallLatest,
#[serde(rename = "mistral-medium-latest")] #[serde(rename = "mistral-medium-latest", alias = "mistral-medium-2312")]
MistralMediumLatest, MistralMediumLatest,
#[serde(rename = "mistral-large-latest")] #[serde(rename = "mistral-large-latest", alias = "mistral-large-2407")]
MistralLargeLatest, MistralLargeLatest,
#[serde(rename = "codestral-latest")] #[serde(rename = "mistral-large-2402")]
MistralLarge,
#[serde(rename = "codestral-latest", alias = "codestral-2405")]
CodestralLatest, CodestralLatest,
#[serde(rename = "open-codestral-mamba")]
CodestralMamba,
} }
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)] #[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]

View File

@@ -9,6 +9,7 @@ pub struct ModelListResponse {
pub data: Vec<ModelListData>, pub data: Vec<ModelListData>,
} }
/// See: https://docs.mistral.ai/api/#tag/models
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ModelListData { pub struct ModelListData {
pub id: String, pub id: String,
@@ -16,27 +17,21 @@ pub struct ModelListData {
/// Unix timestamp (in seconds). /// Unix timestamp (in seconds).
pub created: u32, pub created: u32,
pub owned_by: String, pub owned_by: String,
pub permission: Vec<ModelListDataPermission>, pub root: Option<String>,
// TODO Check this prop (seen in API responses but undocumented). pub archived: bool,
// pub root: ???, pub name: String,
// TODO Check this prop (seen in API responses but undocumented). pub description: String,
// pub parent: ???, pub capabilities: ModelListDataCapabilies,
pub max_context_length: u32,
pub aliases: Vec<String>,
/// ISO 8601 date (`YYYY-MM-DDTHH:MM:SSZ`).
pub deprecation: Option<String>,
} }
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ModelListDataPermission { pub struct ModelListDataCapabilies {
pub id: String, pub completion_chat: bool,
pub object: String, pub completion_fim: bool,
/// Unix timestamp (in seconds). pub function_calling: bool,
pub created: u32, pub fine_tuning: bool,
pub allow_create_engine: bool,
pub allow_sampling: bool,
pub allow_logprobs: bool,
pub allow_search_indices: bool,
pub allow_view: bool,
pub allow_fine_tuning: bool,
pub organization: String,
pub is_blocking: bool,
// TODO Check this prop (seen in API responses but undocumented).
// pub group: ???,
} }

View File

@@ -1,6 +1,6 @@
use async_trait::async_trait; use async_trait::async_trait;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{any::Any, collections::HashMap}; use std::{any::Any, collections::HashMap, fmt::Debug};
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Definitions // Definitions
@@ -133,6 +133,12 @@ pub enum ToolChoice {
// Custom // Custom
#[async_trait] #[async_trait]
pub trait Function { pub trait Function: Send {
async fn execute(&self, arguments: String) -> Box<dyn Any + Send>; async fn execute(&self, arguments: String) -> Box<dyn Any + Send>;
} }
impl Debug for dyn Function {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Function()")
}
}

View File

@@ -1,6 +1,11 @@
use jrest::expect; use jrest::expect;
use mistralai_client::v1::{client::Client, error::ClientError}; use mistralai_client::v1::{client::Client, error::ClientError};
#[derive(Debug)]
struct _Foo {
_client: Client,
}
#[test] #[test]
fn test_client_new_with_none_params() { fn test_client_new_with_none_params() {
let maybe_original_mistral_api_key = std::env::var("MISTRAL_API_KEY").ok(); let maybe_original_mistral_api_key = std::env::var("MISTRAL_API_KEY").ok();

View File

@@ -11,11 +11,14 @@ fn test_model_constant() {
Model::OpenMistral7b, Model::OpenMistral7b,
Model::OpenMixtral8x7b, Model::OpenMixtral8x7b,
Model::OpenMixtral8x22b, Model::OpenMixtral8x22b,
Model::OpenMistralNemo,
Model::MistralTiny, Model::MistralTiny,
Model::MistralSmallLatest, Model::MistralSmallLatest,
Model::MistralMediumLatest, Model::MistralMediumLatest,
Model::MistralLargeLatest, Model::MistralLargeLatest,
Model::MistralLarge,
Model::CodestralLatest, Model::CodestralLatest,
Model::CodestralMamba,
]; ];
let client = Client::new(None, None, None, None).unwrap(); let client = Client::new(None, None, None, None).unwrap();

7
tests/v1_tool_test.rs Normal file
View File

@@ -0,0 +1,7 @@
use mistralai_client::v1::client::Client;
trait _Trait: Send {}
struct _Foo {
_dummy: Client,
}
impl _Trait for _Foo {}