"use client"; import { useState } from "react"; import axios from "axios"; import Card from "../components/ui/Card"; import Button from "../components/ui/Button"; import Modal from "../components/ui/Modal"; import { MdSettings } from "react-icons/md"; import ChatMessages from "./ChatMessages"; export default function ChatPage() { const [question, setQuestion] = useState(""); const [history, setHistory] = useState>([ // ["user", "Hello!"], // ["assistant", "Hello Back!"], // ["user", "Send some long message"], // [ // "assistant", // "This is a very long and really long message which is longer than every other message.", // ], // ["user", "What is redux"], // ["assistant", ``], ]); const [model, setModel] = useState("gpt-3.5-turbo"); const [temperature, setTemperature] = useState(0); const [maxTokens, setMaxTokens] = useState(500); const [isPending, setIsPending] = useState(false); const askQuestion = async () => { setHistory((hist) => [...hist, ["user", question]]); setIsPending(true); const response = await axios.post("http://localhost:5000/chat/", { model, question, history, temperature, max_tokens: maxTokens, }); setHistory(response.data.history); console.log(response.data.history); setQuestion(""); setIsPending(false); }; return (
{/* Chat */}

Chat with your brain

Your AI assistant

{ e.preventDefault(); if (!isPending) askQuestion(); }} className="w-full flex items-center justify-center gap-2" > setQuestion(e.target.value)} className="w-full p-2 border border-gray-300 dark:border-gray-500 outline-none rounded dark:bg-gray-800" placeholder="Enter your question here..." /> {/* Settings Button */} } title="Settings" desc="Modify your brain" >
setTemperature(+e.target.value)} />
setMaxTokens(+e.target.value)} />
{/* Settings Modal */}
); }