Spaces:
Runtime error
Runtime error
File size: 1,386 Bytes
ed45bdf 22ff301 ed45bdf 22ff301 ed45bdf 22ff301 ed45bdf |
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 |
import useLLM from "@react-llm/headless";
import { useEffect, useRef } from "react";
import { ScrollView } from "react95";
function MessageList({
screenName = "endlessbox5",
assistantScreenName = "SmartestChild",
}) {
const scrollRef = useRef(null);
const { conversation, userRoleName } = useLLM();
const messages = conversation?.messages || [];
const scrollToBottom = () => {
if (scrollRef.current) {
scrollRef.current.scrollIntoView();
}
};
useEffect(() => {
scrollToBottom();
}, [conversation, messages.length]);
return (
<ScrollView style={{ height: "350px" }} className="w-full">
<div className="p-2 leading-6 w-full min-h-full">
{conversation?.messages.map((m) => (
<div key={m.id} style={{ display: "flex" }}>
<div
style={{
padding: "2px",
borderRadius: "5px",
}}
>
<span
style={{
fontWeight: "bold",
color: m.role === userRoleName ? "blue" : "red",
}}
>
{m.role === userRoleName ? screenName : assistantScreenName}
</span>
: {m.text}
</div>
</div>
))}
<div ref={scrollRef}></div>
</div>
</ScrollView>
);
}
export default MessageList; |