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/init.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/app/init.rs') diff --git a/src/app/init.rs b/src/app/init.rs index f1f917a..dd8d3b7 100644 --- a/src/app/init.rs +++ b/src/app/init.rs @@ -12,7 +12,8 @@ pub struct App { impl App { pub fn new() -> App { - let chat_llm: LLM = LLM::new("config/chat-LLM.json".to_string()).unwrap(); + let chat_llm: LLM = LLM::new("config/chat-LLM.json".to_string()); + App { messages: vec![Message::new( MessageType::SYSTEM, @@ -20,13 +21,16 @@ impl App { )], conv_id: Uuid::new_v4(), chat_llm, - resume_llm: LLM::new("config/resume-LLM.json".to_string()).unwrap(), + resume_llm: LLM::new("config/resume-LLM.json".to_string()), } } fn append_message(&mut self, msg: String, role: MessageType) { let message = Message::new(role, msg); - message.save_message(self.conv_id.to_string()); + + let err = message.save_message(self.conv_id.to_string()); + warn(err.is_err().to_string()); + self.messages.push(message); } @@ -38,9 +42,13 @@ impl App { self.chat_llm.ask_format(&self.messages).await }); - let categorie = result.unwrap()[0]["function"]["arguments"]["category"].clone(); - - self.ask(categorie.to_string().as_str()); + match result { + Ok(msg) => { + let categorie = msg[0]["function"]["arguments"]["category"].clone(); + self.ask(categorie.to_string().as_str()); + }, + Err(e) => self.append_message(e.to_string(), MessageType::ASSISTANT), + } } fn ask(&mut self, mode: &str) { -- cgit v1.2.3