Files
leleka/crates/deploy/src/plan/render.rs
T

60 lines
1.9 KiB
Rust

//! The text of a plan for `--dry-run` and `preflight`.
use super::*;
/// A human rendering of the plan, with the engine command the service will run.
pub fn render_plan(ctx: &Context, steps: &[Step]) -> String {
let mut out = String::new();
out.push_str("plan:\n");
for (index, step) in steps.iter().enumerate() {
out.push_str(&format!(
" {:>2}. [{:7}] {} - {}\n",
index + 1,
step.state.tag(),
step.title,
step.state.why()
));
if matches!(step.state, StepState::Todo(_) | StepState::Blocked(_)) {
for command in &step.commands {
out.push_str(&format!(" $ {command}\n"));
}
}
}
if let Some(config) = &ctx.config {
out.push_str(&engine_command_text(ctx, config));
}
out
}
/// The engine command line and environment of the configuration, as the service will run them.
fn engine_command_text(ctx: &Context, config: &RunConfig) -> String {
let kar = match config.profile.kar_source {
KarSource::Memfd => KarArg::Fd,
KarSource::File => KarArg::File,
KarSource::None => KarArg::None,
};
let mut out = format!(
"engine command the service runs:\n {} {}\n",
ctx.paths.bin("leleka-inference").display(),
config.engine_args(kar).join(" ")
);
out.push_str(&format!(
" (profile {}: budget {:.1} GiB, context {}, KAR {})\n",
config.profile.name,
config.profile.gpu_budget_bytes as f64 / (1u64 << 30) as f64,
config.profile.context_tokens,
config.profile.kar_source.as_str()
));
let env = config.engine_environment();
if !env.is_empty() {
out.push_str(&format!(
" engine environment: {}\n",
env.iter()
.map(|(k, v)| format!("{k}={v}"))
.collect::<Vec<_>>()
.join(" ")
));
}
out
}