Fixed multiline handling, and did a cargo fmt.
This commit is contained in:
18
src/chat.rs
18
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<Chat> {
|
||||
pub async fn new(settings: &MainConfig, handle: &LLMHandle) -> Result<Chat> {
|
||||
// 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,13 +78,20 @@ 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.");
|
||||
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, msg)
|
||||
.send_privmsg(&channel, line)
|
||||
.wrap_err("Couldn't send response to channel.")?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use color_eyre::Result;
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
use std::path::{
|
||||
Path,
|
||||
PathBuf,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user