From 9a58a178d05fed0d683953b612a5d6dbb8eb5bd3 Mon Sep 17 00:00:00 2001 From: Gregor Adams Date: Sat, 15 Jul 2023 04:31:09 +0200 Subject: [PATCH] docs: improved UI for docs --- README.md | 4 +- docs-gui/components/bot.tsx | 164 ++++++++++-------------- docs-gui/components/chat-input.tsx | 130 +++++++++++++------ docs-gui/components/language-select.tsx | 75 ++++++----- docs-gui/components/layout.tsx | 14 +- package-lock.json | 16 --- package.json | 1 - 7 files changed, 212 insertions(+), 192 deletions(-) diff --git a/README.md b/README.md index d8b3773..3822081 100644 --- a/README.md +++ b/README.md @@ -46,10 +46,10 @@ const artist = new Agent(new DallEModelAdapter(), { }); // Assign tasks -const writerResult = writer.assign({ +const writerResult = await writer.assign({ question: "Describe the future to an artist so that they can draw it", }); -const artistResult = artist.assign(writerResult.message); +const artistResult = await artist.assign(writerResult.message); // Do something with the result console.log(artistResult.message.content); ``` diff --git a/docs-gui/components/bot.tsx b/docs-gui/components/bot.tsx index 74c446d..1f8b664 100644 --- a/docs-gui/components/bot.tsx +++ b/docs-gui/components/bot.tsx @@ -7,8 +7,6 @@ import { DotLottiePlayer } from "@dotlottie/react-player"; import { Box, Card, CardContent, Checkbox, Container, Modal } from "@mui/joy"; import axios from "axios"; import { useAtom } from "jotai"; -import { useEffect } from "react"; -import { Controller, FormProvider, useForm } from "react-hook-form"; import { answerAtom, @@ -47,120 +45,88 @@ export function generateMarkdown(guides: Guide[]): string { export function Bot({ onAnswer, + onExpand, onQuestion, }: { + onExpand?(): void; onQuestion?(): void; onAnswer?(data: { id: string; message: Record }): void; }) { const [loading, setLoading] = useAtom(loadingAtom); - const [question, setQuestion] = useAtom(questionAtom); + + const [question] = useAtom(questionAtom); const [search, setSearch] = useAtom(searchAtom); const [guide, setGuide] = useAtom(guideAtom); - const [language, setLanguage] = useAtom(languageAtom); - const methods = useForm<{ - question: string; - guide: boolean; - language: string; - search: boolean; - }>({ - defaultValues: { question, guide, language, search }, - }); - - const onSubmit = methods.handleSubmit( - async (formData: { - question: string; - guide?: boolean; - search?: boolean; - language: string; - }) => { - setLoading(true); - setQuestion(formData.question); - setSearch(formData.search); - setGuide(formData.guide); - setLanguage(formData.language); - - if (onQuestion) { - onQuestion(); - } + const [language] = useAtom(languageAtom); - try { - const { data } = formData.search - ? await axios.post("/api/search", { - q: formData.question, - }) - : await axios.post("/api/ama", { - question: formData.question, - guide: formData.guide, - language: formData.language, - }); - if (onAnswer) { - if (formData.search) { - onAnswer({ - id: "search", - message: { - answer: generateMarkdown(data), - }, - }); - } else { - onAnswer(data); - } + async function handleSubmit() { + setLoading(true); + + if (onQuestion) { + onQuestion(); + } + + try { + const { data } = search + ? await axios.post("/api/search", { + q: question, + }) + : await axios.post("/api/ama", { + question, + guide, + language, + }); + if (onAnswer) { + if (search) { + onAnswer({ + id: "search", + message: { + answer: generateMarkdown(data), + }, + }); + } else { + onAnswer(data); } - } catch (error) { - console.error(error); - } finally { - setLoading(false); } + } catch (error) { + console.error(error); + } finally { + setLoading(false); } - ); - - const { setValue } = methods; - - useEffect(() => { - setValue("question", question); - setValue("language", language); - setValue("search", search); - setValue("guide", guide); - }, [setValue, guide, search, language, question]); + } return ( - - - - - - ( - - )} - /> - ( - - )} - /> + + + + + { + setSearch(!search); + }} + label="Search" + variant="soft" + sx={{ color: "inherit" }} + /> + + { + setGuide(!guide); + }} + label="Guide" + variant="soft" + sx={{ color: "inherit" }} + /> - - + - + ); } @@ -190,7 +156,7 @@ export default function HyvSearch() { return ( - + diff --git a/docs-gui/components/chat-input.tsx b/docs-gui/components/chat-input.tsx index 85bc1d0..f9bb1d0 100644 --- a/docs-gui/components/chat-input.tsx +++ b/docs-gui/components/chat-input.tsx @@ -1,58 +1,104 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */ // @ts-ignore +import FullscreenIcon from "@mui/icons-material/Fullscreen"; +// @ts-ignore import SendIcon from "@mui/icons-material/Send"; -import { CircularProgress, IconButton, Textarea } from "@mui/joy"; -import { useFormContext } from "react-hook-form"; +import { Box, CircularProgress, IconButton, Textarea } from "@mui/joy"; +import { useAtom } from "jotai"; +import { useState } from "react"; + +// @ts-ignore +import { questionAtom } from "@/docs/atoms"; /* eslint-enable @typescript-eslint/ban-ts-comment */ export interface ChatInputProps { loading: boolean; onSubmit(): void; + onExpand?(): void; } -export function ChatInput({ loading, onSubmit }: ChatInputProps) { - const { register } = useFormContext(); +export function ChatInput({ loading, onSubmit, onExpand }: ChatInputProps) { + const [question, setQuestion] = useAtom(questionAtom); + const [focus, setFocus] = useState(false); return ( -