2023-05-21 02:20:55 +03:00
|
|
|
"use client";
|
2023-06-02 18:01:49 +03:00
|
|
|
import Link from "next/link";
|
2023-06-09 19:49:47 +03:00
|
|
|
import {
|
|
|
|
MdAutorenew,
|
|
|
|
MdMic,
|
|
|
|
MdMicOff,
|
|
|
|
MdSend,
|
|
|
|
MdSettings,
|
|
|
|
} from "react-icons/md";
|
2023-05-21 02:20:55 +03:00
|
|
|
import Button from "../components/ui/Button";
|
2023-05-26 14:56:29 +03:00
|
|
|
import Card from "../components/ui/Card";
|
2023-05-23 11:06:58 +03:00
|
|
|
import PageHeading from "../components/ui/PageHeading";
|
2023-06-03 21:09:00 +03:00
|
|
|
import ChatMessages from "./components/ChatMessages";
|
|
|
|
import { useQuestion } from "./hooks/useQuestion";
|
|
|
|
import { useSpeech } from "./hooks/useSpeech";
|
2023-05-18 02:22:13 +03:00
|
|
|
|
|
|
|
export default function ChatPage() {
|
2023-06-09 19:49:47 +03:00
|
|
|
const {
|
|
|
|
history,
|
|
|
|
isPending,
|
|
|
|
question,
|
|
|
|
askQuestion,
|
|
|
|
setQuestion,
|
|
|
|
resetHistory,
|
|
|
|
} = useQuestion();
|
2023-06-03 21:09:00 +03:00
|
|
|
const { isListening, speechSupported, startListening } = useSpeech();
|
2023-05-29 01:45:48 +03:00
|
|
|
|
2023-05-18 02:22:13 +03:00
|
|
|
return (
|
2023-06-06 14:59:39 +03:00
|
|
|
<main className="min-h-0 w-full flex flex-col pt-32 flex-1 overflow-hidden">
|
|
|
|
<section className="flex flex-col justify-center items-center gap-5 h-full overflow-auto style={{ marginBottom: '20px'}}">
|
2023-05-23 11:06:58 +03:00
|
|
|
<PageHeading
|
|
|
|
title="Chat with your brain"
|
2023-05-25 11:10:35 +03:00
|
|
|
subtitle="Talk to a language model about your uploaded data"
|
2023-05-23 11:06:58 +03:00
|
|
|
/>
|
2023-05-21 02:20:55 +03:00
|
|
|
{/* Chat */}
|
2023-06-08 00:16:59 +03:00
|
|
|
<Card className="py-4 max-w-3xl w-full flex-1 md:mb-24 overflow-auto flex flex-col hover:shadow-none shadow-none ">
|
2023-05-21 02:20:55 +03:00
|
|
|
<ChatMessages history={history} />
|
2023-06-06 14:59:39 +03:00
|
|
|
</Card>
|
2023-06-08 00:16:59 +03:00
|
|
|
<Card className="md:fixed md:rounded md:left-1/2 w-full max-w-3xl bg-gray-100 dark:bg-gray-800 md:-translate-x-1/2 md:bottom-16 px-5 py-5 md:mb-5 hover:shadow-none shadow-none">
|
2023-06-06 14:59:39 +03:00
|
|
|
<form
|
|
|
|
onSubmit={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
if (!isPending) askQuestion();
|
|
|
|
}}
|
2023-06-08 00:16:59 +03:00
|
|
|
className="w-full flex flex-col md:flex-row items-center justify-center gap-2 "
|
2023-06-06 14:59:39 +03:00
|
|
|
>
|
2023-06-08 00:16:59 +03:00
|
|
|
<div className="flex gap-1 w-full">
|
|
|
|
<input
|
2023-06-09 19:49:47 +03:00
|
|
|
autoFocus
|
|
|
|
value={question}
|
|
|
|
onChange={(e) => setQuestion(e.target.value)}
|
|
|
|
onKeyDown={(e) => {
|
|
|
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
|
|
e.preventDefault(); // Prevents the newline from being entered in the textarea
|
|
|
|
if (!isPending) askQuestion(); // Call the submit function here
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
className="w-full p-2 border border-gray-300 dark:border-gray-500 outline-none rounded dark:bg-gray-800"
|
|
|
|
placeholder="Begin conversation here..."
|
|
|
|
/>
|
|
|
|
<Button type="submit" isLoading={isPending}>
|
2023-06-08 00:16:59 +03:00
|
|
|
{isPending ? "" : <MdSend />}
|
2023-06-09 19:49:47 +03:00
|
|
|
</Button>
|
2023-06-08 00:16:59 +03:00
|
|
|
</div>
|
2023-06-09 19:49:47 +03:00
|
|
|
|
2023-06-08 00:16:59 +03:00
|
|
|
<div className="flex">
|
2023-06-09 19:49:47 +03:00
|
|
|
{/* Reset Button */}
|
2023-06-08 00:16:59 +03:00
|
|
|
<Button
|
|
|
|
className="px-3"
|
|
|
|
variant={"tertiary"}
|
|
|
|
type="button"
|
|
|
|
onClick={resetHistory}
|
|
|
|
disabled={isPending}
|
|
|
|
>
|
|
|
|
<MdAutorenew className="text-2xl" />
|
|
|
|
</Button>
|
|
|
|
{/* Mic Button */}
|
|
|
|
<Button
|
|
|
|
className="px-3"
|
|
|
|
variant={"tertiary"}
|
|
|
|
type="button"
|
|
|
|
onClick={startListening}
|
|
|
|
disabled={!speechSupported}
|
|
|
|
>
|
|
|
|
{isListening ? (
|
|
|
|
<MdMicOff className="text-2xl" />
|
|
|
|
) : (
|
|
|
|
<MdMic className="text-2xl" />
|
|
|
|
)}
|
2023-05-29 01:45:48 +03:00
|
|
|
</Button>
|
2023-06-08 00:16:59 +03:00
|
|
|
<Link href={"/config"}>
|
|
|
|
<Button className="px-3" variant={"tertiary"}>
|
|
|
|
<MdSettings className="text-2xl" />
|
|
|
|
</Button>
|
|
|
|
</Link>
|
|
|
|
</div>
|
2023-06-06 14:59:39 +03:00
|
|
|
</form>
|
2023-05-21 02:20:55 +03:00
|
|
|
</Card>
|
2023-05-23 11:06:58 +03:00
|
|
|
</section>
|
|
|
|
</main>
|
2023-05-18 02:22:13 +03:00
|
|
|
);
|
2023-06-09 19:49:47 +03:00
|
|
|
}
|