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

Enable annotation and correct answer in the tabular view in human single evaluation #1213

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
124 changes: 105 additions & 19 deletions agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import {useState, useEffect} from "react"
import {useState, useEffect, useCallback} from "react"
import type {ColumnType} from "antd/es/table"
import {Button, Card, Col, Radio, Row, Space, Statistic, Table, Typography, message} from "antd"
import {
Button,
Card,
Col,
Input,
Radio,
Row,
Space,
Statistic,
Table,
Typography,
message,
} from "antd"
import {
updateEvaluationScenario,
callVariant,
Expand All @@ -22,6 +34,7 @@ import EvaluationVotePanel from "../Evaluations/EvaluationCardView/EvaluationVot
import VariantAlphabet from "../Evaluations/EvaluationCardView/VariantAlphabet"
import {ParamsFormWithRun} from "./SingleModelEvaluationTable"
import {PassThrough} from "stream"
import {debounce} from "lodash"

const {Title} = Typography

Expand Down Expand Up @@ -90,6 +103,22 @@ const useStyles = createUseStyles({
top: 36,
zIndex: 1,
},
sideBar: {
marginTop: "1rem",
display: "flex",
flexDirection: "column",
gap: "2rem",
border: "1px solid #d9d9d9",
borderRadius: 6,
padding: "1rem",
alignSelf: "flex-start",
"&>h4.ant-typography": {
margin: 0,
},
flex: 0.35,
minWidth: 240,
maxWidth: 500,
},
})

