From 95583184e7e9725f1dcc906b0a1655780c97ea61 Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Thu, 22 Aug 2024 16:18:42 -0700 Subject: [PATCH] Make chatbot functions take a variable length of time --- crates/chatbot/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/chatbot/src/lib.rs b/crates/chatbot/src/lib.rs index 7ca535a..13c321f 100644 --- a/crates/chatbot/src/lib.rs +++ b/crates/chatbot/src/lib.rs @@ -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::(0. ..5.)); + tokio::time::sleep(Duration::from_secs_f32(sleep_time)).await; RNG.with(|rng| rng.borrow_mut().gen()) } @@ -44,8 +45,9 @@ impl Chatbot { /// /// Warning: may take a few seconds! pub async fn query_chat(&mut self, messages: &[String], docs: &[String]) -> Vec { - 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::(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![