Skip to content

Commit

Permalink
Join solution
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Aug 26, 2024
1 parent 5535ea2 commit 0b12094
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions crates/server/src/main.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -18,9 +19,15 @@ async fn chat(req: Request) -> Response {
let Ok(mut messages) = serde_json::from_str::<Messages>(&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()))
}

Expand Down

0 comments on commit 0b12094

Please sign in to comment.