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

chore: add column selection in eval comparison page #2632

Merged
merged 9 commits into from
Oct 10, 2024
18 changes: 18 additions & 0 deletions weave-js/src/components/PagePanelComponents/Home/Browse3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -921,16 +921,34 @@ const OpPageBinding = () => {
};

const CompareEvaluationsBinding = () => {
const history = useHistory();
const location = useLocation();
const {entity, project} = useParamsDecoded<Browse3TabParams>();
const query = useURLSearchParamsDict();
const evaluationCallIds = useMemo(() => {
return JSON.parse(query.evaluationCallIds);
}, [query.evaluationCallIds]);

const selectedMetrics: Record<string, boolean> | null = useMemo(() => {
try {
return JSON.parse(query.metrics);
} catch (e) {
return null;
}
}, [query.metrics]);

const setSelectedMetrics = (newModel: Record<string, boolean>) => {
const newQuery = new URLSearchParams(location.search);
newQuery.set('metrics', JSON.stringify(newModel));
history.push({search: newQuery.toString()});
};
return (
<CompareEvaluationsPage
entity={entity}
project={project}
evaluationCallIds={evaluationCallIds}
selectedMetrics={selectedMetrics}
setSelectedMetrics={setSelectedMetrics}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ const useCallTabs = (call: CallSchema) => {
entity={call.entity}
project={call.project}
evaluationCallIds={[call.callId]}
selectedMetrics={{}}
setSelectedMetrics={() => {}}
/>
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type CompareEvaluationsPageProps = {
entity: string;
project: string;
evaluationCallIds: string[];
selectedMetrics: Record<string, boolean> | null;
setSelectedMetrics: (newModel: Record<string, boolean>) => void;
};

export const CompareEvaluationsPage: React.FC<
Expand All @@ -55,6 +57,8 @@ export const CompareEvaluationsPage: React.FC<
entity={props.entity}
project={props.project}
evaluationCallIds={props.evaluationCallIds}
selectedMetrics={props.selectedMetrics}
setSelectedMetrics={props.setSelectedMetrics}
/>
),
},
Expand Down Expand Up @@ -109,6 +113,8 @@ export const CompareEvaluationsPageContent: React.FC<
entity={props.entity}
project={props.project}
evaluationCallIds={props.evaluationCallIds}
selectedMetrics={props.selectedMetrics}
setSelectedMetrics={props.setSelectedMetrics}
baselineEvaluationCallId={baselineEvaluationCallId ?? undefined}
comparisonDimensions={comparisonDimensions ?? undefined}
setBaselineEvaluationCallId={setBaselineEvaluationCallId}
Expand Down Expand Up @@ -174,7 +180,7 @@ const ReturnToEvaluationsButton: FC<{entity: string; project: string}> = ({
const CompareEvaluationsPageInner: React.FC<{
height: number;
}> = props => {
const {state} = useCompareEvaluationsState();
const {state, setSelectedMetrics} = useCompareEvaluationsState();
const showExampleFilter =
Object.keys(state.data.evaluationCalls).length === 2;
const showExamples = Object.keys(state.data.resultRows).length > 0;
Expand All @@ -195,7 +201,7 @@ const CompareEvaluationsPageInner: React.FC<{
evaluationCalls={Object.values(state.data.evaluationCalls)}
/>
<ComparisonDefinitionSection state={state} />
<SummaryPlots state={state} />
<SummaryPlots state={state} setSelectedMetrics={setSelectedMetrics} />
<ScorecardSection state={state} />
{showExamples ? (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const CompareEvaluationsContext = React.createContext<{
React.SetStateAction<ComparisonDimensionsType | null>
>;
setSelectedInputDigest: React.Dispatch<React.SetStateAction<string | null>>;
setSelectedMetrics: (newModel: Record<string, boolean>) => void;
} | null>(null);

export const useCompareEvaluationsState = () => {
Expand All @@ -30,6 +31,9 @@ export const CompareEvaluationsProvider: React.FC<{
entity: string;
project: string;
evaluationCallIds: string[];
selectedMetrics: Record<string, boolean> | null;
setSelectedMetrics: (newModel: Record<string, boolean>) => void;

setBaselineEvaluationCallId: React.Dispatch<
React.SetStateAction<string | null>
>;
Expand All @@ -44,11 +48,13 @@ export const CompareEvaluationsProvider: React.FC<{
entity,
project,
evaluationCallIds,
selectedMetrics,
setSelectedMetrics,

setBaselineEvaluationCallId,
setComparisonDimensions,

setSelectedInputDigest,

baselineEvaluationCallId,
comparisonDimensions,
selectedInputDigest,
Expand All @@ -60,7 +66,8 @@ export const CompareEvaluationsProvider: React.FC<{
evaluationCallIds,
baselineEvaluationCallId,
comparisonDimensions,
selectedInputDigest
selectedInputDigest,
selectedMetrics ?? undefined
);

const value = useMemo(() => {
Expand All @@ -72,13 +79,15 @@ export const CompareEvaluationsProvider: React.FC<{
setBaselineEvaluationCallId,
setComparisonDimensions,
setSelectedInputDigest,
setSelectedMetrics,
};
}, [
initialState.loading,
initialState.result,
setBaselineEvaluationCallId,
setComparisonDimensions,
setSelectedInputDigest,
setSelectedMetrics,
]);

if (!value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export type CompositeSummaryMetricGroupForKeyPath = {
*/
export const buildCompositeMetricsMap = (
data: EvaluationComparisonData,
mType: MetricType
mType: MetricType,
selectedMetrics: Record<string, boolean> | undefined = undefined
): CompositeScoreMetrics => {
const composite: CompositeScoreMetrics = {};

Expand All @@ -93,6 +94,12 @@ export const buildCompositeMetricsMap = (
Object.entries(metricDefinitionMap).forEach(([metricId, metric]) => {
const groupName = groupNameForMetric(metric);
const ref = refForMetric(metric);
const keyPath = flattenedDimensionPath(metric);

if (selectedMetrics && !selectedMetrics[keyPath]) {
// Skip metrics that are not in the selectedMetrics map
return;
}

if (!composite[groupName]) {
composite[groupName] = {
Expand All @@ -105,8 +112,6 @@ export const buildCompositeMetricsMap = (
metricGroup.scorerRefs.push(ref);
}

const keyPath = flattenedDimensionPath(metric);

if (!metricGroup.metrics[keyPath]) {
metricGroup.metrics[keyPath] = {
scorerAgnosticMetricDef: _.omit(metric, 'scorerOpOrObjRef'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export type EvaluationComparisonState = {
comparisonDimensions?: ComparisonDimensionsType;
// The current digest which is in view
selectedInputDigest?: string;
// The selected metrics to display
selectedMetrics?: Record<string, boolean>;
};

export type ComparisonDimensionsType = Array<{
Expand All @@ -43,7 +45,8 @@ export const useEvaluationComparisonState = (
evaluationCallIds: string[],
baselineEvaluationCallId?: string,
comparisonDimensions?: ComparisonDimensionsType,
selectedInputDigest?: string
selectedInputDigest?: string,
selectedMetrics?: Record<string, boolean>
): Loadable<EvaluationComparisonState> => {
const data = useEvaluationComparisonData(entity, project, evaluationCallIds);

Expand Down Expand Up @@ -93,6 +96,7 @@ export const useEvaluationComparisonState = (
baselineEvaluationCallId ?? evaluationCallIds[0],
comparisonDimensions: newComparisonDimensions,
selectedInputDigest,
selectedMetrics,
},
};
}, [
Expand All @@ -102,6 +106,7 @@ export const useEvaluationComparisonState = (
evaluationCallIds,
comparisonDimensions,
selectedInputDigest,
selectedMetrics,
]);

return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,13 @@ export const ExampleCompareSection: React.FC<{
const {ref1, ref2} = useLinkHorizontalScroll();

const compositeScoreMetrics = useMemo(
() => buildCompositeMetricsMap(props.state.data, 'score'),
[props.state.data]
() =>
buildCompositeMetricsMap(
props.state.data,
'score',
props.state.selectedMetrics
),
[props.state.data, props.state.selectedMetrics]
);

if (target == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ const rowIsSelected = (
export const useFilteredAggregateRows = (state: EvaluationComparisonState) => {
const leafDims = useMemo(() => getOrderedCallIds(state), [state]);
const compositeMetricsMap = useMemo(
() => buildCompositeMetricsMap(state.data, 'score'),
[state.data]
() => buildCompositeMetricsMap(state.data, 'score', state.selectedMetrics),
[state.data, state.selectedMetrics]
);

const flattenedRows = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ export const ScorecardSection: React.FC<{
const [diffOnly, setDiffOnly] = React.useState(true);

const compositeSummaryMetrics = useMemo(() => {
return buildCompositeMetricsMap(props.state.data, 'summary');
return buildCompositeMetricsMap(
props.state.data,
'summary',
props.state.selectedMetrics
);
}, [props.state]);

const onCallClick = usePeekCall(
Expand Down
Loading
Loading