2026-03-20 17:57:44 +00:00
|
|
|
// Streaming tests require a live API key and are not run in CI.
|
|
|
|
|
// Uncomment to test locally.
|
|
|
|
|
|
2024-03-09 11:28:50 +01:00
|
|
|
// use futures::stream::StreamExt;
|
|
|
|
|
// use mistralai_client::v1::{
|
2026-03-20 17:57:44 +00:00
|
|
|
// chat::{ChatMessage, ChatParams},
|
2024-03-09 11:28:50 +01:00
|
|
|
// client::Client,
|
|
|
|
|
// constants::Model,
|
|
|
|
|
// };
|
2026-03-20 17:57:44 +00:00
|
|
|
//
|
2024-03-09 11:28:50 +01:00
|
|
|
// #[tokio::test]
|
|
|
|
|
// async fn test_client_chat_stream() {
|
|
|
|
|
// let client = Client::new(None, None, None, None).unwrap();
|
2026-03-20 17:57:44 +00:00
|
|
|
//
|
|
|
|
|
// let model = Model::mistral_small_latest();
|
2024-03-09 11:28:50 +01:00
|
|
|
// let messages = vec![ChatMessage::new_user_message(
|
|
|
|
|
// "Just guess the next word: \"Eiffel ...\"?",
|
|
|
|
|
// )];
|
|
|
|
|
// let options = ChatParams {
|
|
|
|
|
// temperature: Some(0.0),
|
|
|
|
|
// random_seed: Some(42),
|
|
|
|
|
// ..Default::default()
|
|
|
|
|
// };
|
2026-03-20 17:57:44 +00:00
|
|
|
//
|
|
|
|
|
// let stream = client
|
|
|
|
|
// .chat_stream(model, messages, Some(options))
|
|
|
|
|
// .await
|
|
|
|
|
// .expect("Failed to create stream.");
|
|
|
|
|
//
|
|
|
|
|
// stream
|
|
|
|
|
// .for_each(|chunk_result| async {
|
|
|
|
|
// match chunk_result {
|
|
|
|
|
// Ok(chunks) => {
|
|
|
|
|
// for chunk in &chunks {
|
|
|
|
|
// if let Some(content) = &chunk.choices[0].delta.content {
|
|
|
|
|
// print!("{}", content);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2024-03-09 11:28:50 +01:00
|
|
|
// }
|
2026-03-20 17:57:44 +00:00
|
|
|
// Err(error) => eprintln!("Error: {:?}", error),
|
2024-03-09 11:28:50 +01:00
|
|
|
// }
|
2026-03-20 17:57:44 +00:00
|
|
|
// })
|
|
|
|
|
// .await;
|
2024-03-09 11:28:50 +01:00
|
|
|
// }
|