Added chroot support.
This commit is contained in:
18
src/main.rs
18
src/main.rs
@@ -3,6 +3,7 @@ use color_eyre::{
|
||||
eyre::WrapErr,
|
||||
};
|
||||
use human_panic::setup_panic;
|
||||
use std::os::unix::fs;
|
||||
use tracing::{
|
||||
Level,
|
||||
info,
|
||||
@@ -10,12 +11,12 @@ use tracing::{
|
||||
use tracing_subscriber::FmtSubscriber;
|
||||
|
||||
mod chat;
|
||||
mod command;
|
||||
mod commands;
|
||||
mod qna;
|
||||
mod setup;
|
||||
|
||||
const DEFAULT_INSTRUCT: &'static str =
|
||||
"You are a shady, yet helpful IRC bot. You try to give responses that can
|
||||
const DEFAULT_INSTRUCT: &str =
|
||||
"You are a shady, yet helpful IRC bot. You try to give responses that can
|
||||
be sent in a single IRC response according to the specification.";
|
||||
|
||||
#[tokio::main]
|
||||
@@ -36,6 +37,13 @@ async fn main() -> Result<()> {
|
||||
let settings = setup::init().await.wrap_err("Failed to initialize.")?;
|
||||
let config = settings.config;
|
||||
|
||||
// chroot if applicable.
|
||||
if let Ok(chroot_path) = config.get_string("chroot-dir") {
|
||||
fs::chroot(&chroot_path)
|
||||
.wrap_err_with(|| format!("Failed setting chroot '{}'", chroot_path.to_string()))?;
|
||||
std::env::set_current_dir("/").wrap_err("Couldn't change directory after chroot.")?;
|
||||
}
|
||||
|
||||
let handle = qna::new(
|
||||
config.get_string("api-key").wrap_err("API missing.")?,
|
||||
config
|
||||
@@ -44,7 +52,9 @@ async fn main() -> Result<()> {
|
||||
config
|
||||
.get_string("model")
|
||||
.wrap_err("model string missing.")?,
|
||||
config.get_string("instruct").unwrap_or_else(|_| DEFAULT_INSTRUCT.to_string()),
|
||||
config
|
||||
.get_string("instruct")
|
||||
.unwrap_or_else(|_| DEFAULT_INSTRUCT.to_string()),
|
||||
)
|
||||
.wrap_err("Couldn't initialize LLM handle.")?;
|
||||
let mut c = chat::new(&config, &handle).await?;
|
||||
|
||||
Reference in New Issue
Block a user