-
Notifications
You must be signed in to change notification settings - Fork 450
feat: add feedback tracking for assistant messages #1597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
607cf12
2367913
3f3f3a5
7166765
102a4b1
924bde9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { ThumbsDown, ThumbsUp } from "lucide-react"; | ||
| import { useState } from "react"; | ||
| import { Button } from "@/components/ui/button"; | ||
|
|
||
| interface MessageActionsProps { | ||
| trackFeedback: (feedback: "like" | "dislike") => void; | ||
| } | ||
|
|
||
| const MessageActions = ({ trackFeedback }: MessageActionsProps) => { | ||
| const [feedbackSelected, setFeedbackSelected] = useState< | ||
| "like" | "dislike" | null | ||
| >(null); | ||
|
|
||
| const handleFeedback = (feedback: "like" | "dislike") => { | ||
| if (feedbackSelected === feedback) return; // Prevent multiple tracking events for the same feedback | ||
| trackFeedback(feedback); | ||
| setFeedbackSelected(feedback); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="flex space-x-2 mt-2"> | ||
| <Button | ||
| variant="ghost" | ||
| size="icon" | ||
| aria-label="Like" | ||
| aria-pressed={feedbackSelected === "like"} | ||
| className={ | ||
| feedbackSelected !== "like" | ||
| ? "text-muted-foreground hover:text-foreground" | ||
| : "" | ||
| } | ||
| onClick={() => handleFeedback("like")} | ||
| > | ||
| <ThumbsUp | ||
| className={`h-4 w-4 ${feedbackSelected === "like" ? "fill-current" : ""}`} | ||
| /> | ||
| </Button> | ||
| <Button | ||
| variant="ghost" | ||
| size="icon" | ||
| aria-label="Dislike" | ||
| aria-pressed={feedbackSelected === "dislike"} | ||
| className={ | ||
| feedbackSelected !== "dislike" | ||
| ? "text-muted-foreground hover:text-foreground" | ||
| : "" | ||
| } | ||
| onClick={() => handleFeedback("dislike")} | ||
| > | ||
| <ThumbsDown | ||
| className={`h-4 w-4 ${feedbackSelected === "dislike" ? "fill-current" : ""}`} | ||
| /> | ||
| </Button> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default MessageActions; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ import type { | |
| RequestBody, | ||
| ToolCallResult, | ||
| } from "./_types/types"; | ||
| import { INITIAL_ASSISTANT_MESSAGE } from "./_types/types"; | ||
|
|
||
| function ChatPage() { | ||
| const isDebugMode = process.env.NEXT_PUBLIC_OPENRAG_DEBUG === "true"; | ||
|
|
@@ -52,11 +53,7 @@ function ChatPage() { | |
| setConversationFilter, | ||
| } = useChat(); | ||
| const [messages, setMessages] = useState<Message[]>([ | ||
| { | ||
| role: "assistant", | ||
| content: "How can I assist?", | ||
| timestamp: new Date(), | ||
| }, | ||
| INITIAL_ASSISTANT_MESSAGE, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check the INITIAL_ASSISTANT_MESSAGE definition to see if timestamp is static or dynamic
rg -A 5 -B 2 'INITIAL_ASSISTANT_MESSAGE\s*=' frontend/app/chat/_types/types.tsRepository: langflow-ai/openrag Length of output: 45 🏁 Script executed: #!/bin/bash
# Search for INITIAL_ASSISTANT_MESSAGE definition across the frontend
rg 'INITIAL_ASSISTANT_MESSAGE\s*=' frontend/ --type ts --type tsx -A 8Repository: langflow-ai/openrag Length of output: 91 🏁 Script executed: #!/bin/bash
# Also search for where it's imported from in page.tsx
rg 'import.*INITIAL_ASSISTANT_MESSAGE' frontend/app/chat/page.tsx -B 2 -A 2Repository: langflow-ai/openrag Length of output: 189 🏁 Script executed: #!/bin/bash
# Check the structure of the page.tsx file at the mentioned lines
sed -n '50,70p' frontend/app/chat/page.tsx
sed -n '320,335p' frontend/app/chat/page.tsx
sed -n '560,575p' frontend/app/chat/page.tsxRepository: langflow-ai/openrag Length of output: 2087 🏁 Script executed: #!/bin/bash
# Read the types.ts file to find INITIAL_ASSISTANT_MESSAGE definition
cat frontend/app/chat/_types/types.tsRepository: langflow-ai/openrag Length of output: 1728 🏁 Script executed: #!/bin/bash
# Also check the chat-context.tsx implementation mentioned in the review
rg -B 5 -A 5 'new Date().toISOString()' frontend/app/chat/Repository: langflow-ai/openrag Length of output: 45 🏁 Script executed: #!/bin/bash
# Find chat-context.tsx
fd 'chat-context' frontend/ --type fRepository: langflow-ai/openrag Length of output: 98 🏁 Script executed: #!/bin/bash
# Check line 347 area and message initialization in chat-context
rg 'const createMessage|content.*timestamp|new Date' frontend/app/chat/chat-context.tsx -B 3 -A 3Repository: langflow-ai/openrag Length of output: 138 🏁 Script executed: #!/bin/bash
# Check the correct chat-context.tsx location
rg 'INITIAL_ASSISTANT_MESSAGE|new Date' frontend/contexts/chat-context.tsx -B 3 -A 3Repository: langflow-ai/openrag Length of output: 809 🏁 Script executed: #!/bin/bash
# Also search for any message creation patterns around line 347 or nearby
sed -n '340,360p' frontend/contexts/chat-context.tsxRepository: langflow-ai/openrag Length of output: 719 Create fresh timestamps when resetting to INITIAL_ASSISTANT_MESSAGE instead of reusing the stale module-level timestamp. The The pattern in Proposed fix-const [messages, setMessages] = useState<Message[]>([
- INITIAL_ASSISTANT_MESSAGE,
-]);
+const [messages, setMessages] = useState<Message[]>([
+ { ...INITIAL_ASSISTANT_MESSAGE, timestamp: new Date() },
+]);And similarly for lines 328 and 566: -setMessages([INITIAL_ASSISTANT_MESSAGE]);
+setMessages([{ ...INITIAL_ASSISTANT_MESSAGE, timestamp: new Date() }]);Also applies to: 328-328, 566-566 🤖 Prompt for AI Agents |
||
| ]); | ||
| const [input, setInput] = useState(""); | ||
| const { loading, setLoading } = useLoadingStore(); | ||
|
|
@@ -328,13 +325,7 @@ function ChatPage() { | |
| // Abort any in-flight streaming so it doesn't bleed into new chat | ||
| abortStream(); | ||
| // Reset chat UI even if context state was already 'new' | ||
| setMessages([ | ||
| { | ||
| role: "assistant", | ||
| content: "How can I assist?", | ||
| timestamp: new Date(), | ||
| }, | ||
| ]); | ||
| setMessages([INITIAL_ASSISTANT_MESSAGE]); | ||
| setInput(""); | ||
| setExpandedFunctionCalls(new Set()); | ||
| setIsFilterHighlighted(false); | ||
|
|
@@ -572,13 +563,7 @@ function ChatPage() { | |
| useEffect(() => { | ||
| if (placeholderConversation && currentConversationId === null) { | ||
| console.log("Starting new conversation"); | ||
| setMessages([ | ||
| { | ||
| role: "assistant", | ||
| content: "How can I assist?", | ||
| timestamp: new Date(), | ||
| }, | ||
| ]); | ||
| setMessages([INITIAL_ASSISTANT_MESSAGE]); | ||
| lastLoadedConversationRef.current = null; | ||
|
|
||
| // Focus input when starting a new conversation | ||
|
|
@@ -1142,9 +1127,11 @@ function ChatPage() { | |
| isInitialGreeting={ | ||
| index === 0 && | ||
| messages.length === 1 && | ||
| message.content === "How can I assist?" | ||
| message.content === | ||
| INITIAL_ASSISTANT_MESSAGE.content | ||
| } | ||
| usage={message.usage} | ||
| timestamp={message.timestamp} | ||
| /> | ||
| )} | ||
| </div> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.