From ea5fe19ad751fd6fa686e502a5cf7f26a78668e9 Mon Sep 17 00:00:00 2001 From: Oxbian Date: Sun, 18 May 2025 12:19:33 -0400 Subject: feat: refactor chat, resume into modules + color in UI --- src/app/modules/chat.rs | 9 +++++++++ src/app/modules/code.rs | 0 src/app/modules/resume.rs | 9 +++++++++ src/app/modules/wikipedia.rs | 6 +++--- 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 src/app/modules/chat.rs create mode 100644 src/app/modules/code.rs create mode 100644 src/app/modules/resume.rs (limited to 'src/app/modules') diff --git a/src/app/modules/chat.rs b/src/app/modules/chat.rs new file mode 100644 index 0000000..ee00c98 --- /dev/null +++ b/src/app/modules/chat.rs @@ -0,0 +1,9 @@ +use crate::app::llm::{LLM, Message, MessageType}; + +pub async fn ask_chat(mut messages: Vec) -> Result> { + let chat_llm = LLM::new("config/chat-LLM.json"); + messages.push(Message::new(MessageType::USER, chat_llm.system_prompt.to_string())); + + let result: String = chat_llm.ask(&messages).await?; + Ok(result) +} diff --git a/src/app/modules/code.rs b/src/app/modules/code.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/app/modules/resume.rs b/src/app/modules/resume.rs new file mode 100644 index 0000000..057314c --- /dev/null +++ b/src/app/modules/resume.rs @@ -0,0 +1,9 @@ +use crate::app::llm::{LLM, Message, MessageType}; + +pub async fn resume_conv(mut messages: Vec) -> Result> { + let resume_llm = LLM::new("config/resume-LLM.json"); + messages.push(Message::new(MessageType::USER, resume_llm.system_prompt.to_string())); + + let result: String = resume_llm.ask(&messages).await?; + Ok(result) +} diff --git a/src/app/modules/wikipedia.rs b/src/app/modules/wikipedia.rs index 5864df4..86177ae 100644 --- a/src/app/modules/wikipedia.rs +++ b/src/app/modules/wikipedia.rs @@ -76,7 +76,7 @@ async fn find_get_best_article(articles: Vec, user_query: &String, best_ let messages = vec![ Message::new(MessageType::SYSTEM, best_llm.system_prompt.clone()), - Message::new(MessageType::USER, format!("The user's query is: {}. Here are the headings:\n{}\n\nPlease select the most relevant heading. Output the heading **only** and nothing else.", user_query, articles_headings))]; + Message::new(MessageType::USER, format!("The user's query is: {}. Here are the headings:\n{}\n\nPlease select the most relevant heading. Output the heading only and nothing else.", user_query, articles_headings))]; let best_article = best_llm.ask(&messages).await?; // wiki query get article content & parse @@ -98,9 +98,9 @@ fn extract_text_from_tags(html: &str) -> String { // Trouver le premier groupe capturé non vide (parmi cap[1] à cap[4]) (1..=4) .filter_map(|i| cap.get(i)) - .map(|m| m.as_str()) // &str + .map(|m| m.as_str()) .flat_map(|s| s.split_whitespace()) - .collect::>() // Vec<&str> + .collect::>() }) .collect::>() // collect words .join(" "); // join with spaces -- cgit v1.2.3