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 2 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
119 changes: 103 additions & 16 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 @@ -349,19 +385,70 @@ const ABTestingEvaluationTable: React.FC<EvaluationTableProps> = ({
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}
/>
),
width: 300,
render: (text: any, record: any, rowIndex: number) => {
return (
<>
<div className={classes.sideBar}>
<Typography.Title level={4}>Submit your feedback</Typography.Title>

{record.outputs.length > 0 &&
record.outputs.every((item: any) => !!item.variant_output) && (
<Space direction="vertical">
<Typography.Text strong>
Which response is better?
</Typography.Text>
{
<EvaluationVotePanel
type="comparison"
value={record.vote || ""}
variants={variants}
onChange={(vote) =>
handleVoteClick(record.id, vote)
}
loading={record.vote === "loading"}
vertical
key={record.id}
/>
}
</Space>
)}

<Space direction="vertical">
<Typography.Text strong>Expected Answer</Typography.Text>
<Input.TextArea
defaultValue={record.correctAnswer}
autoSize={{minRows: 3, maxRows: 5}}
onChange={(e) =>
depouncedUpdateEvaluationScenario(
{
correctAnswer: e.target.value,
},
record.id,
)
}
key={record.id}
/>
</Space>

<Space direction="vertical">
<Typography.Text strong>Additional Notes</Typography.Text>
<Input.TextArea
defaultValue={record?.note || ""}
autoSize={{minRows: 3, maxRows: 5}}
onChange={(e) =>
depouncedUpdateEvaluationScenario(
{note: e.target.value},
record.id,
)
}
key={record.id}
/>
</Space>
</div>
</>
)
},
},
]

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 @@ -407,26 +431,74 @@ const SingleModelEvaluationTable: React.FC<EvaluationTableProps> = ({
title: "Evaluate",
dataIndex: "evaluate",
key: "evaluate",
width: 200,
// fixed: 'right',
width: 300,
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)
}
loading={record.score === "loading"}
showVariantName={false}
key={record.id}
/>
<>
<div className={classes.sideBar}>
<Typography.Title level={4}>Submit your feedback</Typography.Title>

{record.outputs.length > 0 &&
record.outputs.every((item: any) => !!item.variant_output) && (
<Space direction="vertical">
<Typography.Text strong>Rate the response</Typography.Text>
{
<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}
/>
}
</Space>
)}

<Space direction="vertical">
<Typography.Text strong>Expected Answer</Typography.Text>
<Input.TextArea
defaultValue={record.correctAnswer}
autoSize={{minRows: 3, maxRows: 5}}
onChange={(e) =>
depouncedUpdateEvaluationScenario(
{
correctAnswer: e.target.value,
},
record.id,
)
}
key={record.id}
/>
</Space>

<Space direction="vertical">
<Typography.Text strong>Additional Notes</Typography.Text>
<Input.TextArea
defaultValue={record?.note || ""}
autoSize={{minRows: 3, maxRows: 5}}
onChange={(e) =>
depouncedUpdateEvaluationScenario(
{note: e.target.value},
record.id,
)
}
key={record.id}
/>
</Space>
</div>
</>
)
},
},
Expand Down
Loading