Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make chatbot functions take a variable length of time #36

Open
wants to merge 1 commit into
base: 06-select-b
Choose a base branch
from
Open
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
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
Loading