const ABTestingEvaluationTable: React.FC<EvaluationTableProps> = ({
Expand Down Expand Up @@ -117,6 +146,13 @@ const ABTestingEvaluationTable: React.FC<EvaluationTableProps> = ({
evaluationResults?.votes_data?.variants_votes_data?.[evaluation.variants[1]?.variantId]
?.number_of_votes || 0

const depouncedUpdateEvaluationScenario = useCallback(
debounce((data: Partial<EvaluationScenario>, scenarioId) => {
updateEvaluationScenarioData(scenarioId, data)
}, 800),
[evaluationScenarios],
)

useEffect(() => {
if (evaluationScenarios) {
const obj = [...evaluationScenarios]
Expand Down Expand Up @@ -297,7 +333,7 @@ const ABTestingEvaluationTable: React.FC<EvaluationTableProps> = ({
),
dataIndex: columnKey,
key: columnKey,
width: "25%",
width: "20%",
render: (text: any, record: ABTestingEvaluationTableRow, rowIndex: number) => {
if (text) return text
if (record.outputs && record.outputs.length > 0) {
Expand Down Expand Up @@ -346,22 +382,72 @@ const ABTestingEvaluationTable: React.FC<EvaluationTableProps> = ({
},
...dynamicColumns,
{
title: "Evaluate",
dataIndex: "evaluate",
key: "evaluate",
width: 200,
// fixed: 'right',
render: (text: any, record: any, rowIndex: number) => (
<EvaluationVotePanel
type="comparison"
value={record.vote || ""}
variants={variants}
onChange={(vote) => handleVoteClick(record.id, vote)}
loading={record.vote === "loading"}
vertical
key={record.id}
/>
),
title: "Score",
dataIndex: "score",
key: "score",
render: (text: any, record: any, rowIndex: number) => {
return (
<>
{
<EvaluationVotePanel
type="comparison"
value={record.vote || ""}
variants={variants}
onChange={(vote) => handleVoteClick(record.id, vote)}
loading={record.vote === "loading"}
vertical
key={record.id}
/>
}
</>
)
},
},
{
title: "Expected Answer",
dataIndex: "expectedAnswer",
key: "expectedAnswer",
render: (text: any, record: any, rowIndex: number) => {
let correctAnswer =
record.correctAnswer || evaluation.testset.csvdata[rowIndex].correct_answer

return (
<>
<Input.TextArea
defaultValue={correctAnswer}
autoSize={{minRows: 3, maxRows: 5}}
onChange={(e) =>
depouncedUpdateEvaluationScenario(
{
correctAnswer: e.target.value,
},
record.id,
)
}
key={record.id}
/>
</>
)
},
},
{
title: "Additional Note",
dataIndex: "additionalNote",
key: "additionalNote",
render: (text: any, record: any, rowIndex: number) => {
return (
<>
<Input.TextArea
defaultValue={record?.note || ""}
autoSize={{minRows: 3, maxRows: 5}}
onChange={(e) =>
depouncedUpdateEvaluationScenario({note: e.target.value}, record.id)
}
key={record.id}
/>
</>
)
},
},
]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {useState, useEffect, useCallback} from "react"
import {useState, useEffect, useCallback, useMemo} from "react"
import type {ColumnType} from "antd/es/table"
import {CaretRightOutlined} from "@ant-design/icons"
import {
Button,
Card,
Col,
Form,
Input,
Radio,
Row,
Space,
Expand Down Expand Up @@ -98,6 +99,22 @@ const useStyles = createUseStyles({
top: 36,
zIndex: 1,
},
sideBar: {
marginTop: "1rem",
display: "flex",
flexDirection: "column",
gap: "2rem",
border: "1px solid #d9d9d9",
borderRadius: 6,
padding: "1rem",
alignSelf: "flex-start",
"&>h4.ant-typography": {
margin: 0,
},
flex: 0.35,
minWidth: 240,
maxWidth: 500,
},
})

export const ParamsFormWithRun = ({
Expand Down Expand Up @@ -166,6 +183,13 @@ const SingleModelEvaluationTable: React.FC<EvaluationTableProps> = ({
const [viewMode, setViewMode] = useQueryParam("viewMode", "card")
const [accuracy, setAccuracy] = useState<number>(0)

const depouncedUpdateEvaluationScenario = useCallback(
debounce((data: Partial<EvaluationScenario>, scenarioId) => {
updateEvaluationScenarioData(scenarioId, data)
}, 800),
[evaluationScenarios],
)

useEffect(() => {
if (evaluationScenarios) {
const obj = [...evaluationScenarios]
Expand Down Expand Up @@ -404,29 +428,77 @@ const SingleModelEvaluationTable: React.FC<EvaluationTableProps> = ({
},
...dynamicColumns,
{
title: "Evaluate",
dataIndex: "evaluate",
key: "evaluate",
width: 200,
// fixed: 'right',
title: "Score",
dataIndex: "score",
key: "score",
render: (text: any, record: any, rowIndex: number) => {
return (
<EvaluationVotePanel
type="numeric"
value={[
{
variantId: variants[0].variantId,
score: record.score as number,
},
]}
variants={variants}
onChange={(val) =>
depouncedHandleScoreChange(record.id, val[0].score as number)
<>
{
<EvaluationVotePanel
type="numeric"
value={[
{
variantId: variants[0].variantId,
score: record.score as number,
},
]}
variants={variants}
onChange={(val) =>
depouncedHandleScoreChange(record.id, val[0].score as number)
}
loading={record.score === "loading"}
showVariantName={false}
key={record.id}
/>
}
loading={record.score === "loading"}
showVariantName={false}
key={record.id}
/>
</>
)
},
},
{
title: "Expected Answer",
dataIndex: "expectedAnswer",
key: "expectedAnswer",
render: (text: any, record: any, rowIndex: number) => {
let correctAnswer =
record.correctAnswer || evaluation.testset.csvdata[rowIndex].correct_answer

return (
<>
<Input.TextArea
defaultValue={correctAnswer}
autoSize={{minRows: 3, maxRows: 5}}
onChange={(e) =>
depouncedUpdateEvaluationScenario(
{
correctAnswer: e.target.value,
},
record.id,
)
}
key={record.id}
/>
</>
)
},
},
{
title: "Additional Note",
dataIndex: "additionalNote",
key: "additionalNote",
render: (text: any, record: any, rowIndex: number) => {
return (
<>
<Input.TextArea
defaultValue={record?.note || ""}
autoSize={{minRows: 3, maxRows: 5}}
onChange={(e) =>
depouncedUpdateEvaluationScenario({note: e.target.value}, record.id)
}
key={record.id}
/>
</>
)
},
},
Expand Down
Loading