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

Main to evaluations in backend #1217

Merged
merged 8 commits into from
Jan 17, 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 @@ -387,7 +387,13 @@ const ABTestingEvaluationTable: React.FC<EvaluationTableProps> = ({
Run All
</Button>
<SecondaryButton
onClick={() => exportABTestingEvaluationData(evaluation, rows)}
onClick={() =>
exportABTestingEvaluationData(
evaluation,
evaluationScenarios,
rows,
)
}
disabled={false}
>
Export results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,13 @@ const SingleModelEvaluationTable: React.FC<EvaluationTableProps> = ({
Run All
</Button>
<SecondaryButton
onClick={() => exportSingleModelEvaluationData(evaluation, rows)}
onClick={() =>
exportSingleModelEvaluationData(
evaluation,
evaluationScenarios,
rows,
)
}
disabled={false}
>
Export results
Expand Down
168 changes: 162 additions & 6 deletions agenta-web/src/lib/helpers/evaluate.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,85 @@
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 exportExactEvaluationData = (evaluation: Evaluation, rows: GenericObject[]) => {
const exportRow = rows.map((data, ix) => {
return {
["Inputs"]:
evaluation.testset.csvdata[ix]?.[evaluation.testset.testsetChatColumn] ||
data.inputs[0].input_value,
[`App Variant ${evaluation.variants[0].variantName} Output`]: data?.columnData0
? data?.columnData0
: data.outputs[0]?.variant_output,
["Correct answer"]: data.correctAnswer,
["Evaluation"]: data.score,
}
})
const exportCol = Object.keys(exportRow[0])

const csvData = convertToCsv(exportRow, exportCol)
const filename = `${evaluation.appName}_${evaluation.variants[0].variantName}_${evaluation.evaluationType}.csv`
downloadCsv(csvData, filename)
}

export const exportSimilarityEvaluationData = (evaluation: Evaluation, rows: GenericObject[]) => {
const exportRow = rows.map((data, ix) => {
return {
["Inputs"]:
evaluation.testset.csvdata[ix]?.[evaluation.testset.testsetChatColumn] ||
data.inputs[0].input_value,
[`App Variant ${evaluation.variants[0].variantName} Output`]: data?.columnData0
? data?.columnData0
: data.outputs[0]?.variant_output,
["Correct answer"]: data.correctAnswer,
["Score"]: data.score,
["Evaluation"]: data.similarity,
}
})
const exportCol = Object.keys(exportRow[0])

const csvData = convertToCsv(exportRow, exportCol)
const filename = `${evaluation.appName}_${evaluation.variants[0].variantName}_${evaluation.evaluationType}.csv`
downloadCsv(csvData, filename)
}

export const exportAICritiqueEvaluationData = (evaluation: Evaluation, rows: GenericObject[]) => {
const exportRow = rows.map((data, ix) => {
return {
["Inputs"]:
evaluation.testset.csvdata[ix]?.[evaluation.testset.testsetChatColumn] ||
data.inputs[0].input_value,
[`App Variant ${evaluation.variants[0].variantName} Output`]: data?.columnData0
? data?.columnData0
: data.outputs[0]?.variant_output,
["Correct answer"]: data.correctAnswer,
["Score"]: data.score,
}
})
const exportCol = Object.keys(exportRow[0])

const csvData = convertToCsv(exportRow, exportCol)
const filename = `${evaluation.appName}_${evaluation.variants[0].variantName}_${evaluation.evaluationType}.csv`
downloadCsv(csvData, filename)
}

export const exportABTestingEvaluationData = (
evaluation: Evaluation,
scenarios: EvaluationScenario[],
rows: GenericObject[],
) => {
const exportRow = rows.map((data, ix) => {
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
? data?.columnData0
: data.outputs[0]?.variant_output,
Expand All @@ -17,6 +89,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])
Expand All @@ -26,17 +101,98 @@ 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 = 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,
[`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])

const csvData = convertToCsv(exportRow, exportCol)
const filename = `${evaluation.appName}_${evaluation.variants[0].variantName}_${evaluation.evaluationType}.csv`
downloadCsv(csvData, filename)
}

export const exportRegexEvaluationData = (
evaluation: Evaluation,
rows: GenericObject[],
settings: GenericObject,
) => {
const exportRow = rows.map((data, ix) => {
const isCorrect = data.score === "correct"
const isMatch = settings.regexShouldMatch ? isCorrect : !isCorrect

return {
["Inputs"]:
evaluation.testset.csvdata[ix]?.[evaluation.testset.testsetChatColumn] ||
data.inputs[0].input_value,
[`App Variant ${evaluation.variants[0].variantName} Output 0`]: data?.columnData0
[`App Variant ${evaluation.variants[0].variantName} Output`]: data?.columnData0
? data?.columnData0
: data.outputs[0]?.variant_output,
["Score"]: isNaN(numericScore) ? "-" : numericScore,
["Match / Mismatch"]: isMatch ? "Match" : "Mismatch",
["Evaluation"]: data.score,
}
})
const exportCol = Object.keys(exportRow[0])

const csvData = convertToCsv(exportRow, exportCol)
const filename = `${evaluation.appName}_${evaluation.variants[0].variantName}_${evaluation.evaluationType}.csv`
downloadCsv(csvData, filename)
}

export const exportWebhookEvaluationData = (evaluation: Evaluation, rows: GenericObject[]) => {
const exportRow = rows.map((data, ix) => {
return {
["Inputs"]:
evaluation.testset.csvdata[ix]?.[evaluation.testset.testsetChatColumn] ||
data.inputs[0].input_value,
[`App Variant ${evaluation.variants[0].variantName} Output`]: data?.columnData0
? data?.columnData0
: data.outputs[0]?.variant_output,
["Correct answer"]: data.correctAnswer,
["Score"]: data.score,
}
})
const exportCol = Object.keys(exportRow[0])

const csvData = convertToCsv(exportRow, exportCol)
const filename = `${evaluation.appName}_${evaluation.variants[0].variantName}_${evaluation.evaluationType}.csv`
downloadCsv(csvData, filename)
}

export const exportCustomCodeEvaluationData = (evaluation: Evaluation, rows: GenericObject[]) => {
const exportRow = rows.map((data, ix) => {
return {
["Inputs"]:
evaluation.testset.csvdata[ix]?.[evaluation.testset.testsetChatColumn] ||
data.inputs[0].input_value,
[`App Variant ${evaluation.variants[0].variantName} Output`]: data?.columnData0
? data?.columnData0
: data.outputs[0]?.variant_output,
["Correct answer"]: data.correctAnswer,
["Score"]: data.score,
}
})
const exportCol = Object.keys(exportRow[0])
Expand All @@ -63,4 +219,4 @@ export const calculateResultsDataAvg = (
export const getVotesPercentage = (record: HumanEvaluationListTableDataType, index: number) => {
const variant = record.votesData.variants[index]
return record.votesData.variants_votes_data[variant]?.percentage
}
}
Loading