From b4dd7d51ee2e30c4445e628056b5cbf93d9d8cbb Mon Sep 17 00:00:00 2001 From: Oxbian Date: Sun, 9 Mar 2025 16:44:26 -0400 Subject: feat: log + error handling --- src/app/llm.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/app/llm.rs') diff --git a/src/app/llm.rs b/src/app/llm.rs index a172855..9c6d222 100644 --- a/src/app/llm.rs +++ b/src/app/llm.rs @@ -15,11 +15,9 @@ pub struct LLM { } impl LLM { - pub fn new(config_file: String) -> Result> { - let contents = fs::read_to_string(config_file)?; - let llm: LLM = serde_json::from_str(&contents)?; - - Ok(llm) + pub fn new(config_file: String) -> LLM { + let contents = fs::read_to_string(config_file).unwrap(); + serde_json::from_str(&contents).unwrap() } pub async fn ask(&self, messages: &Vec) -> Result> { @@ -116,9 +114,9 @@ impl Message { Message { role, content } } - pub fn save_message(&self, conv_id: String) { + pub fn save_message(&self, conv_id: String) -> Result<(), Box> { // Create conv directory if doesn't exist - create_dir_all("conv").unwrap(); + create_dir_all("conv")?; // Save message let mut file = OpenOptions::new() @@ -128,7 +126,9 @@ impl Message { .open("conv/".to_string() + &conv_id) .unwrap(); - writeln!(file, "{}", serde_json::to_string(self).unwrap()).unwrap(); + writeln!(file, "{}", serde_json::to_string(self)?)?; + + Ok(()) } } -- cgit v1.2.3