Skip to content

Commit

Permalink
Use new chatbot
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Jul 11, 2024
1 parent 9917002 commit 980911a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions crates/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,4 @@ anyhow = "1.0.86"
axum = { workspace = true }
serde = { workspace = true }
tokio = { workspace = true }
chatbot = { path = "../chatbot" }

[dev-dependencies]
rand = { workspace = true }
chatbot = { path = "../chatbot" }
10 changes: 6 additions & 4 deletions crates/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use axum::{
Json, Router,
};
use serde::{Deserialize, Serialize};
use tokio::join;

async fn root() -> Html<&'static str> {
Html(include_str!("../index.html"))
Expand All @@ -16,10 +17,11 @@ struct Chat {
}

async fn chat(Json(mut chat): Json<Chat>) -> Json<Chat> {
let responses = chatbot::query_chat(&chat.messages).await;
let random = chatbot::gen_random_number().await;
chat.messages
.push(responses[random % responses.len()].to_string());
let responses_fut = chatbot::query_chat(&chat.messages);
let random_fut = chatbot::gen_random_number();
let (mut responses, random) = join!(responses_fut, random_fut);
let response = responses.remove(random % responses.len());
chat.messages.push(response);
Json(chat)
}

Expand Down

0 comments on commit 980911a

Please sign in to comment.