deep_research and swear_cleanup were sharing one Cargo.toml, so every build compiled clap/indicatif/scraper/chrono (only needed by deep_research) even when just building swear_cleanup for its own course work, and vice versa. Moves each into its own workspace member crate (deep_research/, swear_cleanup/) with an independent Cargo.toml declaring only the deps it actually uses; common deps/versions are pinned once via [workspace.dependencies] so the two don't drift. Verified `cargo build -p swear_cleanup` alone no longer pulls in clap/indicatif/scraper/chrono (schemars still compiles for it, but that's a direct transitive dependency of rig itself, not something this split can avoid). Also verified the relocated deep_research binary still runs end-to-end against live Ollama with correct footnote citations and sources. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
68 lines
2.1 KiB
Rust
68 lines
2.1 KiB
Rust
use std::sync::LazyLock;
|
|
use std::time::Duration;
|
|
use serde::Deserialize;
|
|
use tokio::process::Command;
|
|
use tokio::time::sleep;
|
|
|
|
#[derive(Deserialize)]
|
|
struct ServerConfig {
|
|
llama_server: LlamaServerConfig,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
struct LlamaServerConfig {
|
|
binary: String,
|
|
model_path: String,
|
|
host: String,
|
|
port: u16,
|
|
context_size: u32,
|
|
}
|
|
|
|
static SERVER_CONFIG: LazyLock<ServerConfig> = LazyLock::new(|| {
|
|
toml::from_str(include_str!("server.toml")).expect("Could not parse server.toml")
|
|
});
|
|
|
|
static HTTP_CLIENT: LazyLock<reqwest::Client> = LazyLock::new(reqwest::Client::new);
|
|
|
|
pub(crate) fn url() -> String {
|
|
format!("http://{}:{}", SERVER_CONFIG.llama_server.host, SERVER_CONFIG.llama_server.port)
|
|
}
|
|
|
|
async fn is_healthy(health_url: &str) -> bool {
|
|
HTTP_CLIENT.get(health_url).send().await.is_ok_and(|r| r.status().is_success())
|
|
}
|
|
|
|
/// Checks whether llama-server is already serving on the configured host/port,
|
|
/// and if not, spawns it from the configured binary/model path and waits for
|
|
/// it to report healthy before returning.
|
|
pub(crate) async fn ensure_running() -> anyhow::Result<()> {
|
|
let base_url = url();
|
|
let health_url = format!("{base_url}/health");
|
|
|
|
if is_healthy(&health_url).await {
|
|
return Ok(());
|
|
}
|
|
|
|
tracing::info!(url = %base_url, "llama-server not running, starting it");
|
|
|
|
Command::new(&SERVER_CONFIG.llama_server.binary)
|
|
.args([
|
|
"-m", &SERVER_CONFIG.llama_server.model_path,
|
|
"--jinja",
|
|
"-c", &SERVER_CONFIG.llama_server.context_size.to_string(),
|
|
"--host", &SERVER_CONFIG.llama_server.host,
|
|
"--port", &SERVER_CONFIG.llama_server.port.to_string(),
|
|
])
|
|
.spawn()
|
|
.map_err(|e| anyhow::anyhow!("failed to spawn llama-server at {}: {e}", SERVER_CONFIG.llama_server.binary))?;
|
|
|
|
for _ in 0..60 {
|
|
if is_healthy(&health_url).await {
|
|
tracing::info!("llama-server is up");
|
|
return Ok(());
|
|
}
|
|
sleep(Duration::from_secs(1)).await;
|
|
}
|
|
|
|
anyhow::bail!("llama-server did not become healthy within 60s")
|
|
}
|