Skip to content

Commit

Permalink
added helper to remove correctAnswer prefix and improved dropdown def…
Browse files Browse the repository at this point in the history
…ault text
  • Loading branch information
bekossy committed May 14, 2024
1 parent 0495376 commit d879572
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {AgGridReact} from "ag-grid-react"
import {Button, DropdownProps, Space, Spin, Tag, Tooltip, Typography} from "antd"
import React, {useEffect, useMemo, useRef, useState} from "react"
import {createUseStyles} from "react-jss"
import {getFilterParams, getTypedValue} from "@/lib/helpers/evaluate"
import {getFilterParams, getTypedValue, removeCorrectAnswerPrefix} from "@/lib/helpers/evaluate"
import {getColorFromStr, getRandomColors} from "@/lib/helpers/colors"
import {CheckOutlined, CloseCircleOutlined, DownloadOutlined, UndoOutlined} from "@ant-design/icons"
import {getAppValues} from "@/contexts/app.context"
Expand Down Expand Up @@ -84,7 +84,7 @@ const EvaluationCompareMode: React.FC<Props> = () => {
const gridRef = useRef<AgGridReact<_EvaluationScenario>>()
const [isFilterColsDropdownOpen, setIsFilterColsDropdownOpen] = useState(false)
const [isDiffDropdownOpen, setIsDiffDropdownOpen] = useState(false)
const [selectedCorrectAnswer, setSelectedCorrectAnswer] = useState(["Select"])
const [selectedCorrectAnswer, setSelectedCorrectAnswer] = useState(["No columns selected"])

const handleOpenChangeDiff: DropdownProps["onOpenChange"] = (nextOpen, info) => {
if (info.source === "trigger" || nextOpen) {
Expand Down Expand Up @@ -150,13 +150,13 @@ const EvaluationCompareMode: React.FC<Props> = () => {
.filter((item) => item.startsWith("correctAnswer_"))
.forEach((key) =>
colDefs.push({
headerName: `${key.split("_").at(-1)}`,
hide: hiddenVariants.includes(`${key.split("_").at(-1)}`),
headerName: `${removeCorrectAnswerPrefix(key)}`,
hide: hiddenVariants.includes(`${removeCorrectAnswerPrefix(key)}`),
headerComponent: (props: any) => {
return (
<AgCustomHeader {...props}>
<Space direction="vertical" className="py-2">
<span>{key.split("_").at(-1)}</span>
<span>{removeCorrectAnswerPrefix(key)}</span>
<Tag color="green">Ground Truth</Tag>
</Space>
</AgCustomHeader>
Expand Down Expand Up @@ -189,7 +189,7 @@ const EvaluationCompareMode: React.FC<Props> = () => {
cellRenderer: (params: any) => {
return (
<>
{selectedCorrectAnswer[0] !== "Select"
{selectedCorrectAnswer[0] !== "No columns selected"
? LongTextCellRenderer(
params,
<CompareOutputDiff
Expand Down Expand Up @@ -469,17 +469,17 @@ const EvaluationCompareMode: React.FC<Props> = () => {
label: (
<Space>
<CheckOutlined />
<>{key.split("_").at(-1)}</>
<>{removeCorrectAnswerPrefix(key)}</>
</Space>
),
}))}
buttonText={selectedCorrectAnswer[0].split("_").at(-1)}
buttonText={removeCorrectAnswerPrefix(selectedCorrectAnswer[0])}
isOpen={isDiffDropdownOpen}
handleOpenChange={handleOpenChangeDiff}
shownCols={selectedCorrectAnswer}
onClick={({key}) => {
if (key === selectedCorrectAnswer[0]) {
setSelectedCorrectAnswer(["Select"])
setSelectedCorrectAnswer(["No columns selected"])
} else {
setSelectedCorrectAnswer([key])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const EvaluationScenarios: React.FC<Props> = () => {
const [evaluators, setEvaluators] = useAtom(evaluatorsAtom)
const gridRef = useRef<AgGridReact<_EvaluationScenario>>()
const evalaution = scenarios[0]?.evaluation
const [selectedCorrectAnswer, setSelectedCorrectAnswer] = useState(["Select"])
const [selectedCorrectAnswer, setSelectedCorrectAnswer] = useState(["No columns selected"])
const [isFilterColsDropdownOpen, setIsFilterColsDropdownOpen] = useState(false)
const [isDiffDropdownOpen, setIsDiffDropdownOpen] = useState(false)
const [hiddenCols, setHiddenCols] = useState<string[]>([])
Expand Down Expand Up @@ -149,7 +149,7 @@ const EvaluationScenarios: React.FC<Props> = () => {
`${result?.error?.message}\n${result?.error?.stacktrace}`,
)
}
return selectedCorrectAnswer[0] !== "Select"
return selectedCorrectAnswer[0] !== "No columns selected"
? LongTextCellRenderer(
params,
<CompareOutputDiff
Expand Down Expand Up @@ -337,7 +337,7 @@ const EvaluationScenarios: React.FC<Props> = () => {
shownCols={selectedCorrectAnswer}
onClick={({key}) => {
if (key === selectedCorrectAnswer[0]) {
setSelectedCorrectAnswer(["Select"])
setSelectedCorrectAnswer(["No columns selected"])
} else {
setSelectedCorrectAnswer([key])
}
Expand Down
4 changes: 4 additions & 0 deletions agenta-web/src/lib/helpers/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,7 @@ const getCustomComparator = (type: CellDataType) => (valueA: string, valueB: str
if (type === "number") return getNumber(valueA) - getNumber(valueB)
return 0
}

export const removeCorrectAnswerPrefix = (str: string) => {
return str.replace(/^correctAnswer_/, "")
}

0 comments on commit d879572

Please sign in to comment.