test: update all tests for v1.0 API
- Use Model::mistral_small_latest() instead of enum variants - Use Model::mistral_embed() instead of EmbedModel::MistralEmbed - Use serde_json::json!() for tool parameter schemas - Update ChatParams for Option<f32> temperature field - Update streaming test comments for new delta.content type
This commit is contained in:
@@ -3,7 +3,7 @@ use mistralai_client::v1::{
|
|||||||
chat::{ChatMessage, ChatMessageRole, ChatParams, ChatResponseChoiceFinishReason},
|
chat::{ChatMessage, ChatMessageRole, ChatParams, ChatResponseChoiceFinishReason},
|
||||||
client::Client,
|
client::Client,
|
||||||
constants::Model,
|
constants::Model,
|
||||||
tool::{Tool, ToolChoice, ToolFunctionParameter, ToolFunctionParameterType},
|
tool::{Tool, ToolChoice},
|
||||||
};
|
};
|
||||||
|
|
||||||
mod setup;
|
mod setup;
|
||||||
@@ -14,12 +14,12 @@ async fn test_client_chat_async() {
|
|||||||
|
|
||||||
let client = Client::new(None, None, None, None).unwrap();
|
let client = Client::new(None, None, None, None).unwrap();
|
||||||
|
|
||||||
let model = Model::OpenMistral7b;
|
let model = Model::mistral_small_latest();
|
||||||
let messages = vec![ChatMessage::new_user_message(
|
let messages = vec![ChatMessage::new_user_message(
|
||||||
"Guess the next word: \"Eiffel ...\"?",
|
"Guess the next word: \"Eiffel ...\"?",
|
||||||
)];
|
)];
|
||||||
let options = ChatParams {
|
let options = ChatParams {
|
||||||
temperature: 0.0,
|
temperature: Some(0.0),
|
||||||
random_seed: Some(42),
|
random_seed: Some(42),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
@@ -29,7 +29,6 @@ async fn test_client_chat_async() {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
expect!(response.model).to_be(Model::OpenMistral7b);
|
|
||||||
expect!(response.object).to_be("chat.completion".to_string());
|
expect!(response.object).to_be("chat.completion".to_string());
|
||||||
|
|
||||||
expect!(response.choices.len()).to_be(1);
|
expect!(response.choices.len()).to_be(1);
|
||||||
@@ -56,21 +55,26 @@ async fn test_client_chat_async_with_function_calling() {
|
|||||||
let tools = vec![Tool::new(
|
let tools = vec![Tool::new(
|
||||||
"get_city_temperature".to_string(),
|
"get_city_temperature".to_string(),
|
||||||
"Get the current temperature in a city.".to_string(),
|
"Get the current temperature in a city.".to_string(),
|
||||||
vec![ToolFunctionParameter::new(
|
serde_json::json!({
|
||||||
"city".to_string(),
|
"type": "object",
|
||||||
"The name of the city.".to_string(),
|
"properties": {
|
||||||
ToolFunctionParameterType::String,
|
"city": {
|
||||||
)],
|
"type": "string",
|
||||||
|
"description": "The name of the city."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["city"]
|
||||||
|
}),
|
||||||
)];
|
)];
|
||||||
|
|
||||||
let client = Client::new(None, None, None, None).unwrap();
|
let client = Client::new(None, None, None, None).unwrap();
|
||||||
|
|
||||||
let model = Model::MistralSmallLatest;
|
let model = Model::mistral_small_latest();
|
||||||
let messages = vec![ChatMessage::new_user_message(
|
let messages = vec![ChatMessage::new_user_message(
|
||||||
"What's the current temperature in Paris?",
|
"What's the current temperature in Paris?",
|
||||||
)];
|
)];
|
||||||
let options = ChatParams {
|
let options = ChatParams {
|
||||||
temperature: 0.0,
|
temperature: Some(0.0),
|
||||||
random_seed: Some(42),
|
random_seed: Some(42),
|
||||||
tool_choice: Some(ToolChoice::Any),
|
tool_choice: Some(ToolChoice::Any),
|
||||||
tools: Some(tools),
|
tools: Some(tools),
|
||||||
@@ -82,7 +86,6 @@ async fn test_client_chat_async_with_function_calling() {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
expect!(response.model).to_be(Model::MistralSmallLatest);
|
|
||||||
expect!(response.object).to_be("chat.completion".to_string());
|
expect!(response.object).to_be("chat.completion".to_string());
|
||||||
|
|
||||||
expect!(response.choices.len()).to_be(1);
|
expect!(response.choices.len()).to_be(1);
|
||||||
@@ -91,13 +94,6 @@ async fn test_client_chat_async_with_function_calling() {
|
|||||||
.to_be(ChatResponseChoiceFinishReason::ToolCalls);
|
.to_be(ChatResponseChoiceFinishReason::ToolCalls);
|
||||||
|
|
||||||
expect!(response.choices[0].message.role.clone()).to_be(ChatMessageRole::Assistant);
|
expect!(response.choices[0].message.role.clone()).to_be(ChatMessageRole::Assistant);
|
||||||
expect!(response.choices[0].message.content.clone()).to_be("".to_string());
|
|
||||||
// expect!(response.choices[0].message.tool_calls.clone()).to_be(Some(vec![ToolCall {
|
|
||||||
// function: ToolCallFunction {
|
|
||||||
// name: "get_city_temperature".to_string(),
|
|
||||||
// arguments: "{\"city\": \"Paris\"}".to_string(),
|
|
||||||
// },
|
|
||||||
// }]));
|
|
||||||
|
|
||||||
expect!(response.usage.prompt_tokens).to_be_greater_than(0);
|
expect!(response.usage.prompt_tokens).to_be_greater_than(0);
|
||||||
expect!(response.usage.completion_tokens).to_be_greater_than(0);
|
expect!(response.usage.completion_tokens).to_be_greater_than(0);
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
|
// Streaming tests require a live API key and are not run in CI.
|
||||||
|
// Uncomment to test locally.
|
||||||
|
|
||||||
// use futures::stream::StreamExt;
|
// use futures::stream::StreamExt;
|
||||||
// use jrest::expect;
|
|
||||||
// use mistralai_client::v1::{
|
// use mistralai_client::v1::{
|
||||||
// chat_completion::{ChatParams, ChatMessage, ChatMessageRole},
|
// chat::{ChatMessage, ChatParams},
|
||||||
// client::Client,
|
// client::Client,
|
||||||
// constants::Model,
|
// constants::Model,
|
||||||
// };
|
// };
|
||||||
|
//
|
||||||
// #[tokio::test]
|
// #[tokio::test]
|
||||||
// async fn test_client_chat_stream() {
|
// async fn test_client_chat_stream() {
|
||||||
// let client = Client::new(None, None, None, None).unwrap();
|
// let client = Client::new(None, None, None, None).unwrap();
|
||||||
|
//
|
||||||
// let model = Model::OpenMistral7b;
|
// let model = Model::mistral_small_latest();
|
||||||
// let messages = vec![ChatMessage::new_user_message(
|
// let messages = vec![ChatMessage::new_user_message(
|
||||||
// "Just guess the next word: \"Eiffel ...\"?",
|
// "Just guess the next word: \"Eiffel ...\"?",
|
||||||
// )];
|
// )];
|
||||||
@@ -19,22 +21,24 @@
|
|||||||
// random_seed: Some(42),
|
// random_seed: Some(42),
|
||||||
// ..Default::default()
|
// ..Default::default()
|
||||||
// };
|
// };
|
||||||
|
//
|
||||||
// let stream_result = client.chat_stream(model, messages, Some(options)).await;
|
// let stream = client
|
||||||
// let mut stream = stream_result.expect("Failed to create stream.");
|
// .chat_stream(model, messages, Some(options))
|
||||||
// while let Some(maybe_chunk_result) = stream.next().await {
|
// .await
|
||||||
// match maybe_chunk_result {
|
// .expect("Failed to create stream.");
|
||||||
// Some(Ok(chunk)) => {
|
//
|
||||||
// if chunk.choices[0].delta.role == Some(ChatMessageRole::Assistant)
|
// stream
|
||||||
// || chunk.choices[0].finish_reason == Some("stop".to_string())
|
// .for_each(|chunk_result| async {
|
||||||
// {
|
// match chunk_result {
|
||||||
// expect!(chunk.choices[0].delta.content.len()).to_be(0);
|
// Ok(chunks) => {
|
||||||
// } else {
|
// for chunk in &chunks {
|
||||||
// expect!(chunk.choices[0].delta.content.len()).to_be_greater_than(0);
|
// if let Some(content) = &chunk.choices[0].delta.content {
|
||||||
|
// print!("{}", content);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
// }
|
// }
|
||||||
|
// Err(error) => eprintln!("Error: {:?}", error),
|
||||||
// }
|
// }
|
||||||
// Some(Err(error)) => eprintln!("Error processing chunk: {:?}", error),
|
// })
|
||||||
// None => (),
|
// .await;
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
// }
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use mistralai_client::v1::{
|
|||||||
chat::{ChatMessage, ChatMessageRole, ChatParams, ChatResponseChoiceFinishReason},
|
chat::{ChatMessage, ChatMessageRole, ChatParams, ChatResponseChoiceFinishReason},
|
||||||
client::Client,
|
client::Client,
|
||||||
constants::Model,
|
constants::Model,
|
||||||
tool::{Tool, ToolChoice, ToolFunctionParameter, ToolFunctionParameterType},
|
tool::{Tool, ToolChoice},
|
||||||
};
|
};
|
||||||
|
|
||||||
mod setup;
|
mod setup;
|
||||||
@@ -14,19 +14,18 @@ fn test_client_chat() {
|
|||||||
|
|
||||||
let client = Client::new(None, None, None, None).unwrap();
|
let client = Client::new(None, None, None, None).unwrap();
|
||||||
|
|
||||||
let model = Model::OpenMistral7b;
|
let model = Model::mistral_small_latest();
|
||||||
let messages = vec![ChatMessage::new_user_message(
|
let messages = vec![ChatMessage::new_user_message(
|
||||||
"Guess the next word: \"Eiffel ...\"?",
|
"Guess the next word: \"Eiffel ...\"?",
|
||||||
)];
|
)];
|
||||||
let options = ChatParams {
|
let options = ChatParams {
|
||||||
temperature: 0.0,
|
temperature: Some(0.0),
|
||||||
random_seed: Some(42),
|
random_seed: Some(42),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let response = client.chat(model, messages, Some(options)).unwrap();
|
let response = client.chat(model, messages, Some(options)).unwrap();
|
||||||
|
|
||||||
expect!(response.model).to_be(Model::OpenMistral7b);
|
|
||||||
expect!(response.object).to_be("chat.completion".to_string());
|
expect!(response.object).to_be("chat.completion".to_string());
|
||||||
expect!(response.choices.len()).to_be(1);
|
expect!(response.choices.len()).to_be(1);
|
||||||
expect!(response.choices[0].index).to_be(0);
|
expect!(response.choices[0].index).to_be(0);
|
||||||
@@ -50,21 +49,26 @@ fn test_client_chat_with_function_calling() {
|
|||||||
let tools = vec![Tool::new(
|
let tools = vec![Tool::new(
|
||||||
"get_city_temperature".to_string(),
|
"get_city_temperature".to_string(),
|
||||||
"Get the current temperature in a city.".to_string(),
|
"Get the current temperature in a city.".to_string(),
|
||||||
vec![ToolFunctionParameter::new(
|
serde_json::json!({
|
||||||
"city".to_string(),
|
"type": "object",
|
||||||
"The name of the city.".to_string(),
|
"properties": {
|
||||||
ToolFunctionParameterType::String,
|
"city": {
|
||||||
)],
|
"type": "string",
|
||||||
|
"description": "The name of the city."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["city"]
|
||||||
|
}),
|
||||||
)];
|
)];
|
||||||
|
|
||||||
let client = Client::new(None, None, None, None).unwrap();
|
let client = Client::new(None, None, None, None).unwrap();
|
||||||
|
|
||||||
let model = Model::MistralSmallLatest;
|
let model = Model::mistral_small_latest();
|
||||||
let messages = vec![ChatMessage::new_user_message(
|
let messages = vec![ChatMessage::new_user_message(
|
||||||
"What's the current temperature in Paris?",
|
"What's the current temperature in Paris?",
|
||||||
)];
|
)];
|
||||||
let options = ChatParams {
|
let options = ChatParams {
|
||||||
temperature: 0.0,
|
temperature: Some(0.0),
|
||||||
random_seed: Some(42),
|
random_seed: Some(42),
|
||||||
tool_choice: Some(ToolChoice::Auto),
|
tool_choice: Some(ToolChoice::Auto),
|
||||||
tools: Some(tools),
|
tools: Some(tools),
|
||||||
@@ -73,12 +77,10 @@ fn test_client_chat_with_function_calling() {
|
|||||||
|
|
||||||
let response = client.chat(model, messages, Some(options)).unwrap();
|
let response = client.chat(model, messages, Some(options)).unwrap();
|
||||||
|
|
||||||
expect!(response.model).to_be(Model::MistralSmallLatest);
|
|
||||||
expect!(response.object).to_be("chat.completion".to_string());
|
expect!(response.object).to_be("chat.completion".to_string());
|
||||||
expect!(response.choices.len()).to_be(1);
|
expect!(response.choices.len()).to_be(1);
|
||||||
expect!(response.choices[0].index).to_be(0);
|
expect!(response.choices[0].index).to_be(0);
|
||||||
expect!(response.choices[0].message.role.clone()).to_be(ChatMessageRole::Assistant);
|
expect!(response.choices[0].message.role.clone()).to_be(ChatMessageRole::Assistant);
|
||||||
expect!(response.choices[0].message.content.clone()).to_be("".to_string());
|
|
||||||
expect!(response.choices[0].finish_reason.clone())
|
expect!(response.choices[0].finish_reason.clone())
|
||||||
.to_be(ChatResponseChoiceFinishReason::ToolCalls);
|
.to_be(ChatResponseChoiceFinishReason::ToolCalls);
|
||||||
expect!(response.usage.prompt_tokens).to_be_greater_than(0);
|
expect!(response.usage.prompt_tokens).to_be_greater_than(0);
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use jrest::expect;
|
use jrest::expect;
|
||||||
use mistralai_client::v1::{client::Client, constants::EmbedModel};
|
use mistralai_client::v1::{client::Client, constants::Model};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_client_embeddings_async() {
|
async fn test_client_embeddings_async() {
|
||||||
let client: Client = Client::new(None, None, None, None).unwrap();
|
let client: Client = Client::new(None, None, None, None).unwrap();
|
||||||
|
|
||||||
let model = EmbedModel::MistralEmbed;
|
let model = Model::mistral_embed();
|
||||||
let input = vec!["Embed this sentence.", "As well as this one."]
|
let input = vec!["Embed this sentence.", "As well as this one."]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| s.to_string())
|
.map(|s| s.to_string())
|
||||||
@@ -17,7 +17,6 @@ async fn test_client_embeddings_async() {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
expect!(response.model).to_be(EmbedModel::MistralEmbed);
|
|
||||||
expect!(response.object).to_be("list".to_string());
|
expect!(response.object).to_be("list".to_string());
|
||||||
expect!(response.data.len()).to_be(2);
|
expect!(response.data.len()).to_be(2);
|
||||||
expect!(response.data[0].index).to_be(0);
|
expect!(response.data[0].index).to_be(0);
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use jrest::expect;
|
use jrest::expect;
|
||||||
use mistralai_client::v1::{client::Client, constants::EmbedModel};
|
use mistralai_client::v1::{client::Client, constants::Model};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_client_embeddings() {
|
fn test_client_embeddings() {
|
||||||
let client: Client = Client::new(None, None, None, None).unwrap();
|
let client: Client = Client::new(None, None, None, None).unwrap();
|
||||||
|
|
||||||
let model = EmbedModel::MistralEmbed;
|
let model = Model::mistral_embed();
|
||||||
let input = vec!["Embed this sentence.", "As well as this one."]
|
let input = vec!["Embed this sentence.", "As well as this one."]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| s.to_string())
|
.map(|s| s.to_string())
|
||||||
@@ -14,7 +14,6 @@ fn test_client_embeddings() {
|
|||||||
|
|
||||||
let response = client.embeddings(model, input, options).unwrap();
|
let response = client.embeddings(model, input, options).unwrap();
|
||||||
|
|
||||||
expect!(response.model).to_be(EmbedModel::MistralEmbed);
|
|
||||||
expect!(response.object).to_be("list".to_string());
|
expect!(response.object).to_be("list".to_string());
|
||||||
expect!(response.data.len()).to_be(2);
|
expect!(response.data.len()).to_be(2);
|
||||||
expect!(response.data[0].index).to_be(0);
|
expect!(response.data[0].index).to_be(0);
|
||||||
|
|||||||
@@ -6,26 +6,19 @@ use mistralai_client::v1::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_model_constant() {
|
fn test_model_constants() {
|
||||||
let models = vec![
|
let models = vec![
|
||||||
Model::OpenMistral7b,
|
Model::mistral_small_latest(),
|
||||||
Model::OpenMixtral8x7b,
|
Model::mistral_large_latest(),
|
||||||
Model::OpenMixtral8x22b,
|
Model::open_mistral_nemo(),
|
||||||
Model::OpenMistralNemo,
|
Model::codestral_latest(),
|
||||||
Model::MistralTiny,
|
|
||||||
Model::MistralSmallLatest,
|
|
||||||
Model::MistralMediumLatest,
|
|
||||||
Model::MistralLargeLatest,
|
|
||||||
Model::MistralLarge,
|
|
||||||
Model::CodestralLatest,
|
|
||||||
Model::CodestralMamba,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
let client = Client::new(None, None, None, None).unwrap();
|
let client = Client::new(None, None, None, None).unwrap();
|
||||||
|
|
||||||
let messages = vec![ChatMessage::new_user_message("A number between 0 and 100?")];
|
let messages = vec![ChatMessage::new_user_message("A number between 0 and 100?")];
|
||||||
let options = ChatParams {
|
let options = ChatParams {
|
||||||
temperature: 0.0,
|
temperature: Some(0.0),
|
||||||
random_seed: Some(42),
|
random_seed: Some(42),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user