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
|
// Need: owners, channels, username, nick, server, password
|
||||||
#[instrument]
|
#[instrument]
|
||||||
pub async fn new(
|
pub async fn new(settings: &MainConfig, handle: &LLMHandle) -> Result<Chat> {
|
||||||
settings: &MainConfig,
|
|
||||||
handle: &LLMHandle,
|
|
||||||
) -> Result<Chat> {
|
|
||||||
// Going to just assign and let the irc library handle errors for now, and
|
// Going to just assign and let the irc library handle errors for now, and
|
||||||
// add my own checking if necessary.
|
// add my own checking if necessary.
|
||||||
let port: u16 = settings.get("port")?;
|
let port: u16 = settings.get("port")?;
|
||||||
@@ -81,13 +78,20 @@ impl Chat {
|
|||||||
if let Command::PRIVMSG(channel, message) = message.command
|
if let Command::PRIVMSG(channel, message) = message.command
|
||||||
&& message.starts_with("!gem")
|
&& message.starts_with("!gem")
|
||||||
{
|
{
|
||||||
let msg = self.llm_handle.send_request(message).await?;
|
let msg = self.llm_handle.send_request(&message).await?;
|
||||||
event!(Level::INFO, "Message received.");
|
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
|
client
|
||||||
.send_privmsg(channel, msg)
|
.send_privmsg(&channel, line)
|
||||||
.wrap_err("Couldn't send response to channel.")?;
|
.wrap_err("Couldn't send response to channel.")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use std::{
|
use std::path::{
|
||||||
path::{Path, PathBuf},
|
Path,
|
||||||
|
PathBuf,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ async fn main() -> Result<()> {
|
|||||||
fs::chroot(&chroot_path)
|
fs::chroot(&chroot_path)
|
||||||
.wrap_err_with(|| format!("Failed setting 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.")?;
|
std::env::set_current_dir("/").wrap_err("Couldn't change directory after chroot.")?;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup root path for commands.
|
// Setup root path for commands.
|
||||||
|
|||||||
@@ -70,11 +70,6 @@ impl LLMHandle {
|
|||||||
while let Some(Ok(stream_event)) = stream.next().await {
|
while let Some(Ok(stream_event)) = stream.next().await {
|
||||||
if let ChatStreamEvent::Chunk(StreamChunk { content }) = stream_event {
|
if let ChatStreamEvent::Chunk(StreamChunk { content }) = stream_event {
|
||||||
text.push_str(&content);
|
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