2024-02-07 00:11:07 +05:30
|
|
|
import React from "react"
|
2024-03-23 14:44:05 +05:30
|
|
|
import { useMessageOption } from "~/hooks/useMessageOption"
|
2024-02-07 21:07:41 +05:30
|
|
|
import { PlaygroundEmpty } from "./PlaygroundEmpty"
|
2024-03-23 14:44:05 +05:30
|
|
|
import { PlaygroundMessage } from "~/components/Common/Playground/Message"
|
2024-04-06 20:18:46 +05:30
|
|
|
import { MessageSourcePopup } from "@/components/Common/Playground/MessageSourcePopup"
|
2024-02-07 00:11:07 +05:30
|
|
|
|
|
|
|
|
export const PlaygroundChat = () => {
|
2024-03-16 00:30:41 +05:30
|
|
|
const {
|
|
|
|
|
messages,
|
|
|
|
|
streaming,
|
|
|
|
|
regenerateLastMessage,
|
|
|
|
|
isSearchingInternet,
|
2024-04-11 00:08:20 +05:30
|
|
|
editMessage,
|
|
|
|
|
ttsEnabled
|
2024-03-16 00:30:41 +05:30
|
|
|
} = useMessageOption()
|
2024-02-07 00:11:07 +05:30
|
|
|
const divRef = React.useRef<HTMLDivElement>(null)
|
2024-04-06 20:18:46 +05:30
|
|
|
const [isSourceOpen, setIsSourceOpen] = React.useState(false)
|
|
|
|
|
const [source, setSource] = React.useState<any>(null)
|
2024-02-07 00:11:07 +05:30
|
|
|
React.useEffect(() => {
|
|
|
|
|
if (divRef.current) {
|
|
|
|
|
divRef.current.scrollIntoView({ behavior: "smooth" })
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return (
|
2024-04-06 20:18:46 +05:30
|
|
|
<>
|
|
|
|
|
{" "}
|
|
|
|
|
<div className="grow flex flex-col md:translate-x-0 transition-transform duration-300 ease-in-out">
|
|
|
|
|
{messages.length === 0 && (
|
|
|
|
|
<div className="mt-32">
|
|
|
|
|
<PlaygroundEmpty />
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{/* {messages.length > 0 && <div className="w-full h-16 flex-shrink-0"></div>} */}
|
|
|
|
|
{messages.map((message, index) => (
|
|
|
|
|
<PlaygroundMessage
|
|
|
|
|
key={index}
|
|
|
|
|
isBot={message.isBot}
|
|
|
|
|
message={message.message}
|
|
|
|
|
name={message.name}
|
|
|
|
|
images={message.images || []}
|
|
|
|
|
currentMessageIndex={index}
|
|
|
|
|
totalMessages={messages.length}
|
|
|
|
|
onRengerate={regenerateLastMessage}
|
|
|
|
|
isProcessing={streaming}
|
|
|
|
|
isSearchingInternet={isSearchingInternet}
|
|
|
|
|
sources={message.sources}
|
|
|
|
|
onEditFormSubmit={(value) => {
|
|
|
|
|
editMessage(index, value, !message.isBot)
|
|
|
|
|
}}
|
|
|
|
|
onSourceClick={(data) => {
|
|
|
|
|
setSource(data)
|
|
|
|
|
setIsSourceOpen(true)
|
|
|
|
|
}}
|
2024-04-11 00:08:20 +05:30
|
|
|
isTTSEnabled={ttsEnabled}
|
2024-04-06 20:18:46 +05:30
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
{messages.length > 0 && (
|
|
|
|
|
<div className="w-full h-32 md:h-48 flex-shrink-0"></div>
|
|
|
|
|
)}
|
|
|
|
|
<div ref={divRef} />
|
|
|
|
|
</div>
|
|
|
|
|
<MessageSourcePopup
|
|
|
|
|
open={isSourceOpen}
|
|
|
|
|
setOpen={setIsSourceOpen}
|
|
|
|
|
source={source}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
2024-02-07 00:11:07 +05:30
|
|
|
)
|
|
|
|
|
}
|