Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | import React, { useRef, useEffect } from "react";
import { ChatMessage } from "@/objects/Model";
import RichMarkdown from "@/components/chat/RichMarkdown/RichMarkdown";
import "./ChatHistory.css";
export interface ChatHistoryInterface {
messages: ChatMessage[];
model_name: string;
loading: boolean;
}
const ChatHistory: React.FC<ChatHistoryInterface> = (props) => {
const chatEndRef = useRef<HTMLDivElement | null>(null);
useEffect(() => {
chatEndRef.current?.scrollIntoView({ behavior: "smooth" });
}, [props]);
return (
<div className="max-h-[40vh] overflow-y-auto border border-gray p-2 bg-slate-100 rounded mb-4 text-black">
{props.messages.length > 0 ? (
props.messages.map((entry, index) => (
<div
key={index}
className={`p-2 rounded ${
entry.role === "user"
? "bg-blue-100 text-right"
: entry.role === "assistant"
? "bg-gray-100 text-left"
: "bg-amber-100 text-center italic text-amber-950"
}`}
>
<strong className="font-bold">
{entry.role === "user"
? "You"
: entry.role === "assistant"
? props.model_name
: "System"}
:
</strong>{" "}
<RichMarkdown content={entry.content} />
</div>
))
) : (
<span className="text-gray-500 italic">
Your chat is empty, type below to start a conversation...
</span>
)}
{props.loading && (
<div className="p-4 rounded">
<div className="flex flex-row items-center gap-4">
<div className="spinner"></div>
<span>Bot is thinking...</span>
</div>
</div>
)}
<div ref={chatEndRef} />
</div>
);
};
export default ChatHistory;
|