From f26455c9f53208ea40667979620c1abf65c2e938 Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Tue, 16 Jan 2024 08:34:12 +0100 Subject: [PATCH 1/3] added notes and expected answer to csv export and made input column dynamic --- .../ABTestingEvaluationTable.tsx | 8 +++- .../SingleModelEvaluationTable.tsx | 8 +++- agenta-web/src/lib/helpers/evaluate.ts | 42 +++++++++++++++---- 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx index 6b16833414..8ddd477498 100644 --- a/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx @@ -387,7 +387,13 @@ const ABTestingEvaluationTable: React.FC = ({ Run All exportABTestingEvaluationData(evaluation, rows)} + onClick={() => + exportABTestingEvaluationData( + evaluation, + evaluationScenarios, + rows, + ) + } disabled={evaluationStatus !== EvaluationFlow.EVALUATION_FINISHED} > Export results diff --git a/agenta-web/src/components/EvaluationTable/SingleModelEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/SingleModelEvaluationTable.tsx index 8770a6d6b0..e3b96acbe0 100644 --- a/agenta-web/src/components/EvaluationTable/SingleModelEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/SingleModelEvaluationTable.tsx @@ -454,7 +454,13 @@ const SingleModelEvaluationTable: React.FC = ({ Run All exportSingleModelEvaluationData(evaluation, rows)} + onClick={() => + exportSingleModelEvaluationData( + evaluation, + evaluationScenarios, + rows, + ) + } disabled={evaluationStatus !== EvaluationFlow.EVALUATION_FINISHED} > Export results diff --git a/agenta-web/src/lib/helpers/evaluate.ts b/agenta-web/src/lib/helpers/evaluate.ts index fb1b932da6..594d6befd0 100644 --- a/agenta-web/src/lib/helpers/evaluate.ts +++ b/agenta-web/src/lib/helpers/evaluate.ts @@ -1,13 +1,22 @@ import {HumanEvaluationListTableDataType} from "@/components/Evaluations/HumanEvaluationResult" -import {Evaluation, GenericObject, Variant} from "../Types" +import {Evaluation, EvaluationScenario, GenericObject, Variant} from "../Types" import {convertToCsv, downloadCsv} from "./fileManipulations" -export const exportABTestingEvaluationData = (evaluation: Evaluation, rows: GenericObject[]) => { +export const exportABTestingEvaluationData = ( + evaluation: Evaluation, + scenarios: EvaluationScenario[], + rows: GenericObject[], +) => { const exportRow = rows.map((data, ix) => { + const inputColumns = data.inputs.reduce( + (columns: any, input: {input_name: string; input_value: string}) => { + columns[`${input.input_name}`] = input.input_value + return columns + }, + {}, + ) return { - ["Inputs"]: - evaluation.testset.csvdata[ix]?.[evaluation.testset.testsetChatColumn] || - data.inputs[0].input_value, + ...inputColumns, [`App Variant ${evaluation.variants[0].variantName} Output 0`]: data?.columnData0 ? data?.columnData0 : data.outputs[0]?.variant_output, @@ -17,6 +26,9 @@ export const exportABTestingEvaluationData = (evaluation: Evaluation, rows: Gene ["Vote"]: evaluation.variants.find((v: Variant) => v.variantId === data.vote)?.variantName || data.vote, + ["Expected answer"]: + scenarios[ix]?.correctAnswer || evaluation.testset.csvdata[ix].correct_answer, + ["Additional notes"]: scenarios[ix]?.note, } }) const exportCol = Object.keys(exportRow[0]) @@ -26,17 +38,29 @@ export const exportABTestingEvaluationData = (evaluation: Evaluation, rows: Gene downloadCsv(csvData, filename) } -export const exportSingleModelEvaluationData = (evaluation: Evaluation, rows: GenericObject[]) => { +export const exportSingleModelEvaluationData = ( + evaluation: Evaluation, + scenarios: EvaluationScenario[], + rows: GenericObject[], +) => { const exportRow = rows.map((data, ix) => { + const inputColumns = data.inputs.reduce( + (columns: any, input: {input_name: string; input_value: string}) => { + columns[`${input.input_name}`] = input.input_value + return columns + }, + {}, + ) const numericScore = parseInt(data.score) return { - ["Inputs"]: - evaluation.testset.csvdata[ix]?.[evaluation.testset.testsetChatColumn] || - data.inputs[0].input_value, + ...inputColumns, [`App Variant ${evaluation.variants[0].variantName} Output 0`]: data?.columnData0 ? data?.columnData0 : data.outputs[0]?.variant_output, ["Score"]: isNaN(numericScore) ? "-" : numericScore, + ["Expected answer"]: + scenarios[ix]?.correctAnswer || evaluation.testset.csvdata[ix].correct_answer, + ["Additional notes"]: scenarios[ix]?.note, } }) const exportCol = Object.keys(exportRow[0]) From 59a90378f04c0ac08958ba31f4607d38690e956f Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Tue, 16 Jan 2024 08:39:04 +0100 Subject: [PATCH 2/3] fixed prettier --- .../src/pages/apps/[app_id]/testsets/new/upload/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agenta-web/src/pages/apps/[app_id]/testsets/new/upload/index.tsx b/agenta-web/src/pages/apps/[app_id]/testsets/new/upload/index.tsx index 29f7c47337..139c45ffdc 100644 --- a/agenta-web/src/pages/apps/[app_id]/testsets/new/upload/index.tsx +++ b/agenta-web/src/pages/apps/[app_id]/testsets/new/upload/index.tsx @@ -70,8 +70,8 @@ export default function AddANewTestset() { router.push(`/apps/${appId}/testsets`) } catch (e: any) { if ( - e?.response?.data?.detail?.find( - (item: GenericObject) => item?.loc?.includes("csvdata"), + e?.response?.data?.detail?.find((item: GenericObject) => + item?.loc?.includes("csvdata"), ) ) message.error(malformedFileError) From 942c5351f408a9a9c3ba3a4bb1c09794d6ab03ff Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Tue, 16 Jan 2024 12:53:56 +0100 Subject: [PATCH 3/3] modifies inputs logic to cater for chat --- agenta-web/src/lib/helpers/evaluate.ts | 32 +++++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/agenta-web/src/lib/helpers/evaluate.ts b/agenta-web/src/lib/helpers/evaluate.ts index 594d6befd0..c4ce8f95b1 100644 --- a/agenta-web/src/lib/helpers/evaluate.ts +++ b/agenta-web/src/lib/helpers/evaluate.ts @@ -8,13 +8,15 @@ export const exportABTestingEvaluationData = ( rows: GenericObject[], ) => { const exportRow = rows.map((data, ix) => { - const inputColumns = data.inputs.reduce( - (columns: any, input: {input_name: string; input_value: string}) => { - columns[`${input.input_name}`] = input.input_value - return columns - }, - {}, - ) + const inputColumns = evaluation.testset.testsetChatColumn + ? {Input: evaluation.testset.csvdata[ix]?.[evaluation.testset.testsetChatColumn]} + : data.inputs.reduce( + (columns: any, input: {input_name: string; input_value: string}) => { + columns[`${input.input_name}`] = input.input_value + return columns + }, + {}, + ) return { ...inputColumns, [`App Variant ${evaluation.variants[0].variantName} Output 0`]: data?.columnData0 @@ -44,13 +46,15 @@ export const exportSingleModelEvaluationData = ( rows: GenericObject[], ) => { const exportRow = rows.map((data, ix) => { - const inputColumns = data.inputs.reduce( - (columns: any, input: {input_name: string; input_value: string}) => { - columns[`${input.input_name}`] = input.input_value - return columns - }, - {}, - ) + const inputColumns = evaluation.testset.testsetChatColumn + ? {Input: evaluation.testset.csvdata[ix]?.[evaluation.testset.testsetChatColumn]} + : data.inputs.reduce( + (columns: any, input: {input_name: string; input_value: string}) => { + columns[`${input.input_name}`] = input.input_value + return columns + }, + {}, + ) const numericScore = parseInt(data.score) return { ...inputColumns,