import {useState,useEffect,useRef} from 'react'; import '../styles/agent-convo.css' import { Button, Stack, Image, Form, Row, Col, Spinner, InputGroup,FormControl, Modal } from "react-bootstrap"; import { ReactComponent as ReloadIcon } from "../assets/reload.svg"; import { ReactComponent as KeyIcon } from "../assets/key.svg"; import { ReactComponent as LogoutIcon } from "../assets/logout-white.svg"; import { ReactComponent as Bot1Icon } from "../assets/user-1.svg"; import { ReactComponent as Bot2Icon } from "../assets/user-2.svg"; import { ReactComponent as Bot3Icon } from "../assets/user-3.svg"; import { ReactComponent as Bot4Icon } from "../assets/user-4.svg"; import logoImage from '../assets/camelagi.png' import {ReactComponent as SendIcon} from '../assets/send.svg' import { ToastContainer, toast } from 'react-toastify'; import {ReactComponent as GoogleIcon} from '../assets/google.svg' import { ReactComponent as DiscordIcon } from "../assets/discord.svg"; import axios from "axios" import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' import { ReactComponent as ShareIcon } from "../assets/share-white.svg"; function AgentConvo() { const [isLoggedIn,setIsLoggedIn] = useState(false); const [authUrl,setAuthUrl] = useState("") const [ranUser1, setRanUser1] = useState(null); const [ranUser2, setRanUser2] = useState(null); const [started, setStarted] = useState(false); const [key, setKey] = useState(""); const [task, setTask] = useState(""); const [finished, setFinished] = useState(false); const [keyAdded, setKeyAdded] = useState(false); const [user, setUser] = useState(false); const [role1, setRole1] = useState(""); const [role2, setRole2] = useState(""); const [chat,setChat] = useState([]) const [sessId,setSessId] = useState(0) const [showBanner, setShowBanner] = useState(false); const [turn,setTurn] = useState(0) const sessionRef = useRef(null) sessionRef.current = sessId const chatRef = useRef(null) chatRef.current = chat const turnRef = useRef(null) turnRef.current = turn let fetchMessages = () => { setChat([...chatRef.current,{role:0,msg:null}]) axios.post("/rp/start",{role1:role1,role2:role2,task:task,sessId:sessionRef.current}).then((res)=>{ setSessId(res.data.sessId) if(res.data.convoEnd==true){ setFinished((prev)=>true) }else{ chatRef.current.at(-1).msg = res.data.userMsg setChat([...chatRef.current,{role:1,msg:null}]) setTimeout(() => { chatRef.current.at(-1).msg = res.data.assistantMsg; setTurn((prev)=>prev+1) startDiscussion(false) }, 3000); // setUpdate((prev)=>!prev) } }) .catch((err)=>{ toast("Failed to respond " + err.response.data); }) } let startDiscussion = (newTurn) => { let getTurn = turnRef.current if(newTurn==true){ getTurn = 0 setTurn((prev)=>0) setStarted((prev)=>true) } if(getTurn<2){ fetchMessages() } } const addKey = () => { axios.post("/store_key",{key:key}).then((res)=>{ setKeyAdded(true) }).catch((err)=>{ toast("Key cannot be verified, try again"); }) } const logout = () => { axios.get("/heybot/logout").then((res)=>{ window.location.reload(); }).catch((err)=>{ console.log(err) }) } const shareChat = () => { navigator.clipboard.writeText(window.location.host+'/conversation/share?session='+sessionRef.current) window.open('/conversation/share?session='+sessionRef.current, "_blank"); } useEffect(() => { setRanUser1(Math.random()) setRanUser2(Math.random()) axios.get("/rp/isLoggedIn").then((res)=>{ setIsLoggedIn(res.data.isLoggedIn) if(res.data.isLoggedIn == false){ setAuthUrl(res.data.auth_url) }else{ setUser({id:res.data.userId,image:res.data.image}) if(res.data.key_added==null){ setKeyAdded((prev)=>false) }else{ setKeyAdded((prev)=>true) setKey(res.data.key_added) } } }).catch((err)=>{ console.log(err) }) window.setTimeout(()=>setShowBanner(true),30000) },[]) useEffect(() => { if(document.querySelector('.end-chat')!=null){document.querySelector('.end-chat').scrollIntoView({ behavior: 'smooth', block: 'end' });} }, [chat]) return ( <>

CamelAGI

{isLoggedIn&&
window.location.reload()} className="icon"/> {setKeyAdded(false)} className="icon"/>}
}
{isLoggedIn? {keyAdded? <> {started? <> {chatRef.current.length>0&&chatRef.current.map((message)=> message.role==0?
{ranUser1!=null&&ranUser1>0.5?:}
{message.msg==null? :

}
{role1}
:
{message.msg==null? :

}
{role2}
{ranUser2!=null&&ranUser2>0.5?:}
)} {sessionRef.current!=0&&}
{finished?
Task Completed!
: <> {turnRef.current<3? :} } : <>
Get started with a task to discuss
Enter Role of the Instructor setRole1(e.target.value)}/> Enter Role of the Assistant setRole2(e.target.value)}/> Enter topic of discussion setTask(e.target.value)}/> } :
Add your OpenAI Key

Get your OpenAI Key by signing up/ logging in from the OpenAI Dashboard. Go to Dashboard

setKey(e.target.value)} onKeyDown={(e)=>{e.code=="Enter"&&addKey()}} /> Watch this video to get started
}
: {/*
Login to agi
*/}
Accomplish your task with AI agents
{/* navigate('/agi/faq')}> Know More */}
}
setShowBanner(false)}> setShowBanner(false)} className="position-absolute top-0 end-0 me-4 mt-2">X Camel AGI - Communicative Agents on GPT | Product Hunt Join Our Discord Star CamelAGI on Github
) } export default AgentConvo;