Skip to content

Commit

Permalink
Make chatbot functions take a variable length of time
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Sep 4, 2024
1 parent 57a9e35 commit 58f4d81
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crates/chatbot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ pub fn seed_rng(seed: u64) {
///
/// Warning: may take a few seconds!
pub async fn gen_random_number() -> usize {
tokio::time::sleep(Duration::from_secs(2)).await;
let sleep_time = RNG.with(|rng| rng.borrow_mut().gen_range::<f32, _>(0. ..5.));
tokio::time::sleep(Duration::from_secs_f32(sleep_time)).await;
RNG.with(|rng| rng.borrow_mut().gen())
}

Expand Down Expand Up @@ -44,8 +45,9 @@ impl Chatbot {
///
/// Warning: may take a few seconds!
pub async fn query_chat(&mut self, messages: &[String], docs: &[String]) -> Vec<String> {
tokio::time::sleep(Duration::from_secs(2)).await;
let most_recent = messages.last().unwrap();
let sleep_time = RNG.with(|rng| rng.borrow_mut().gen_range::<f32, _>(0. ..5.));
tokio::time::sleep(Duration::from_secs_f32(sleep_time)).await;
let emoji = &self.emojis[self.emoji_counter];
self.emoji_counter = (self.emoji_counter + 1) % self.emojis.len();
vec![
Expand Down

0 comments on commit 58f4d81

Please sign in to comment.