Files
robotnik/src/main.rs

75 lines
2.0 KiB
Rust
Raw Normal View History

2025-08-05 01:47:11 -05:00
use color_eyre::{
Result,
eyre::WrapErr,
};
use human_panic::setup_panic;
2025-08-11 19:31:38 -05:00
use std::os::unix::fs;
2025-08-05 01:47:11 -05:00
use tracing::{
Level,
info,
};
use tracing_subscriber::FmtSubscriber;
mod chat;
2025-08-11 19:31:38 -05:00
mod commands;
2025-08-05 01:47:11 -05:00
mod qna;
mod setup;
2025-08-11 19:31:38 -05:00
const DEFAULT_INSTRUCT: &str =
"You are a shady, yet helpful IRC bot. You try to give responses that can
2025-08-05 02:14:30 -05:00
be sent in a single IRC response according to the specification.";
2025-08-05 01:47:11 -05:00
#[tokio::main]
async fn main() -> Result<()> {
// Some error sprucing.
better_panic::install();
setup_panic!();
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::TRACE)
.finish();
tracing::subscriber::set_global_default(subscriber)
.wrap_err("Failed to setup trace logging.")?;
info!("Starting");
let settings = setup::init().await.wrap_err("Failed to initialize.")?;
let config = settings.config;
2025-08-11 19:31:38 -05:00
// chroot if applicable.
if let Ok(chroot_path) = config.get_string("chroot-dir") {
2025-08-11 23:37:18 -05:00
info!("Attempting to chroot to {}", chroot_path);
2025-08-11 19:31:38 -05:00
fs::chroot(&chroot_path)
2025-08-11 23:37:18 -05:00
.wrap_err_with(|| format!("Failed setting chroot '{}'", chroot_path))?;
2025-08-11 19:31:38 -05:00
std::env::set_current_dir("/").wrap_err("Couldn't change directory after chroot.")?;
}
2025-08-11 23:37:18 -05:00
// Setup root path for commands.
let cmd_root = if let Ok(command_path) = config.get_string("command-path") {
Some(commands::Root::new(command_path))
} else {
None
};
let handle = qna::LLMHandle::new(
2025-08-05 01:47:11 -05:00
config.get_string("api-key").wrap_err("API missing.")?,
config
.get_string("base-url")
.wrap_err("base-url missing.")?,
2025-08-11 23:37:18 -05:00
cmd_root,
2025-08-05 01:47:11 -05:00
config
.get_string("model")
.wrap_err("model string missing.")?,
2025-08-11 19:31:38 -05:00
config
.get_string("instruct")
.unwrap_or_else(|_| DEFAULT_INSTRUCT.to_string()),
2025-08-05 01:47:11 -05:00
)
.wrap_err("Couldn't initialize LLM handle.")?;
let mut c = chat::new(&config, &handle).await?;
c.run().await.unwrap();
Ok(())
}