From 100d4c49cf6d939e80c5655b2c635db437dfb30b Mon Sep 17 00:00:00 2001 From: Valerie Jessup Date: Thu, 23 Mar 2023 17:30:23 -0400 Subject: [PATCH 1/4] chat bot impl --- website/docs/about/introduction.mdx | 3 + website/docusaurus.config.js | 7 + website/src/components/ChatBot/ChatBot.tsx | 156 +++++++++++++++++++++ website/src/components/ChatBot/index.ts | 1 + website/src/css/icons.css | 33 ++++- website/src/css/navbar.css | 3 + website/static/img/qa.png | Bin 0 -> 20731 bytes 7 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 website/src/components/ChatBot/ChatBot.tsx create mode 100644 website/src/components/ChatBot/index.ts create mode 100644 website/static/img/qa.png diff --git a/website/docs/about/introduction.mdx b/website/docs/about/introduction.mdx index 79e147902e..fa96237dc5 100644 --- a/website/docs/about/introduction.mdx +++ b/website/docs/about/introduction.mdx @@ -13,6 +13,7 @@ import RoundedCardGroup from "/src/components/RoundedCard/RoundedCardGroup"; import { RustIcon } from "/src/components/icons/RustIcon"; import useBaseUrl from "@docusaurus/useBaseUrl"; import { Box, Container } from "@mui/system"; +import { ChatBot } from "/src/components/ChatBot"; import WhatIsSwitchboard from "/data/docs/faq_what_is_switchboard.md"; import WhatIsAnOracle from "/data/docs/faq_what_is_an_oracle.md"; @@ -23,6 +24,8 @@ import UseCases from "/data/docs/faq_use_cases.md";
+ + Need Help?
Ask Switchboard Bot a Question!
", + }, { type: "search", position: "right", diff --git a/website/src/components/ChatBot/ChatBot.tsx b/website/src/components/ChatBot/ChatBot.tsx new file mode 100644 index 0000000000..619c1ecdf6 --- /dev/null +++ b/website/src/components/ChatBot/ChatBot.tsx @@ -0,0 +1,156 @@ +import React, { useState, useEffect } from "react"; +import { styled } from "@mui/system"; +import { Dialog, Divider, IconButton, TextField } from "@mui/material"; +import SendIcon from "@mui/icons-material/Send"; + +const StyledDialog = styled(Dialog)({ + "& .MuiDialog-paper": { + width: 600, + height: 600, + paddingBottom: "32px", + display: "flex", + flexDirection: "column", + }, +}); + +const StyledHeader = styled("div")({ + justifyContent: "space-between", + flexDirection: "column", + display: "flex", + width: "100%", + padding: "12px 18px 12px 30px", +}); + +const StyledTextField = styled(TextField)({ + "& .MuiOutlinedInput-root": { + height: 48, + border: "solid 1px #6b7c9333", + borderRadius: "8px", + fontSize: "16px", + color: "#425466", + "& fieldset": { + borderColor: "transparent", + }, + "&:hover fieldset": { + borderColor: "transparent", + }, + "&.Mui-focused fieldset": { + borderColor: "transparent", + }, + }, +}); + +enum Sender { + "bot", + "user", +} + +interface Message { + sender: Sender; + message: string; +} + +const ChatBot = (props: { open: boolean }) => { + const [questionInput, setQuestionInput] = useState(""); + const [messageHistory, setMessageHistory] = useState([ + { + sender: Sender.bot, + message: "Welcome to Switchboard Chat! Ask me a question below.", + }, + ]); + const [open, setOpen] = useState(true); + + // need to set up session storage to keep track of message history + useEffect(() => { + const messagesFromStorage = sessionStorage.getItem("messageHistory"); + if (messagesFromStorage) setMessageHistory(JSON.parse(messagesFromStorage)); + }, []); + + useEffect(() => { + sessionStorage.setItem( + "messageHistory", + // clear any error states + JSON.stringify(messageHistory) + ); + }, [messageHistory]); + + const onQuestionInputChange = (e: React.ChangeEvent) => { + setQuestionInput(e.target.value); + }; + + const submitQuestion = () => { + messageHistory.push({ sender: Sender.user, message: questionInput }); + setQuestionInput(""); + }; + + const onQuestionKeyDown = (event: React.KeyboardEvent) => { + if (event.key === "Enter") { + submitQuestion(); + } + }; + + return ( + setOpen(false)}> + + + Chat with Switchboard Bot + + Ask a question and the Switchboard Bot will try to help! + + +
+ {messageHistory.map((message: Message, idx: number) => { + const userMessage = message.sender === Sender.user; + return ( +
+ {message.message} +
+ ); + })} +
+
+ +
+ + + + +
+
+
+ ); +}; + +export default ChatBot; diff --git a/website/src/components/ChatBot/index.ts b/website/src/components/ChatBot/index.ts new file mode 100644 index 0000000000..ad140c6b16 --- /dev/null +++ b/website/src/components/ChatBot/index.ts @@ -0,0 +1 @@ +export { default as ChatBot } from "./ChatBot"; diff --git a/website/src/css/icons.css b/website/src/css/icons.css index 0549ebf6e6..89e6738886 100644 --- a/website/src/css/icons.css +++ b/website/src/css/icons.css @@ -14,6 +14,38 @@ html[data-theme="dark"] .instruction-icon { color: #ffcb4c; } +/* Ask Me Icon */ +.header-askme-link::before { + content: ""; + position: relative; + width: 28px; + height: 28px; + display: inline-block; + background: url("/img/qa.png") no-repeat; + background-size: 28px; +} + +/* Show the tooltip text when you mouse over the tooltip container */ +.header-askme-link:hover .header-askme-tooltip { + visibility: visible; +} + +.header-askme-link .header-askme-tooltip { + visibility: hidden; + padding: 5px 16px; + border-radius: 6px; + font-size: 16px; + font-weight: 500; + top: 80%; + box-shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px; + border: solid 1px gray; + background-color: white; + position: absolute; + text-align: center; + z-index: 1; + margin-left: -60px; /* Use half of the width (120/2 = 60), to center the tooltip */ +} + /* Github Icon */ .header-github-link:hover { opacity: 0.6; @@ -35,7 +67,6 @@ html[data-theme="dark"] .instruction-icon { display: none; } - /* Aptos Icon */ .header-aptos-link::before { content: ""; diff --git a/website/src/css/navbar.css b/website/src/css/navbar.css index 233479dc5e..362b9254d7 100644 --- a/website/src/css/navbar.css +++ b/website/src/css/navbar.css @@ -12,6 +12,9 @@ padding: 0 1vw; overflow-wrap: break-word; } +.askme_btn { + border-radius: 16px; +} html[data-theme="dark"] .navbar { border-bottom: solid 1px #8998aa; diff --git a/website/static/img/qa.png b/website/static/img/qa.png new file mode 100644 index 0000000000000000000000000000000000000000..cc686e0325fb021030b8158ea8807480bac00f78 GIT binary patch literal 20731 zcmb5WhdbNf`#+wTwQFx$vv$?0tt~~Z)}FOmYO76z=(H8BQ6sHUwTddLM$%d}QxvHb zDYc^#ijYWt&%Qse?;r5Xb-6Omy3c*?bD#TpKORTgO>0v&W+7$}2*hS?W^4-r(EuN5 zKxY_$x4&`UPk=YN$gAe|XMk7YnLDY#ccySNmq-wZz5m}I_=N(yFz};bl!{`?%7bh1gPYhnXP)DpaTT868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i_>m+XYKH}G_W^_0js0e&5=`P?7veeweCC~cBlbHGyRG3OE05xAG_ zeP+9Zzw{Fi*4MvUH%V77{~|iahx05RH8xMmT-h+r462@tf9MtF_E3v5oCZyOd;Ffi zFia`_^{H|uU(Q|6V>HDOYD5^xsWo z0y$?sbOJbwfjp}NO$pm)O`q|vVGj3zvm(@#7IJ_CD5iFs@B&+xjpl#n^#VRu>IxlO zm&w3#m{czP;Z;XYtNzW+OlQPE0lGl}C=jL3@^z~|Pv2>ah7$UBY`IwmaLU)7>O=6= zv6e@zCD_S9U@F{f*+(9uz9h5s);k zRfpq;r9q%jsL+?;X1I#=hin76LDm&|RC}1)&w5{O9n=A7cl8|N6ZqS)96p{>8M1NY z+FG*|P8aX@( zgVyk%E>2lJf8+t^JgE^wqm=@H-UMFfsD=syI;Lw=M2w?1xNOlJD@mDub)Oy|f^*uU zZ`5?y00nn)=#pbcXapW=m>*~@g3cF=-tG=k9Z?PiheBS$n9gNzlE#K%sH(&3SZE$j zI}zG)>zf>mK_uJghuoMYmIS#ap7$153HOQ{d8ec1q8!ab!-Y5Ytqxy~puj(Rm@ByX zt(4jWb$mH&SWW=I`6>1TUN7=?46i|&!H_PiAGO(e0?y6QRPCU!R=?wU?#a;u8T-ay zFzunbO;~tt$ z;=ZxwtqwKP3rZHm)AUy@oZnm zBGASVz9Ao(FOvOqKQs!mA Qs1W4k>4$#&C-(CH01S1nBLDyZ literal 0 HcmV?d00001 From 684d2d03c1b3bf8258a0a196a3de5e22eee5b12f Mon Sep 17 00:00:00 2001 From: Valerie Jessup Date: Mon, 27 Mar 2023 11:19:35 -0400 Subject: [PATCH 2/4] Fix chat bot navbar and scrolling of modal --- website/docusaurus.config.js | 5 +- .../ChainComponent/ChainComponent2.tsx | 74 +++++---- website/src/components/ChatBot/ChatBot.tsx | 143 ++++++++++++++++-- .../components/NavbarItems/ChatBotIcon.tsx | 47 ++++++ website/src/css/icons.css | 32 +--- .../src/theme/NavbarItem/ComponentTypes.tsx | 2 + website/src/types/png.d.ts | 4 + 7 files changed, 220 insertions(+), 87 deletions(-) create mode 100644 website/src/components/NavbarItems/ChatBotIcon.tsx create mode 100644 website/src/types/png.d.ts diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index 79b1e90d7d..56c8e0613f 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -338,11 +338,8 @@ const config = { "aria-label": "GitHub repository", }, { - type: "html", + type: "custom-chatBotNavbarItem", position: "right", - className: "header-askme-link", - value: - "Need Help?
Ask Switchboard Bot a Question!
", }, { type: "search", diff --git a/website/src/components/ChainComponent/ChainComponent2.tsx b/website/src/components/ChainComponent/ChainComponent2.tsx index 136c818257..0b35409bfc 100644 --- a/website/src/components/ChainComponent/ChainComponent2.tsx +++ b/website/src/components/ChainComponent/ChainComponent2.tsx @@ -56,47 +56,45 @@ export default function ChainComponent2({ items }: ChainComponentProps) { > {items.map((item, index) => { return ( - <> - + + - - - {item.title} - - - + {item.title} + + ); })} diff --git a/website/src/components/ChatBot/ChatBot.tsx b/website/src/components/ChatBot/ChatBot.tsx index 619c1ecdf6..a8711e3f03 100644 --- a/website/src/components/ChatBot/ChatBot.tsx +++ b/website/src/components/ChatBot/ChatBot.tsx @@ -1,13 +1,57 @@ -import React, { useState, useEffect } from "react"; +import React, { useState, useEffect, useRef } from "react"; import { styled } from "@mui/system"; import { Dialog, Divider, IconButton, TextField } from "@mui/material"; import SendIcon from "@mui/icons-material/Send"; +const TypingDiv = styled("div")({ + width: "5em", + height: "2em", + position: "relative", + padding: "10px", + background: "#e6e6e6", + borderRadius: "16px", + display: "flex", + alignItems: "center", + justifyContent: "center", + "@keyframes loadingFade": { + "0%": { + opacity: 0, + }, + "50%": { + opacity: 0.8, + }, + "100%": { + opacity: 0, + }, + }, +}); + +const TypingDot = styled("div")({ + float: "left", + width: "8px", + height: "8px", + margin: "0 4px", + background: "#8d8c91", + borderRadius: "50%", + opacity: "0", + animation: "loadingFade 1s infinite", + ":nth-of-type(1)": { + animationDelay: "0s", + }, + ":nth-of-type(2)": { + animationDelay: "0.2s", + }, + ":nth-of-type(3)": { + animationDelay: "0.4s", + marginRight: "0px", + }, +}); + const StyledDialog = styled(Dialog)({ "& .MuiDialog-paper": { - width: 600, + width: 650, height: 600, - paddingBottom: "32px", + paddingBottom: "16px", display: "flex", flexDirection: "column", }, @@ -50,15 +94,40 @@ interface Message { message: string; } -const ChatBot = (props: { open: boolean }) => { +const CHAT_URL = "https://chat.switchboard.xyz"; + +const fetchChat = async (input: string) => { + return fetch(`${CHAT_URL}`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + input, + }), + }) + .then((response) => { + if (response.ok) { + return response.json().then((json) => json.completion); + } else { + return "That isn't a valid question. Please try again."; + } + }) + .catch(() => "Sorry, something went wrong. Please try again."); +}; + +const ChatBot = (props: { open: boolean; onClose: () => void }) => { const [questionInput, setQuestionInput] = useState(""); + const [isTyping, setIsTyping] = useState(false); const [messageHistory, setMessageHistory] = useState([ { sender: Sender.bot, message: "Welcome to Switchboard Chat! Ask me a question below.", }, ]); - const [open, setOpen] = useState(true); + + const messagesRef = useRef(); + const endOfMessagesRef = useRef(); // need to set up session storage to keep track of message history useEffect(() => { @@ -67,20 +136,42 @@ const ChatBot = (props: { open: boolean }) => { }, []); useEffect(() => { - sessionStorage.setItem( - "messageHistory", - // clear any error states - JSON.stringify(messageHistory) - ); + sessionStorage.setItem("messageHistory", JSON.stringify(messageHistory)); }, [messageHistory]); + // use a ref to scroll down to most recent message + useEffect(() => { + endOfMessagesRef.current?.scrollIntoView({ behavior: "smooth" }); + }, [messageHistory]); + + // need a timeout so that the ref exists when trying to + // scroll down when you first open the modal + useEffect(() => { + setTimeout(() => { + endOfMessagesRef.current?.scrollIntoView({ behavior: "smooth" }); + }, 100); + }, [props.open]); + const onQuestionInputChange = (e: React.ChangeEvent) => { setQuestionInput(e.target.value); }; - const submitQuestion = () => { - messageHistory.push({ sender: Sender.user, message: questionInput }); + const submitQuestion = async () => { + const message = questionInput; // temp to keep track of current message + setMessageHistory((prevState: Message[]) => [ + ...prevState, + { sender: Sender.user, message }, + ]); setQuestionInput(""); + + // fetch response + setIsTyping(true); + const response = await fetchChat(message); + setIsTyping(false); + setMessageHistory((prevState: Message[]) => [ + ...prevState, + { sender: Sender.bot, message: response }, + ]); }; const onQuestionKeyDown = (event: React.KeyboardEvent) => { @@ -90,7 +181,7 @@ const ChatBot = (props: { open: boolean }) => { }; return ( - setOpen(false)}> + Chat with Switchboard Bot @@ -105,6 +196,8 @@ const ChatBot = (props: { open: boolean }) => { width: "100%", height: "100%", padding: "16px 32px", + maxHeight: 500, + overflowY: "scroll", }} > {messageHistory.map((message: Message, idx: number) => { @@ -113,7 +206,7 @@ const ChatBot = (props: { open: boolean }) => {
{ width: "60%", alignSelf: userMessage ? "flex-end" : "flex-start", }} + ref={messagesRef} > {message.message}
); })} + {isTyping && ( + + + + + + )} +
{ onKeyDown={onQuestionKeyDown} placeholder="Type your question here..." sx={{ flexGrow: 1, marginRight: "12px" }} + autoComplete="off" />
+ + Powered by ChatGPT +
); diff --git a/website/src/components/NavbarItems/ChatBotIcon.tsx b/website/src/components/NavbarItems/ChatBotIcon.tsx new file mode 100644 index 0000000000..e851a03e8e --- /dev/null +++ b/website/src/components/NavbarItems/ChatBotIcon.tsx @@ -0,0 +1,47 @@ +import React, { useState } from "react"; +import qaIcon from "../../../static/img/qa.png"; +import { IconButton, Tooltip } from "@mui/material"; +import { ChatBot } from "../ChatBot"; + +const ChatBotIcon = () => { + const [openChatModal, setOpenChatModal] = useState(false); + + const onClose = () => { + setOpenChatModal(false); + }; + + return ( + <> + + setOpenChatModal(true)} + sx={{ + ":hover": { + backgroundColor: "white", + opacity: 0.6, + }, + }} + > + + + + + + ); +}; + +export default ChatBotIcon; diff --git a/website/src/css/icons.css b/website/src/css/icons.css index 89e6738886..cb7b0929e4 100644 --- a/website/src/css/icons.css +++ b/website/src/css/icons.css @@ -14,36 +14,8 @@ html[data-theme="dark"] .instruction-icon { color: #ffcb4c; } -/* Ask Me Icon */ -.header-askme-link::before { - content: ""; - position: relative; - width: 28px; - height: 28px; - display: inline-block; - background: url("/img/qa.png") no-repeat; - background-size: 28px; -} - -/* Show the tooltip text when you mouse over the tooltip container */ -.header-askme-link:hover .header-askme-tooltip { - visibility: visible; -} - -.header-askme-link .header-askme-tooltip { - visibility: hidden; - padding: 5px 16px; - border-radius: 6px; - font-size: 16px; - font-weight: 500; - top: 80%; - box-shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px; - border: solid 1px gray; - background-color: white; - position: absolute; - text-align: center; - z-index: 1; - margin-left: -60px; /* Use half of the width (120/2 = 60), to center the tooltip */ +.DocSearch-Search-Icon { + display: none; } /* Github Icon */ diff --git a/website/src/theme/NavbarItem/ComponentTypes.tsx b/website/src/theme/NavbarItem/ComponentTypes.tsx index a8bf5754a9..50a666f17b 100644 --- a/website/src/theme/NavbarItem/ComponentTypes.tsx +++ b/website/src/theme/NavbarItem/ComponentTypes.tsx @@ -1,7 +1,9 @@ import ComponentTypes from "@theme-original/NavbarItem/ComponentTypes"; import SupportedChainsNavbarItem from "@site/src/components/NavbarItems/SupportedChainsNavbarItem"; +import ChatBotIcon from "@site/src/components/NavbarItems/ChatBotIcon"; export default { ...ComponentTypes, "custom-supportedChainsNavbarItem": SupportedChainsNavbarItem, + "custom-chatBotNavbarItem": ChatBotIcon, }; diff --git a/website/src/types/png.d.ts b/website/src/types/png.d.ts new file mode 100644 index 0000000000..81ed67b796 --- /dev/null +++ b/website/src/types/png.d.ts @@ -0,0 +1,4 @@ +declare module "*.png" { + const value: any; + export = value; +} From 2a36c8b8ca7ad8d99e453e8db5dad03241939fd2 Mon Sep 17 00:00:00 2001 From: Valerie Jessup Date: Mon, 27 Mar 2023 11:28:10 -0400 Subject: [PATCH 3/4] Small cleanup --- website/src/components/ChatBot/ChatBot.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/website/src/components/ChatBot/ChatBot.tsx b/website/src/components/ChatBot/ChatBot.tsx index a8711e3f03..fc2f8c5794 100644 --- a/website/src/components/ChatBot/ChatBot.tsx +++ b/website/src/components/ChatBot/ChatBot.tsx @@ -135,12 +135,9 @@ const ChatBot = (props: { open: boolean; onClose: () => void }) => { if (messagesFromStorage) setMessageHistory(JSON.parse(messagesFromStorage)); }, []); + // save to sessionStorage & use a ref to scroll down to most recent message useEffect(() => { sessionStorage.setItem("messageHistory", JSON.stringify(messageHistory)); - }, [messageHistory]); - - // use a ref to scroll down to most recent message - useEffect(() => { endOfMessagesRef.current?.scrollIntoView({ behavior: "smooth" }); }, [messageHistory]); From 201aff909a853bf65e92b32a9bcfb6dfb31705ac Mon Sep 17 00:00:00 2001 From: Valerie Jessup Date: Mon, 27 Mar 2023 16:06:44 -0400 Subject: [PATCH 4/4] cleanup --- website/docs/about/introduction.mdx | 3 --- website/src/css/navbar.css | 3 --- 2 files changed, 6 deletions(-) diff --git a/website/docs/about/introduction.mdx b/website/docs/about/introduction.mdx index fa96237dc5..79e147902e 100644 --- a/website/docs/about/introduction.mdx +++ b/website/docs/about/introduction.mdx @@ -13,7 +13,6 @@ import RoundedCardGroup from "/src/components/RoundedCard/RoundedCardGroup"; import { RustIcon } from "/src/components/icons/RustIcon"; import useBaseUrl from "@docusaurus/useBaseUrl"; import { Box, Container } from "@mui/system"; -import { ChatBot } from "/src/components/ChatBot"; import WhatIsSwitchboard from "/data/docs/faq_what_is_switchboard.md"; import WhatIsAnOracle from "/data/docs/faq_what_is_an_oracle.md"; @@ -24,8 +23,6 @@ import UseCases from "/data/docs/faq_use_cases.md";
- -