Skip to content
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

added reasoning to labeling queues #200

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const removeQueueItemSchema = z.object({
labelClass: z.object({
name: z.string(),
id: z.string()
})
}),
reasoning: z.string().optional()
})),
action: z.object({
resultId: z.string().optional()
Expand All @@ -43,16 +44,16 @@ export async function POST(request: Request, { params }: { params: { projectId:
});

// adding new labels to the span
const newLabels = addedLabels.map(({ value, labelClass }) => ({
const newLabels = addedLabels.map(({ value, labelClass, reasoning }) => ({
value: value,
classId: labelClass.id,
spanId,
reasoning,
labelSource: "MANUAL" as const,
}));

await db.insert(labels).values(newLabels);


const resultId = action.resultId;

// create new results in batch
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

--radius: 0.5rem; */

--background: 0 0% 8%;
--background: 0 0% 4%;
--foreground: 0 8% 90%;

--card: 240 4% 12%;
Expand Down
41 changes: 26 additions & 15 deletions frontend/components/queue/queue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ScrollArea } from '../ui/scroll-area';
import { isChatMessageList } from '@/lib/flow/utils';
import ChatMessageListTab from '../traces/chat-message-list-tab';
import Formatter from '../ui/formatter';
import DefaultTextarea from '../ui/default-textarea';

interface QueueProps {
queue: LabelingQueue;
Expand All @@ -31,7 +32,7 @@ export default function Queue({ queue }: QueueProps) {
} | null>(null);

const [isRemoving, setIsRemoving] = useState(false);
const [addedLabels, setAddedLabels] = useState<Array<{ value: number, labelClass: LabelClass }>>([]);
const [addedLabels, setAddedLabels] = useState<Array<{ value: number, labelClass: LabelClass, reasoning?: string | null }>>([]);

const next = (refDate: string, direction: 'next' | 'prev' = 'next') => {
fetch(`/api/projects/${projectId}/queues/${queue.id}/move`, {
Expand Down Expand Up @@ -74,8 +75,6 @@ export default function Queue({ queue }: QueueProps) {
next((new Date(0)).toUTCString());
}, []);

console.log(addedLabels);

return (
<div className="flex flex-col w-full h-full">
<div className="flex-none">
Expand Down Expand Up @@ -156,18 +155,30 @@ export default function Queue({ queue }: QueueProps) {
<Label className="text-sm text-secondary-foreground">Labels to be added to the span</Label>
<div className="mt-4 space-y-2">
{addedLabels.map((label, index) => (
<div key={index} className="flex items-center justify-between p-2 border border-foreground/10 bg-muted rounded">
<span>{Object.entries(label.labelClass.valueMap).find(([key, value]) => value === label.value)?.[0]}</span>
<div key={index} className="flex flex-col p-2 border border-foreground/10 bg-muted rounded gap-2">
<div className="flex items-center gap-2 justify-between w-full">
<span>{Object.entries(label.labelClass.valueMap).find(([key, value]) => value === label.value)?.[0]}</span>
<div className="flex items-center gap-2">
<span className="text-sm text-muted-foreground">{label.labelClass.name}</span>
<Button
variant="ghost"
size="sm"
onClick={() => removeLabel(index)}
className="h-6 px-2"
>
<X size={14} />
</Button>
</div>
</div>
<div className="flex items-center gap-2">
<span className="text-sm text-muted-foreground">{label.labelClass.name}</span>
<Button
variant="ghost"
size="sm"
onClick={() => removeLabel(index)}
className="h-6 px-2"
>
<X size={14} />
</Button>
<DefaultTextarea
className="w-full"
placeholder="Reasoning (optional)"
value={label.reasoning || ''}
onChange={(e) => {
setAddedLabels(prev => prev.map(l => l.labelClass.id === label.labelClass.id ? { ...l, reasoning: e.target.value } : l));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using labelClass.id for updates can lead to incorrect behavior if there are multiple labels with the same labelClass.id. Consider using the index for updates instead.

Suggested change
setAddedLabels(prev => prev.map(l => l.labelClass.id === label.labelClass.id ? { ...l, reasoning: e.target.value } : l));
setAddedLabels(prev => prev.map((l, i) => i === index ? { ...l, reasoning: e.target.value } : l));

}}
/>
</div>
</div>
))}
Expand All @@ -182,7 +193,7 @@ export default function Queue({ queue }: QueueProps) {
label => label.labelClass.id === labelClass.id
);
if (!isDuplicateClass) {
setAddedLabels(prev => [...prev, { value, labelClass }]);
setAddedLabels(prev => [...prev, { value, labelClass, reasoning: null }]);
}
}}
/>
Expand Down