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

944 | Feature: File input support in Apps #1010

Merged
merged 6 commits into from
Dec 7, 2023
Merged
Changes from 4 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
Binary file added agenta-web/public/assets/fallback.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ import {EvaluationTypeLabels, camelToSnake} from "@/lib/helpers/utils"
import {testsetRowToChatMessages} from "@/lib/helpers/testset"
import EvaluationVotePanel from "../Evaluations/EvaluationCardView/EvaluationVotePanel"
import VariantAlphabet from "../Evaluations/EvaluationCardView/VariantAlphabet"
import ParamsForm from "../Playground/ParamsForm/ParamsForm"

const {Title} = Typography

@@ -76,7 +77,7 @@ const useStyles = createUseStyles({
"& button": {
marginLeft: 10,
},
marginTop: 10,
marginTop: "0.75rem",
},
recordInput: {
marginBottom: 10,
@@ -336,23 +337,29 @@ const ABTestingEvaluationTable: React.FC<EvaluationTableProps> = ({
dataIndex: "inputs",
render: (text: any, record: ABTestingEvaluationTableRow, rowIndex: number) => (
<div>
{evaluation.testset.testsetChatColumn
? evaluation.testset.csvdata[rowIndex][
evaluation.testset.testsetChatColumn
] || " - "
: record &&
record.inputs &&
record.inputs.length && // initial value of inputs is array with 1 element and variantInputs could contain more than 1 element
record.inputs.map((input: any, index: number) => (
<div className={classes.recordInput} key={index}>
<Input.TextArea
rows={2}
placeholder={input.input_name}
value={input.input_value}
onChange={(e) => handleInputChange(e, record.id, index)}
/>
</div>
))}
{evaluation.testset.testsetChatColumn ? (
evaluation.testset.csvdata[rowIndex][
evaluation.testset.testsetChatColumn
] || " - "
) : (
<ParamsForm
isChatVariant={false}
onParamChange={(name, value) =>
handleInputChange(
{target: {value}} as any,
record.id,
record?.inputs.findIndex((ip) => ip.input_name === name),
)
}
inputParams={
variantData[0].inputParams?.map((item) => ({
...item,
value: record.inputs.find((ip) => ip.input_name === item.name)
?.input_value,
})) || []
}
/>
)}

<div className={classes.inputTestBtn}>
<Button
@@ -461,7 +468,6 @@ const ABTestingEvaluationTable: React.FC<EvaluationTableProps> = ({
dataSource={rows}
columns={columns}
pagination={false}
rowClassName={() => "editable-row"}
rowKey={(record) => record.id!}
/>
) : (
@@ -473,6 +479,7 @@ const ABTestingEvaluationTable: React.FC<EvaluationTableProps> = ({
onInputChange={handleInputChange}
updateEvaluationScenarioData={updateEvaluationScenarioData}
evaluation={evaluation}
variantData={variantData}
/>
)}
</div>
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ import {exportAICritiqueEvaluationData} from "@/lib/helpers/evaluate"
import SecondaryButton from "../SecondaryButton/SecondaryButton"
import {useAppTheme} from "../Layout/ThemeContextProvider"
import {contentToChatMessageString, testsetRowToChatMessages} from "@/lib/helpers/testset"
import ParamsForm from "../Playground/ParamsForm/ParamsForm"

const {Title} = Typography

@@ -214,13 +215,10 @@ Answer ONLY with one of the given grading or evaluation options.
}
}, [evaluationStatus, evaluation.id])

const handleInputChange = (
e: React.ChangeEvent<HTMLInputElement>,
rowIndex: any,
inputFieldKey: number,
) => {
const handleInputChange = (value: any, name: string, rowIndex: any) => {
const newRows = [...rows]
newRows[rowIndex].inputs[inputFieldKey].input_value = e.target.value
const ip = newRows[rowIndex].inputs.find((ip) => ip.input_name === name)
if (ip) ip.input_value = value
setRows(newRows)
}

@@ -374,22 +372,25 @@ Answer ONLY with one of the given grading or evaluation options.
dataIndex: "inputs",
render: (text: any, record: AICritiqueEvaluationTableRow, rowIndex: number) => (
<div>
{evaluation.testset.testsetChatColumn
? evaluation.testset.csvdata[rowIndex][
evaluation.testset.testsetChatColumn
] || " - "
: record &&
record.inputs &&
record.inputs.length && // initial value of inputs is array with 1 element and variantInputs could contain more than 1 element
record.inputs.map((input: any, index: number) => (
<div className={classes.recordInput} key={index}>
<Input
placeholder={input.input_name}
value={input.input_value}
onChange={(e) => handleInputChange(e, record.id, index)}
/>
</div>
))}
{evaluation.testset.testsetChatColumn ? (
evaluation.testset.csvdata[rowIndex][
evaluation.testset.testsetChatColumn
] || " - "
) : (
<ParamsForm
isChatVariant={false}
onParamChange={(name, value) =>
handleInputChange(value, name, rowIndex)
}
inputParams={
variantData[0].inputParams?.map((item) => ({
...item,
value: record.inputs.find((ip) => ip.input_name === item.name)
?.input_value,
})) || []
}
/>
)}
</div>
),
},
@@ -522,12 +523,7 @@ Answer ONLY with one of the given grading or evaluation options.
</center>
</div>
<div>
<Table
dataSource={rows}
columns={columns}
pagination={false}
rowClassName={() => "editable-row"}
/>
<Table dataSource={rows} columns={columns} pagination={false} />
</div>
</div>
)
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ import SecondaryButton from "../SecondaryButton/SecondaryButton"
import {exportCustomCodeEvaluationData} from "@/lib/helpers/evaluate"
import CodeBlock from "../DynamicCodeBlock/CodeBlock"
import {contentToChatMessageString, testsetRowToChatMessages} from "@/lib/helpers/testset"
import ParamsForm from "../Playground/ParamsForm/ParamsForm"

const {Title} = Typography

@@ -209,13 +210,10 @@ const CustomCodeRunEvaluationTable: React.FC<CustomCodeEvaluationTableProps> = (
getTests()
}, [evaluation])

const handleInputChange = (
e: React.ChangeEvent<HTMLInputElement>,
rowIndex: any,
inputFieldKey: number,
) => {
const handleInputChange = (value: any, name: string, rowIndex: any) => {
const newRows = [...rows]
newRows[rowIndex].inputs[inputFieldKey].input_value = e.target.value
const ip = newRows[rowIndex].inputs.find((ip) => ip.input_name === name)
if (ip) ip.input_value = value
setRows(newRows)
}

@@ -412,22 +410,25 @@ const CustomCodeRunEvaluationTable: React.FC<CustomCodeEvaluationTableProps> = (
dataIndex: "inputs",
render: (text: any, record: CustomCodeEvaluationTableRow, rowIndex: number) => (
<div>
{evaluation.testset.testsetChatColumn
? evaluation.testset.csvdata[rowIndex][
evaluation.testset.testsetChatColumn
] || " - "
: record &&
record.inputs &&
record.inputs.length && // initial value of inputs is array with 1 element and variantInputs could contain more than 1 element
record.inputs.map((input: any, index: number) => (
<div className={classes.recordInput} key={index}>
<Input
placeholder={input.input_name}
value={input.input_value}
onChange={(e) => handleInputChange(e, record.id, index)}
/>
</div>
))}
{evaluation.testset.testsetChatColumn ? (
evaluation.testset.csvdata[rowIndex][
evaluation.testset.testsetChatColumn
] || " - "
) : (
<ParamsForm
isChatVariant={false}
onParamChange={(name, value) =>
handleInputChange(value, name, rowIndex)
}
inputParams={
variantData[0].inputParams?.map((item) => ({
...item,
value: record.inputs.find((ip) => ip.input_name === item.name)
?.input_value,
})) || []
}
/>
)}
</div>
),
},
@@ -522,12 +523,7 @@ const CustomCodeRunEvaluationTable: React.FC<CustomCodeEvaluationTableProps> = (
)}

<div>
<Table
dataSource={rows}
columns={columns}
pagination={false}
rowClassName={() => "editable-row"}
/>
<Table dataSource={rows} columns={columns} pagination={false} />
</div>

<Modal
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ import {exportExactEvaluationData} from "@/lib/helpers/evaluate"
import SecondaryButton from "../SecondaryButton/SecondaryButton"
import {contentToChatMessageString, testsetRowToChatMessages} from "@/lib/helpers/testset"
import {Evaluation} from "@/lib/Types"
import ParamsForm from "../Playground/ParamsForm/ParamsForm"

const {Title} = Typography

@@ -152,13 +153,10 @@ const ExactMatchEvaluationTable: React.FC<ExactMatchEvaluationTableProps> = ({
setAccuracy(accuracy)
}, [rows])

const handleInputChange = (
e: React.ChangeEvent<HTMLInputElement>,
rowIndex: any,
inputFieldKey: number,
) => {
const handleInputChange = (value: any, name: string, rowIndex: any) => {
const newRows = [...rows]
newRows[rowIndex].inputs[inputFieldKey].input_value = e.target.value
const ip = newRows[rowIndex].inputs.find((ip) => ip.input_name === name)
if (ip) ip.input_value = value
setRows(newRows)
}

@@ -314,22 +312,25 @@ const ExactMatchEvaluationTable: React.FC<ExactMatchEvaluationTableProps> = ({
dataIndex: "inputs",
render: (text: any, record: ExactMatchEvaluationTableRow, rowIndex: number) => (
<div>
{evaluation.testset.testsetChatColumn
? evaluation.testset.csvdata[rowIndex][
evaluation.testset.testsetChatColumn
] || " - "
: record &&
record.inputs &&
record.inputs.length && // initial value of inputs is array with 1 element and variantInputs could contain more than 1 element
record.inputs.map((input: any, index: number) => (
<div className={classes.recordInput} key={index}>
<Input
placeholder={input.input_name}
value={input.input_value}
onChange={(e) => handleInputChange(e, record.id, index)}
/>
</div>
))}
{evaluation.testset.testsetChatColumn ? (
evaluation.testset.csvdata[rowIndex][
evaluation.testset.testsetChatColumn
] || " - "
) : (
<ParamsForm
isChatVariant={false}
onParamChange={(name, value) =>
handleInputChange(value, name, rowIndex)
}
inputParams={
variantData[0].inputParams?.map((item) => ({
...item,
value: record.inputs.find((ip) => ip.input_name === item.name)
?.input_value,
})) || []
}
/>
)}
</div>
),
},
@@ -432,13 +433,7 @@ const ExactMatchEvaluationTable: React.FC<ExactMatchEvaluationTableProps> = ({
</Row>
</div>
<div>
<Table
dataSource={rows}
columns={columns}
pagination={false}
rowClassName={() => "editable-row"}
rowKey="id"
/>
<Table dataSource={rows} columns={columns} pagination={false} rowKey="id" />
</div>
</div>
)
Loading
Loading