-
Notifications
You must be signed in to change notification settings - Fork 0
Add feedback popover with comment for AI responses #31
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ac7bc91
feat: add feedback popover for capturing comment with langfuse score
google-labs-jules[bot] a816efc
feat: add feedback popover for capturing comment with langfuse score
google-labs-jules[bot] 9d386ec
feat: add feedback popover for capturing comment with langfuse score
google-labs-jules[bot] 691654f
feat: show thumbs-up/down specific feedback options in popover
MrOrz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { useState } from 'react' | ||
| import { Checkbox } from './ui/checkbox' | ||
| import { Textarea } from './ui/textarea' | ||
| import { Button } from './ui/button' | ||
|
|
||
| const POSITIVE_OPTIONS = ['語氣適合', '篇幅適中', '出處精準', '具有說服力'] | ||
|
|
||
| const NEGATIVE_OPTIONS = [ | ||
| '篇幅過長', | ||
| '篇幅過短', | ||
| '沒抓到重點', | ||
| '出處不足', | ||
| '回應文字與出處不符', | ||
| '提供不存在的出處', | ||
| '出處摘要錯誤', | ||
| ] | ||
|
|
||
| interface FeedbackPopoverContentProps { | ||
| isPositive: boolean | ||
| onSubmit: (comment: string) => void | ||
| } | ||
|
|
||
| export function FeedbackPopoverContent({ | ||
| isPositive, | ||
| onSubmit, | ||
| }: FeedbackPopoverContentProps) { | ||
| const options = isPositive ? POSITIVE_OPTIONS : NEGATIVE_OPTIONS | ||
| const [selectedOptions, setSelectedOptions] = useState<Set<string>>(new Set()) | ||
| const [comment, setComment] = useState('') | ||
|
|
||
| const handleToggleOption = (option: string) => { | ||
| const newOptions = new Set(selectedOptions) | ||
| if (newOptions.has(option)) { | ||
| newOptions.delete(option) | ||
| } else { | ||
| newOptions.add(option) | ||
| } | ||
| setSelectedOptions(newOptions) | ||
| } | ||
|
|
||
| const handleSubmit = () => { | ||
| let finalComment = '' | ||
| selectedOptions.forEach((opt) => { | ||
| finalComment += `☑ ${opt}\n` | ||
| }) | ||
| if (comment.trim()) { | ||
| finalComment += comment.trim() | ||
| } | ||
| onSubmit(finalComment.trim()) | ||
| } | ||
|
|
||
| return ( | ||
| <div className="flex flex-col gap-4"> | ||
| <div className="flex flex-col gap-2"> | ||
| <h4 className="font-medium text-sm">Tell us more</h4> | ||
| {options.map((option) => ( | ||
| <label | ||
| key={option} | ||
| className="flex items-center gap-2 cursor-pointer text-sm" | ||
| > | ||
| <Checkbox | ||
| checked={selectedOptions.has(option)} | ||
| onCheckedChange={() => handleToggleOption(option)} | ||
| /> | ||
| {option} | ||
| </label> | ||
| ))} | ||
| </div> | ||
| <Textarea | ||
| placeholder="Additional comments..." | ||
| value={comment} | ||
| onChange={(e) => setComment(e.target.value)} | ||
| className="min-h-[80px]" | ||
| /> | ||
| <Button onClick={handleSubmit} size="sm"> | ||
| Submit | ||
| </Button> | ||
| </div> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| "use client" | ||
|
|
||
| import { Checkbox as CheckboxPrimitive } from "@base-ui/react/checkbox" | ||
|
|
||
| import { CheckIcon } from "lucide-react" | ||
| import { cn } from "@/lib/utils" | ||
|
|
||
| function Checkbox({ className, ...props }: CheckboxPrimitive.Root.Props) { | ||
| return ( | ||
| <CheckboxPrimitive.Root | ||
| data-slot="checkbox" | ||
| className={cn( | ||
| "peer relative flex size-4 shrink-0 items-center justify-center rounded-[6px] border border-input transition-shadow outline-none group-has-disabled/field:opacity-50 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-[3px] aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground dark:data-checked:bg-primary", | ||
| className | ||
| )} | ||
| {...props} | ||
| > | ||
| <CheckboxPrimitive.Indicator | ||
| data-slot="checkbox-indicator" | ||
| className="grid place-content-center text-current transition-none [&>svg]:size-3.5" | ||
| > | ||
| <CheckIcon | ||
| /> | ||
| </CheckboxPrimitive.Indicator> | ||
| </CheckboxPrimitive.Root> | ||
| ) | ||
| } | ||
|
|
||
| export { Checkbox } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import * as React from "react" | ||
| import { Popover as PopoverPrimitive } from "@base-ui/react/popover" | ||
|
|
||
| import { cn } from "@/lib/utils" | ||
|
|
||
| function Popover({ ...props }: PopoverPrimitive.Root.Props) { | ||
| return <PopoverPrimitive.Root data-slot="popover" {...props} /> | ||
| } | ||
|
|
||
| function PopoverTrigger({ ...props }: PopoverPrimitive.Trigger.Props) { | ||
| return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} /> | ||
| } | ||
|
|
||
| function PopoverContent({ | ||
|
MrOrz marked this conversation as resolved.
|
||
| className, | ||
| align = "center", | ||
| alignOffset = 0, | ||
| side = "bottom", | ||
| sideOffset = 4, | ||
| ...props | ||
| }: PopoverPrimitive.Popup.Props & | ||
| Pick< | ||
| PopoverPrimitive.Positioner.Props, | ||
| "align" | "alignOffset" | "side" | "sideOffset" | ||
| >) { | ||
|
MrOrz marked this conversation as resolved.
|
||
| return ( | ||
| <PopoverPrimitive.Portal> | ||
| <PopoverPrimitive.Positioner | ||
| align={align} | ||
| alignOffset={alignOffset} | ||
| side={side} | ||
| sideOffset={sideOffset} | ||
| className="isolate z-50" | ||
| > | ||
| <PopoverPrimitive.Popup | ||
| data-slot="popover-content" | ||
| className={cn( | ||
| "z-50 flex w-72 origin-(--transform-origin) flex-col gap-4 rounded-2xl bg-popover p-4 text-sm text-popover-foreground shadow-2xl ring-1 ring-foreground/5 outline-hidden duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", | ||
| className | ||
| )} | ||
| {...props} | ||
| /> | ||
| </PopoverPrimitive.Positioner> | ||
| </PopoverPrimitive.Portal> | ||
| ) | ||
| } | ||
|
|
||
| function PopoverHeader({ className, ...props }: React.ComponentProps<"div">) { | ||
| return ( | ||
| <div | ||
| data-slot="popover-header" | ||
| className={cn("flex flex-col gap-1 text-sm", className)} | ||
| {...props} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| function PopoverTitle({ className, ...props }: PopoverPrimitive.Title.Props) { | ||
| return ( | ||
| <PopoverPrimitive.Title | ||
| data-slot="popover-title" | ||
| className={cn("text-base font-medium", className)} | ||
| {...props} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| function PopoverDescription({ | ||
| className, | ||
| ...props | ||
| }: PopoverPrimitive.Description.Props) { | ||
| return ( | ||
| <PopoverPrimitive.Description | ||
| data-slot="popover-description" | ||
| className={cn("text-muted-foreground", className)} | ||
| {...props} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| export { | ||
| Popover, | ||
| PopoverContent, | ||
| PopoverDescription, | ||
| PopoverHeader, | ||
| PopoverTitle, | ||
| PopoverTrigger, | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.