Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions crates/chatbot/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rand::{rngs::SmallRng, Rng, SeedableRng};
use std::{cell::RefCell, time::Duration};
use std::{cell::RefCell, path::PathBuf, time::Duration};

thread_local! {
static RNG: RefCell<SmallRng> = RefCell::new(SmallRng::from_entropy());
Expand Down Expand Up @@ -33,17 +33,26 @@ impl Chatbot {
}
}

pub fn retrieval_documents(&self, _messages: &[String]) -> Vec<PathBuf> {
vec![
PathBuf::from("data/doc1.txt"),
PathBuf::from("data/doc2.txt"),
]
}

/// Generates a list of possible responses given the current chat.
///
/// Warning: may take a few seconds!
pub async fn query_chat(&mut self, messages: &[String]) -> Vec<String> {
pub async fn query_chat(&mut self, messages: &[String], docs: &[String]) -> Vec<String> {
std::thread::sleep(Duration::from_secs(2));
let most_recent = messages.last().unwrap();
let emoji = &self.emojis[self.emoji_counter];
self.emoji_counter = (self.emoji_counter + 1) % self.emojis.len();
vec![
format!("\"{most_recent}\"? And how does that make you feel? {emoji}",),
format!("\"{most_recent}\"! Interesting! Go on... {emoji}"),
format!("Have you considered: {}", docs.first().unwrap()),
format!("I might recommend: {}", docs.last().unwrap()),
]
}
}
1 change: 1 addition & 0 deletions data/doc1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello world!
1 change: 1 addition & 0 deletions data/doc2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Lorem ipsum dolor sit amet.
Loading