mirror of
https://github.com/hanzoai/engine.git
synced 2026-11-20 23:45:50 +00:00
Replace all remaining references to the upstream project/author/framework brands with hanzo / hanzoai across source, comments, docs, examples, and build scripts. - Project spellings mistral.rs / mistral-rs / mistralrs -> hanzo (and the hanzo-* crate/binary names in Dockerfiles, Makefile, install.ps1, .gitignore). - Author EricLBuehler / EricBuehler / EricB / Eric Buehler -> hanzoai / Hanzo AI (incl. Cargo `authors` and LICENSE copyright). - URLs: github.com/EricLBuehler/mistral.rs -> github.com/hanzoai/engine; ericlbuehler.github.io/mistral.rs -> hanzoai.github.io/engine; github.com/huggingface/candle -> github.com/hanzoai/ml; docs.rs/candle-* -> docs.rs/hanzo-ml; ghcr.io image -> ghcr.io/hanzoai/engine. - Env var prefix MISTRALRS_ -> HANZO_ (producers and consumers kept in sync, incl. the build-script-injected HANZO_GIT_REVISION). - ROCm static lib libmistralrsrocm.a / mistralrsrocm -> libhanzorocm.a / hanzorocm. - localStorage keys mistralrs_settings -> hanzo_settings. Deliberately preserved: real model architectures (struct Mistral, models/mistral.rs file, Mixtral/Llama/Gemma/Qwen/Phi), real model-org HF repo-ids (mistralai/, meta-llama/, google/, Qwen/, microsoft/), the `use hanzo_ml as candle` code aliases and `candle::` identifiers, and the upstream-author HF data repo-id suffix in "hanzoai/mistralrs_tests". Both `cargo check` and `cargo check --features vulkan` pass with 0 errors. Co-authored-by: Hanzo Dev <[email protected]>
71 lines
2.0 KiB
Rust
71 lines
2.0 KiB
Rust
//! Log model output to a file using the tracing framework.
|
|
//!
|
|
//! Run with: `cargo run --release --example file_logging -p hanzo`
|
|
|
|
use anyhow::Result;
|
|
use hanzo::{IsqBits, ModelBuilder, TextMessageRole, TextMessages};
|
|
use std::fs;
|
|
use std::fs::OpenOptions;
|
|
use tracing::info;
|
|
use tracing::level_filters::LevelFilter;
|
|
use tracing_subscriber::EnvFilter;
|
|
|
|
const LOG_FILE: &str = "custom_logging.log";
|
|
|
|
fn init_logging(log_file: &str) {
|
|
let _ = fs::remove_file(log_file);
|
|
let path = log_file.to_owned();
|
|
let writer = move || {
|
|
OpenOptions::new()
|
|
.create(true)
|
|
.append(true)
|
|
.open(&path)
|
|
.expect("failed to open log file")
|
|
};
|
|
|
|
let filter = EnvFilter::builder()
|
|
.with_default_directive(LevelFilter::INFO.into())
|
|
.from_env_lossy()
|
|
.add_directive("hanzo_engine=debug".parse().unwrap());
|
|
|
|
tracing_subscriber::fmt()
|
|
.with_env_filter(filter)
|
|
.with_target(false)
|
|
.with_writer(writer)
|
|
.try_init()
|
|
.expect("subscriber installed only once");
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
init_logging(LOG_FILE);
|
|
info!("Custom subscriber installed; writing logs to {LOG_FILE}");
|
|
|
|
let model = ModelBuilder::new("Qwen/Qwen3-VL-4B-Instruct")
|
|
.with_auto_isq(IsqBits::Four)
|
|
// NOTE: deliberately skip `.with_logging()` so only our subscriber runs.
|
|
.build()
|
|
.await?;
|
|
|
|
let messages = TextMessages::new()
|
|
.add_message(
|
|
TextMessageRole::System,
|
|
"You describe locations succinctly.",
|
|
)
|
|
.add_message(
|
|
TextMessageRole::User,
|
|
"Give me two sentences about the Mount Washington summit weather.",
|
|
);
|
|
|
|
let response = model.send_chat_request(messages).await?;
|
|
let answer = response.choices[0].message.content.as_ref().unwrap();
|
|
println!("Model response:\n{answer}");
|
|
|
|
info!("Completed inference run.");
|
|
|
|
let captured_logs = fs::read_to_string(LOG_FILE)?;
|
|
println!("\n--- Captured hanzo logs ---\n{captured_logs}");
|
|
|
|
Ok(())
|
|
}
|