pub mod api; pub mod appstate; pub mod components; #[cfg(test)] mod tests { use crate::{ api::openai::OpenAI, appstate::{Chat, Message, MessageAuthor}, }; use futures_util::{pin_mut, stream::StreamExt}; #[tokio::test] async fn chat_completions_streamed() { let chat = Chat::new( None, None, vec![Message { author: MessageAuthor::User, thought_process: String::default(), content: String::from("Hello! How are you?"), }], ); let openai = OpenAI::new("http://localhost:11343/v1", ""); let stream = openai .chat_completions_streamed(chat.clone()) .await .unwrap(); pin_mut!(stream); let mut reasoning_string = String::new(); let mut content_string = String::new(); while let Some(item) = stream.next().await { let choice = item.choices.first().unwrap(); if let Some(val) = &choice.delta.reasoning_content { reasoning_string.push_str(val); } if let Some(val) = &choice.delta.content { content_string.push_str(val); } print!("\x1b[2J\x1b[H"); println!("\x1b[2m{reasoning_string}\x1b[0m\n\x1b[1m{content_string}\x1b[0m"); } println!("\n"); assert_eq!(4, 4); // Dont question it. lmao. Maybe there is a better way } }