diff --git a/crates/server/src/main.rs b/crates/server/src/main.rs index 2a4ad2f..d1c21b0 100644 --- a/crates/server/src/main.rs +++ b/crates/server/src/main.rs @@ -1,5 +1,6 @@ use miniserve::{http::StatusCode, Content, Request, Response}; use serde::{Deserialize, Serialize}; +use tokio::join; async fn index(_req: Request) -> Response { let content = include_str!("../index.html").to_string(); @@ -18,9 +19,15 @@ async fn chat(req: Request) -> Response { let Ok(mut messages) = serde_json::from_str::(&body) else { return Err(StatusCode::INTERNAL_SERVER_ERROR); }; - messages - .messages - .push("And how does that make you feel?".into()); + + let (i, mut responses) = join!( + chatbot::gen_random_number(), + chatbot::query_chat(&messages.messages) + ); + + let response = responses.remove(i % responses.len()); + messages.messages.push(response); + Ok(Content::Json(serde_json::to_string(&messages).unwrap())) }