From 3fa8ebf23d6f87ad2b45b85fcc71b36f7b61ad17 Mon Sep 17 00:00:00 2001 From: Griffin Tarpenning Date: Tue, 19 Nov 2024 14:53:30 -0800 Subject: [PATCH] chore(weave): human annotation labeling review comments (#3020) --- .../StructuredFeedback/FeedbackSidebar.tsx | 41 +++++++++++++++++- .../StructuredFeedback/HumanAnnotation.tsx | 39 +++++++++++------ .../humanAnnotationTypes.ts | 8 +++- .../StructuredFeedback/tsHumanFeedback.ts | 35 ++++++++------- .../Home/Browse3/pages/CallPage/CallPage.tsx | 21 +++++---- .../pages/CallPage/PaginationControls.tsx | 41 ++++++++++++++---- .../pages/CallsPage/callsTableColumns.tsx | 3 ++ .../ScorersPage/AnnotationScorerForm.tsx | 21 ++++++--- .../pages/ScorersPage/NewScorerDrawer.tsx | 1 + .../src/integrations/analytics/viewEvents.ts | 43 +++++++++++++++++++ 10 files changed, 194 insertions(+), 59 deletions(-) diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/FeedbackSidebar.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/FeedbackSidebar.tsx index 249a2335704..a593f79b9ac 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/FeedbackSidebar.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/FeedbackSidebar.tsx @@ -1,9 +1,13 @@ import {toast} from '@wandb/weave/common/components/elements/Toast'; +import {useOrgName} from '@wandb/weave/common/hooks/useOrganization'; import {useViewerInfo} from '@wandb/weave/common/hooks/useViewerInfo'; +import {useViewerUserInfo2} from '@wandb/weave/common/hooks/useViewerUserInfo'; import {Button} from '@wandb/weave/components/Button'; import {Icon} from '@wandb/weave/components/Icon'; +import {Loading} from '@wandb/weave/components/Loading'; +import {annotationsViewed} from '@wandb/weave/integrations/analytics/viewEvents'; import {makeRefCall} from '@wandb/weave/util/refs'; -import React, {useState} from 'react'; +import React, {useEffect, useState} from 'react'; import {useHistory} from 'react-router-dom'; import {useWeaveflowRouteContext} from '../../context'; @@ -14,6 +18,7 @@ import {tsHumanAnnotationSpec} from './humanAnnotationTypes'; type FeedbackSidebarProps = { humanAnnotationSpecs: tsHumanAnnotationSpec[]; + specsLoading: boolean; callID: string; entity: string; project: string; @@ -21,6 +26,7 @@ type FeedbackSidebarProps = { export const FeedbackSidebar = ({ humanAnnotationSpecs, + specsLoading, callID, entity, project, @@ -32,6 +38,11 @@ export const FeedbackSidebar = ({ Record Promise> >({}); + const {loading: viewerLoading, userInfo} = useViewerUserInfo2(); + const {loading: orgNameLoading, orgName} = useOrgName({ + entityName: entity, + }); + const save = async () => { setIsSaving(true); try { @@ -58,6 +69,28 @@ export const FeedbackSidebar = ({ } }; + useEffect(() => { + if (!viewerLoading && !orgNameLoading) { + annotationsViewed({ + traceId: callID, + userId: userInfo.id, + organizationName: orgName, + entityName: entity, + projectName: project, + numAnnotationSpecs: humanAnnotationSpecs.length, + }); + } + }, [ + viewerLoading, + orgNameLoading, + userInfo, + orgName, + entity, + project, + humanAnnotationSpecs.length, + callID, + ]); + return (
@@ -75,7 +108,7 @@ export const FeedbackSidebar = ({ setUnsavedFeedbackChanges={setUnsavedFeedbackChanges} />
-
+
+ ) : specsLoading ? ( +
+ +
) : (
diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/HumanAnnotation.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/HumanAnnotation.tsx index 9a1d1438786..66838942c03 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/HumanAnnotation.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/HumanAnnotation.tsx @@ -167,7 +167,7 @@ const FeedbackComponentSelector: React.FC<{ jsonSchema: Record; focused: boolean; onAddFeedback: (value: any) => Promise; - foundValue: string | number | null; + foundValue: string | number | boolean | null; feedbackSpecRef: string; setUnsavedFeedbackChanges: React.Dispatch< React.SetStateAction Promise>> @@ -194,12 +194,23 @@ const FeedbackComponentSelector: React.FC<{ ); switch (type) { + case 'integer': + return ( + + ); case 'number': return ( ); @@ -513,35 +524,35 @@ export const BinaryFeedbackColumn = ({ defaultValue, focused, }: { - onAddFeedback?: (value: string) => Promise; - defaultValue: string | null; + onAddFeedback?: (value: any) => Promise; + defaultValue: boolean | null; focused?: boolean; }) => { - const [value, setValue] = useState(defaultValue); + const [value, setValue] = useState(defaultValue); useEffect(() => { setValue(defaultValue); }, [defaultValue]); - const handleClick = (newValue: string) => { + const handleClick = (newValue: boolean) => { // If clicking the same value, deselect it const valueToSet = value === newValue ? null : newValue; setValue(valueToSet); - onAddFeedback?.(valueToSet ?? ''); + onAddFeedback?.(valueToSet); }; return (
diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/humanAnnotationTypes.ts b/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/humanAnnotationTypes.ts index 43b58c759d6..8d3a89e9d24 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/humanAnnotationTypes.ts +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/humanAnnotationTypes.ts @@ -2,7 +2,13 @@ import {AnnotationSpec} from '../../pages/wfReactInterface/generatedBaseObjectCl import {Feedback} from '../../pages/wfReactInterface/traceServerClientTypes'; export const HUMAN_ANNOTATION_BASE_TYPE = 'wandb.annotation'; -export const FEEDBACK_TYPE_OPTIONS = ['string', 'number', 'boolean', 'enum']; +export const FEEDBACK_TYPE_OPTIONS = [ + 'string', + 'number', + 'boolean', + 'enum', + 'integer', +]; export type FeedbackSchemaType = (typeof FEEDBACK_TYPE_OPTIONS)[number]; export const makeAnnotationFeedbackType = (type: string) => diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/tsHumanFeedback.ts b/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/tsHumanFeedback.ts index e6ebabd1b73..6460d474b15 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/tsHumanFeedback.ts +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/tsHumanFeedback.ts @@ -12,7 +12,7 @@ import {tsHumanAnnotationSpec} from './humanAnnotationTypes'; export const useHumanAnnotationSpecs = ( entity: string, project: string -): tsHumanAnnotationSpec[] => { +): {humanAnnotationSpecs: tsHumanAnnotationSpec[]; specsLoading: boolean} => { const req: TraceObjQueryReq = { project_id: projectIdFromParts({entity, project}), filter: { @@ -31,20 +31,23 @@ export const useHumanAnnotationSpecs = ( return useMemo(() => { if (cols == null) { - return []; + return {humanAnnotationSpecs: [], specsLoading: res.loading}; } - return cols.map(col => ({ - ...col.val, - // attach object refs to the columns - ref: objectVersionKeyToRefUri({ - scheme: 'weave', - weaveKind: 'object', - entity, - project, - objectId: col.object_id, - versionHash: col.digest, - path: '', - }), - })); - }, [cols, entity, project]); + return { + humanAnnotationSpecs: cols.map(col => ({ + ...col.val, + // attach object refs to the columns + ref: objectVersionKeyToRefUri({ + scheme: 'weave', + weaveKind: 'object', + entity, + project, + objectId: col.object_id, + versionHash: col.digest, + path: '', + }), + })), + specsLoading: res.loading, + }; + }, [cols, entity, project, res.loading]); }; diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CallPage/CallPage.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CallPage/CallPage.tsx index d674ae48975..7bf7b17f4bf 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CallPage/CallPage.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CallPage/CallPage.tsx @@ -223,7 +223,7 @@ const CallPageInnerVertical: FC<{ ) ); }, [currentRouter, history, path, showTraceTree, call, showFeedbackExpand]); - const humanAnnotationSpecs = useHumanAnnotationSpecs( + const {humanAnnotationSpecs, specsLoading} = useHumanAnnotationSpecs( call.entity, call.project ); @@ -275,16 +275,6 @@ const CallPageInnerVertical: FC<{ )} -