From 3d006bde92020df2e39aec20b76a98ed7496e904 Mon Sep 17 00:00:00 2001 From: Chris Chudzicki Date: Wed, 8 Jan 2025 14:21:10 -0500 Subject: [PATCH] add a websocket frontend --- frontend-demo/src/app/http/page.tsx | 45 ++++++++++++++++++++++++ frontend-demo/src/app/page.tsx | 53 ++++++++--------------------- 2 files changed, 60 insertions(+), 38 deletions(-) create mode 100644 frontend-demo/src/app/http/page.tsx diff --git a/frontend-demo/src/app/http/page.tsx b/frontend-demo/src/app/http/page.tsx new file mode 100644 index 0000000..3eb6398 --- /dev/null +++ b/frontend-demo/src/app/http/page.tsx @@ -0,0 +1,45 @@ +"use client" +import React from "react" +import { AiChat, AiChatProps } from "@mitodl/smoot-design/ai" +import styled from "@emotion/styled" + +const INITIAL_MESSAGES: AiChatProps["initialMessages"] = [ + { + content: "Hi! What are you interested in learning about?", + role: "assistant", + }, +] + +const STARTERS = [ + { content: "I'm interested in quantum computing" }, + { content: "I want to understand global warming. " }, + { content: "I am curious about AI applications for business" }, +] + +const REQUEST_OPTS: AiChatProps["requestOpts"] = { + apiUrl: `${process.env.NEXT_PUBLIC_MITOL_API_BASE_URL}/http/recommendation_agent/`, + transformBody(messages) { + const message = messages[messages.length - 1].content + return { message } + }, + fetchOpts: { + credentials: "include", + }, +} + +const StyledChat = styled(AiChat)({ + height: "calc(80vh - 72px)", + marginTop: "16px", +}) + +const HomePage: React.FC = () => { + return ( + + ) +} + +export default HomePage diff --git a/frontend-demo/src/app/page.tsx b/frontend-demo/src/app/page.tsx index 3eb6398..dc3c85f 100644 --- a/frontend-demo/src/app/page.tsx +++ b/frontend-demo/src/app/page.tsx @@ -1,45 +1,22 @@ -"use client" -import React from "react" -import { AiChat, AiChatProps } from "@mitodl/smoot-design/ai" -import styled from "@emotion/styled" +import Link from "next/link" -const INITIAL_MESSAGES: AiChatProps["initialMessages"] = [ - { - content: "Hi! What are you interested in learning about?", - role: "assistant", - }, -] - -const STARTERS = [ - { content: "I'm interested in quantum computing" }, - { content: "I want to understand global warming. " }, - { content: "I am curious about AI applications for business" }, -] - -const REQUEST_OPTS: AiChatProps["requestOpts"] = { - apiUrl: `${process.env.NEXT_PUBLIC_MITOL_API_BASE_URL}/http/recommendation_agent/`, - transformBody(messages) { - const message = messages[messages.length - 1].content - return { message } - }, - fetchOpts: { - credentials: "include", - }, +export const metadata = { + title: "Home", } -const StyledChat = styled(AiChat)({ - height: "calc(80vh - 72px)", - marginTop: "16px", -}) - -const HomePage: React.FC = () => { +const Page = () => { return ( - +
+
    +
  • + Http Chat +
  • +
  • + Websocket Chat +
  • +
+
) } -export default HomePage +export default Page