From 9719d9203ca5a4c828399530d2e5bacd04a87209 Mon Sep 17 00:00:00 2001 From: Micheal Smith Date: Fri, 31 Oct 2025 05:34:34 -0500 Subject: [PATCH] Fixed multiline handling, and did a cargo fmt. --- src/chat.rs | 22 +++++++++++++--------- src/commands.rs | 5 +++-- src/main.rs | 1 - src/qna.rs | 5 ----- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index fb7f5f7..20b154f 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -31,10 +31,7 @@ pub struct Chat { // Need: owners, channels, username, nick, server, password #[instrument] -pub async fn new( - settings: &MainConfig, - handle: &LLMHandle, -) -> Result { +pub async fn new(settings: &MainConfig, handle: &LLMHandle) -> Result { // Going to just assign and let the irc library handle errors for now, and // add my own checking if necessary. let port: u16 = settings.get("port")?; @@ -81,11 +78,18 @@ impl Chat { if let Command::PRIVMSG(channel, message) = message.command && message.starts_with("!gem") { - let msg = self.llm_handle.send_request(message).await?; - event!(Level::INFO, "Message received."); - client - .send_privmsg(channel, msg) - .wrap_err("Couldn't send response to channel.")?; + let msg = self.llm_handle.send_request(&message).await?; + event!(Level::INFO, "Asked: {}", message); + event!(Level::INFO, "Answered: {}", msg); + + // Send responses as one PRIVMSG per line. + let mut lines = msg.lines(); + + while let Some(line) = lines.next() { + client + .send_privmsg(&channel, line) + .wrap_err("Couldn't send response to channel.")?; + } } } diff --git a/src/commands.rs b/src/commands.rs index 32282a9..1c51c7b 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,6 +1,7 @@ use color_eyre::Result; -use std::{ - path::{Path, PathBuf}, +use std::path::{ + Path, + PathBuf, }; #[derive(Clone, Debug)] diff --git a/src/main.rs b/src/main.rs index ffda2ba..7b86a51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,7 +43,6 @@ async fn main() -> Result<()> { fs::chroot(&chroot_path) .wrap_err_with(|| format!("Failed setting chroot '{}'", chroot_path))?; std::env::set_current_dir("/").wrap_err("Couldn't change directory after chroot.")?; - } // Setup root path for commands. diff --git a/src/qna.rs b/src/qna.rs index 454512f..696af22 100644 --- a/src/qna.rs +++ b/src/qna.rs @@ -70,11 +70,6 @@ impl LLMHandle { while let Some(Ok(stream_event)) = stream.next().await { if let ChatStreamEvent::Chunk(StreamChunk { content }) = stream_event { text.push_str(&content); - } else if let ChatStreamEvent::End(end) = stream_event { - let texts = end.captured_texts().unwrap(); - for text in texts.into_iter() { - info!("An answer: {}", text); - } } }