diff options
author | Oxbian <oxbian@mailbox.org> | 2025-03-09 16:44:26 -0400 |
---|---|---|
committer | Oxbian <oxbian@mailbox.org> | 2025-03-09 16:44:26 -0400 |
commit | b4dd7d51ee2e30c4445e628056b5cbf93d9d8cbb (patch) | |
tree | 1262872c8bbec3fec90a19bf2d59ece652eb0bed /src/app/llm.rs | |
parent | 43f26405e818aec791b28c50373843851fe1320e (diff) | |
download | NAI-b4dd7d51ee2e30c4445e628056b5cbf93d9d8cbb.tar.gz NAI-b4dd7d51ee2e30c4445e628056b5cbf93d9d8cbb.zip |
feat: log + error handling
Diffstat (limited to 'src/app/llm.rs')
-rw-r--r-- | src/app/llm.rs | 16 |
1 files changed, 8 insertions, 8 deletions
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<LLM, Box<dyn std::error::Error>> { - 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<Message>) -> Result<String, Box<dyn std::error::Error>> { @@ -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<dyn std::error::Error>> { // 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(()) } } |