MCPcopy
hub / github.com/jacoblee93/fully-local-pdf-chatbot / ChatMessageBubble

Function ChatMessageBubble

components/ChatMessageBubble.tsx:11–125  ·  view source on GitHub ↗
(props: {
  message: ChatWindowMessage;
  aiEmoji?: React.JSX.Element;
  onRemovePressed?: () => void;
})

Source from the content-addressed store, hash-verified

9import { Feedback } from 'langsmith';
10
11export function ChatMessageBubble(props: {
12 message: ChatWindowMessage;
13 aiEmoji?: React.JSX.Element;
14 onRemovePressed?: () => void;
15}) {
16 const { role, content, runId } = props.message;
17
18 const colorClassName =
19 role === "user" ? "bg-sky-600" : "bg-slate-50 text-black";
20 const alignmentClassName =
21 role === "user" ? "ml-auto" : "mr-auto";
22 const prefix = role === "user" ? "🧑" : props.aiEmoji;
23
24 const [isLoading, setIsLoading] = useState(false);
25 const [feedback, setFeedback] = useState<Feedback | null>(null);
26 const [comment, setComment] = useState("");
27 const [showCommentForm, setShowCommentForm] = useState(false);
28
29 async function handleScoreButtonPress(e: React.MouseEvent<HTMLButtonElement, MouseEvent>, score: number) {
30 e.preventDefault();
31 setComment("");
32 await sendFeedback(score);
33 }
34
35 async function handleCommentSubmission(e: FormEvent<HTMLFormElement>) {
36 e.preventDefault();
37 const score = typeof feedback?.score === "number" ? feedback.score : 0;
38 await sendFeedback(score);
39 }
40
41 async function sendFeedback(score: number) {
42 if (isLoading) {
43 return;
44 }
45
46 setIsLoading(true);
47
48 const response = await fetch("api/feedback", {
49 method: feedback?.id ? "PUT" : "POST",
50 body: JSON.stringify({
51 id: feedback?.id,
52 run_id: runId,
53 score,
54 comment,
55 })
56 });
57
58 const json = await response.json();
59
60 if (json.error) {
61 toast(json.error, {
62 theme: "dark"
63 });
64 return;
65 } else if (feedback?.id && comment) {
66 toast("Response recorded! Go to https://smith.langchain.com and check it out in under your run's \"Feedback\" pane.", {
67 theme: "dark",
68 autoClose: 3000,

Callers

nothing calls this directly

Calls 1

handleScoreButtonPressFunction · 0.85

Tested by

no test coverage detected