File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ [package ]
2+ name = " chatbot"
3+ version = " 0.1.0"
4+ edition = " 2021"
5+
6+ [dependencies ]
7+ rand = { version = " 0.8.5" , features = [" small_rng" ] }
8+ tokio = { workspace = true , features = [" time" ] }
Original file line number Diff line number Diff line change 1+ use rand:: { rngs:: SmallRng , Rng , SeedableRng } ;
2+ use std:: { cell:: RefCell , time:: Duration } ;
3+
4+ thread_local ! {
5+ static RNG : RefCell <SmallRng > = RefCell :: new( SmallRng :: from_entropy( ) ) ;
6+ }
7+
8+ /// Seeds the thread-local RNG used by [`gen_random_number`].
9+ pub fn seed_rng ( seed : u64 ) {
10+ RNG . with ( |rng| * rng. borrow_mut ( ) = SmallRng :: seed_from_u64 ( seed) ) ;
11+ }
12+
13+ /// Generates a random `usize`.
14+ ///
15+ /// Warning: may take a few seconds!
16+ pub async fn gen_random_number ( ) -> usize {
17+ tokio:: time:: sleep ( Duration :: from_secs ( 2 ) ) . await ;
18+ RNG . with ( |rng| rng. borrow_mut ( ) . gen ( ) )
19+ }
20+
21+ /// Generates a list of possible responses given the current chat.
22+ ///
23+ /// Warning: may take a few seconds!
24+ pub async fn query_chat ( _messages : & [ String ] ) -> Vec < String > {
25+ tokio:: time:: sleep ( Duration :: from_secs ( 2 ) ) . await ;
26+ vec ! [
27+ "And how does that make you feel?" . to_string( ) ,
28+ "Interesting! Go on..." . to_string( ) ,
29+ ]
30+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ edition = "2021"
55
66[dependencies ]
77miniserve = { path = " ../miniserve" }
8+ chatbot = { path = " ../chatbot" }
89serde = { version = " 1.0.204" , features = [" derive" ] }
910serde_json = " 1.0.121"
1011tokio = { workspace = true , features = [" full" ] }
You can’t perform that action at this time.
0 commit comments