use std::{
fs,
io::{self, Write},
};
use futures::StreamExt;
use mirror::{
builder::{LLMBackend, LLMBuilder}, chat::{ChatMessage, ImageMime}, };
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let llm = LLMBuilder::new()
.backend(LLMBackend::Ollama) .model("qwen2.5vl:7b") .max_tokens(8512) .temperature(0.7) .stream(false) .system("You are a helpful AI assistant specialized in programming.")
.build()
.expect("Failed to build LLM (Ollama)");
let content = fs::read("./examples/image001.jpg").expect("The image001.jpg file should exist");
let messages = vec![
ChatMessage::user()
.content("Explain what you see in the image")
.build(),
ChatMessage::user().image(ImageMime::JPEG, content).build(),
];
match llm.chat_stream(&messages).await {
Ok(mut stream) => {
while let Some(delta) = stream.next().await {
print!("{}", delta.unwrap_or("".to_owned()));
io::stdout().flush().expect("failed to flush");
}
println!("") }
Err(e) => eprintln!("Chat error: {}", e),
}
Ok(())
}