2024-03-03 15:20:30 +01:00
|
|
|
use jrest::expect;
|
|
|
|
|
use mistralai_client::v1::{
|
2024-03-04 08:16:06 +01:00
|
|
|
chat_completion::{ChatCompletionParams, ChatMessage, ChatMessageRole},
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[test]
|
2024-03-04 04:21:03 +01:00
|
|
|
fn test_client_chat() {
|
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 {
|
|
|
|
|
role: ChatMessageRole::user,
|
2024-03-03 15:20:30 +01:00
|
|
|
content: "Just guess the next word: \"Eiffel ...\"?".to_string(),
|
|
|
|
|
}];
|
2024-03-03 19:10:25 +01:00
|
|
|
let options = ChatCompletionParams {
|
2024-03-03 15:20:30 +01:00
|
|
|
temperature: Some(0.0),
|
|
|
|
|
random_seed: Some(42),
|
|
|
|
|
..Default::default()
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-03 19:10:25 +01:00
|
|
|
let response = client.chat(model, messages, Some(options)).unwrap();
|
2024-03-03 15:20:30 +01:00
|
|
|
|
2024-03-04 03:14:23 +01:00
|
|
|
expect!(response.model).to_be(Model::OpenMistral7b);
|
2024-03-03 19:10:25 +01:00
|
|
|
expect!(response.object).to_be("chat.completion".to_string());
|
|
|
|
|
expect!(response.choices.len()).to_be(1);
|
|
|
|
|
expect!(response.choices[0].index).to_be(0);
|
2024-03-04 08:16:06 +01:00
|
|
|
expect!(response.choices[0].message.role.clone()).to_be(ChatMessageRole::assistant);
|
2024-03-03 19:10:25 +01:00
|
|
|
expect!(response.choices[0].message.content.clone())
|
|
|
|
|
.to_be("Tower. The Eiffel Tower is a famous landmark in Paris, France.".to_string());
|
|
|
|
|
expect!(response.usage.prompt_tokens).to_be_greater_than(0);
|
|
|
|
|
expect!(response.usage.completion_tokens).to_be_greater_than(0);
|
2024-03-04 03:14:23 +01:00
|
|
|
expect!(response.usage.total_tokens).to_be_greater_than(0);
|
2024-03-03 15:20:30 +01:00
|
|
|
}
|