mirror of
https://github.com/zenlm/engine.git
synced 2026-10-30 15:00:05 +00:00
* Initial * Markdown * Copy code * Add model loading sidebar * Support vision models * Tweak isq * Links go to another page * Clear when switch model * Fix html tags * Add image support! * More then one images * Fix * Improved textarea * Tab for switching between vision and text * No paged attn for now * Prettier format * Multiple models at once * Better switching, clearing ability * Mobile support * Inline markdown parser * Update examples * Typos * Support specifying isq * Fix mobile * Fixes * Fix button on mobile * Image height is capped * Thumbnail * Fix rotating kv cache edge case * Add drag and drop for images * Small things * Sidebar is frozen now * Better listner * Add readme * Tweak readme
53 lines
1.4 KiB
Rust
53 lines
1.4 KiB
Rust
use anyhow::Result;
|
|
use clap::Parser;
|
|
use mistralrs::{IsqType, TextMessageRole, VisionMessages, VisionModelBuilder};
|
|
use mistralrs_core::initialize_logging;
|
|
use tokio::task;
|
|
|
|
#[derive(Parser)]
|
|
#[command(version, about, long_about = None)]
|
|
struct Args {
|
|
#[arg(short, long, default_value = "Qwen/Qwen2.5-VL-3B-Instruct")]
|
|
model_id: String,
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
initialize_logging();
|
|
let args = Args::parse();
|
|
|
|
let bytes = task::spawn_blocking(|| {
|
|
match reqwest::blocking::get(
|
|
"https://cdn.britannica.com/45/5645-050-B9EC0205/head-treasure-flower-disk-flowers-inflorescence-ray.jpg",
|
|
) {
|
|
Ok(http_resp) => Ok(http_resp.bytes()?.to_vec()),
|
|
Err(e) => anyhow::bail!(e),
|
|
}
|
|
}).await??;
|
|
|
|
let image = image::load_from_memory(&bytes)?;
|
|
|
|
let model = VisionModelBuilder::new(args.model_id)
|
|
.with_isq(IsqType::Q8_0)
|
|
.with_logging()
|
|
.build()
|
|
.await?;
|
|
|
|
let messages = VisionMessages::new().add_image_message(
|
|
TextMessageRole::User,
|
|
"What is depicted here?",
|
|
vec![image],
|
|
&model,
|
|
)?;
|
|
|
|
let response = model.send_chat_request(messages).await?;
|
|
|
|
println!("{}", response.choices[0].message.content.as_ref().unwrap());
|
|
dbg!(
|
|
response.usage.avg_prompt_tok_per_sec,
|
|
response.usage.avg_compl_tok_per_sec
|
|
);
|
|
|
|
Ok(())
|
|
}
|