From 2ef07a9ac6941b96626e1ae71cf06dde2d991745 Mon Sep 17 00:00:00 2001 From: MohammedMaaz Date: Thu, 7 Dec 2023 03:50:10 +0500 Subject: [PATCH 1/3] feat: file input support in playground and evaluations --- agenta-web/public/assets/fallback.png | Bin 0 -> 2404 bytes .../ABTestingEvaluationTable.tsx | 44 ++++--- .../AICritiqueEvaluationTable.tsx | 52 ++++----- .../CustomCodeRunEvaluationTable.tsx | 52 ++++----- .../ExactMatchEvaluationTable.tsx | 53 ++++----- .../EvaluationTable/RegexEvaluationTable.tsx | 52 ++++----- .../SimilarityMatchEvaluationTable.tsx | 52 ++++----- .../SingleModelEvaluationTable.tsx | 43 ++++--- .../WebhookEvaluationTable.tsx | 56 +++++---- .../Evaluations/EvaluationCardView/index.tsx | 42 ++++--- .../Playground/ParamsForm/ParamsForm.tsx | 107 ++++++++++++++++++ .../components/Playground/Views/TestView.tsx | 42 +++---- agenta-web/src/lib/helpers/openapi_parser.ts | 4 +- agenta-web/src/lib/helpers/testset.ts | 3 +- agenta-web/src/lib/helpers/validators.ts | 6 +- examples/vision_gpt_explain_image/.gitignore | 7 ++ examples/vision_gpt_explain_image/app.py | 2 +- 17 files changed, 367 insertions(+), 250 deletions(-) create mode 100644 agenta-web/public/assets/fallback.png create mode 100644 agenta-web/src/components/Playground/ParamsForm/ParamsForm.tsx create mode 100644 examples/vision_gpt_explain_image/.gitignore diff --git a/agenta-web/public/assets/fallback.png b/agenta-web/public/assets/fallback.png new file mode 100644 index 0000000000000000000000000000000000000000..d3cbad03790c43025419fb22c239616d2ff66d1c GIT binary patch literal 2404 zcmeHI>s!)i82`xEwI*FN0$b6?MMzaQTFd9UkD4-TRl z8Cn_w0ANJhNeR)_79FHWeI3giyRHBLxINC#FPP@%hY9AekH)cL0KhgUn#nYwIoh^G zMKPIeoep+}oWu~ZI5UJPXlZ_cX~A@0nw#_UA|r>*QN!@PEkMzp2et95GBNX2&TZx6 zpSsGp8&(}~`G&6aB1RPIg%S;ichQ`J^q&YIFQ>bb5|L1d*K6DF>|zI0ZiQGmSV<8y zz6HbkO4JC-f>M6XhW-#Cw!jBGA(rrUCPiYA=>oB?TU%?m)*gKf)Nn$=lx7c-@TI4F zqSbKZ6Cc{~?JLB*E|(I=j(~34J*N<6)eF+;-mo>P36<4ug(>#8 zcIugNxm=oAsl4Zn>Bq`heePa)Pfw4J-o7U`W@hJiyC11a&yIdvm9vG^IgUy$C(Ue8 zD;?T9IO>s+kprJ9!Z*ad5$2)!n@+J}k?Gf0~m0=xf??Es&jCI z0ElG)RrG)x0Q%+-j#{T%_A}r}eV#XnEx$#rudk;MR{h2@0EcjygT)swUYwZwGoa{y?#)RTbF)d=U5}z9G zpN}P;n>@0=J>JxcEJClttHU=wU5QI!NNC|tl6vn>(;K^f zE)>Dgb&M7l=RVzTt%?5Ptah2dHZj|=*JgP7y|^)5-gJIuVsdqlG|kwhcAJ_TC!;I+ zE+NFfVw=OuT8p)%Zsf?wRzcax*nZ79l?Pb7qxOe@k?)mC<;3gPKWDH@oW?ejMN@8! zBx5R-dbMf4g`01(#c2Q76XaEf5b2MLP#f;P;jJnlp6A{9E)UIUy1<`GB$cND=zi%G zr|fY-zs$224s)=!0y@rT!SZ*V%DwJAz4^2hib`$84k>Iz;>cDQ2t`H1fFUS)UH4Gt2` zkq@0KUwZNHT}V4NvAV)c{ru^j+W7<@7$pqVM`uU8{*LIo>8WvLWK&jMyrTL8K0`*h z7_%O>vC>=^jo|bgYDho5xGMT@L2vlVa1s2RKw8K5(z9$7hNVw(4_r1kne0WR;BHuFb?$)dm(Yg@ueLVLV7$uLB zxL)xHiHeFYQ61|*h%a+v*=(0vtkK6BqO?KlImXL6-cWQuF(E+{-_W^4kGLc_wfOj| z%ZnOqXtib?M+0p{PbQmK#TJE#q0l1VPLIBP0L}5R{~C!Z46ZgJ=-yBMH@mE06x%+Q yU*`(c-%bE+NKgd-y{nQnShDE6fUl)nIBe#5l@ literal 0 HcmV?d00001 diff --git a/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx index adc4e7ad37..0b72d622ec 100644 --- a/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx @@ -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,22 +337,29 @@ const ABTestingEvaluationTable: React.FC = ({ dataIndex: "inputs", render: (text: any, record: ABTestingEvaluationTableRow, rowIndex: number) => (
- {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) => ( -
- handleInputChange(e, record.id, index)} - /> -
- ))} + {evaluation.testset.testsetChatColumn ? ( + evaluation.testset.csvdata[rowIndex][ + evaluation.testset.testsetChatColumn + ] || " - " + ) : ( + + 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, + })) || [] + } + /> + )}
diff --git a/agenta-web/src/components/EvaluationTable/AICritiqueEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/AICritiqueEvaluationTable.tsx index b6ab986f42..0c46619d43 100644 --- a/agenta-web/src/components/EvaluationTable/AICritiqueEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/AICritiqueEvaluationTable.tsx @@ -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, - 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) => (
- {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) => ( -
- handleInputChange(e, record.id, index)} - /> -
- ))} + {evaluation.testset.testsetChatColumn ? ( + evaluation.testset.csvdata[rowIndex][ + evaluation.testset.testsetChatColumn + ] || " - " + ) : ( + + handleInputChange(value, name, rowIndex) + } + inputParams={ + variantData[0].inputParams?.map((item) => ({ + ...item, + value: record.inputs.find((ip) => ip.input_name === item.name) + ?.input_value, + })) || [] + } + /> + )}
), }, @@ -522,12 +523,7 @@ Answer ONLY with one of the given grading or evaluation options.
- "editable-row"} - /> +
) diff --git a/agenta-web/src/components/EvaluationTable/CustomCodeRunEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/CustomCodeRunEvaluationTable.tsx index e378bd2f01..eeb8fd2c5e 100644 --- a/agenta-web/src/components/EvaluationTable/CustomCodeRunEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/CustomCodeRunEvaluationTable.tsx @@ -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 = ( getTests() }, [evaluation]) - const handleInputChange = ( - e: React.ChangeEvent, - 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 = ( dataIndex: "inputs", render: (text: any, record: CustomCodeEvaluationTableRow, rowIndex: number) => (
- {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) => ( -
- handleInputChange(e, record.id, index)} - /> -
- ))} + {evaluation.testset.testsetChatColumn ? ( + evaluation.testset.csvdata[rowIndex][ + evaluation.testset.testsetChatColumn + ] || " - " + ) : ( + + handleInputChange(value, name, rowIndex) + } + inputParams={ + variantData[0].inputParams?.map((item) => ({ + ...item, + value: record.inputs.find((ip) => ip.input_name === item.name) + ?.input_value, + })) || [] + } + /> + )}
), }, @@ -522,12 +523,7 @@ const CustomCodeRunEvaluationTable: React.FC = ( )}
-
"editable-row"} - /> +
= ({ setAccuracy(accuracy) }, [rows]) - const handleInputChange = ( - e: React.ChangeEvent, - 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 = ({ dataIndex: "inputs", render: (text: any, record: ExactMatchEvaluationTableRow, rowIndex: number) => (
- {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) => ( -
- handleInputChange(e, record.id, index)} - /> -
- ))} + {evaluation.testset.testsetChatColumn ? ( + evaluation.testset.csvdata[rowIndex][ + evaluation.testset.testsetChatColumn + ] || " - " + ) : ( + + handleInputChange(value, name, rowIndex) + } + inputParams={ + variantData[0].inputParams?.map((item) => ({ + ...item, + value: record.inputs.find((ip) => ip.input_name === item.name) + ?.input_value, + })) || [] + } + /> + )}
), }, @@ -432,13 +433,7 @@ const ExactMatchEvaluationTable: React.FC = ({
-
"editable-row"} - rowKey="id" - /> +
) diff --git a/agenta-web/src/components/EvaluationTable/RegexEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/RegexEvaluationTable.tsx index 348acba9c0..996e4b68fa 100644 --- a/agenta-web/src/components/EvaluationTable/RegexEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/RegexEvaluationTable.tsx @@ -30,6 +30,7 @@ import SecondaryButton from "../SecondaryButton/SecondaryButton" import {exportRegexEvaluationData} from "@/lib/helpers/evaluate" import {isValidRegex} from "@/lib/helpers/validators" import {contentToChatMessageString, testsetRowToChatMessages} from "@/lib/helpers/testset" +import ParamsForm from "../Playground/ParamsForm/ParamsForm" const {Title} = Typography @@ -164,13 +165,10 @@ const RegexEvaluationTable: React.FC = ({ setAccuracy(accuracy) }, [rows]) - const handleInputChange = ( - e: React.ChangeEvent, - 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) } @@ -330,22 +328,25 @@ const RegexEvaluationTable: React.FC = ({ dataIndex: "inputs", render: (_: any, record: RegexEvaluationTableRow, rowIndex: number) => (
- {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) => ( -
- handleInputChange(e, record.id, index)} - /> -
- ))} + {evaluation.testset.testsetChatColumn ? ( + evaluation.testset.csvdata[rowIndex][ + evaluation.testset.testsetChatColumn + ] || " - " + ) : ( + + handleInputChange(value, name, rowIndex) + } + inputParams={ + variantData[0].inputParams?.map((item) => ({ + ...item, + value: record.inputs.find((ip) => ip.input_name === item.name) + ?.input_value, + })) || [] + } + /> + )}
), }, @@ -500,12 +501,7 @@ const RegexEvaluationTable: React.FC = ({ )}
-
"editable-row"} - /> +
) diff --git a/agenta-web/src/components/EvaluationTable/SimilarityMatchEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/SimilarityMatchEvaluationTable.tsx index 70d138f4a6..96ac5cb380 100644 --- a/agenta-web/src/components/EvaluationTable/SimilarityMatchEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/SimilarityMatchEvaluationTable.tsx @@ -26,6 +26,7 @@ import {createUseStyles} from "react-jss" import {exportSimilarityEvaluationData} from "@/lib/helpers/evaluate" import SecondaryButton from "../SecondaryButton/SecondaryButton" import {contentToChatMessageString, testsetRowToChatMessages} from "@/lib/helpers/testset" +import ParamsForm from "../Playground/ParamsForm/ParamsForm" const {Title} = Typography @@ -166,13 +167,10 @@ const SimilarityMatchEvaluationTable: React.FC, - 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) } @@ -316,22 +314,25 @@ const SimilarityMatchEvaluationTable: React.FC (
- {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) => ( -
- handleInputChange(e, record.id, index)} - /> -
- ))} + {evaluation.testset.testsetChatColumn ? ( + evaluation.testset.csvdata[rowIndex][ + evaluation.testset.testsetChatColumn + ] || " - " + ) : ( + + handleInputChange(value, name, rowIndex) + } + inputParams={ + variantData[0].inputParams?.map((item) => ({ + ...item, + value: record.inputs.find((ip) => ip.input_name === item.name) + ?.input_value, + })) || [] + } + /> + )}
), }, @@ -467,12 +468,7 @@ const SimilarityMatchEvaluationTable: React.FC -
"editable-row"} - /> +
) diff --git a/agenta-web/src/components/EvaluationTable/SingleModelEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/SingleModelEvaluationTable.tsx index 5a1fdaad36..6b0004c632 100644 --- a/agenta-web/src/components/EvaluationTable/SingleModelEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/SingleModelEvaluationTable.tsx @@ -35,6 +35,7 @@ import {EvaluationTypeLabels, camelToSnake} from "@/lib/helpers/utils" import {testsetRowToChatMessages} from "@/lib/helpers/testset" import {debounce} from "lodash" import EvaluationVotePanel from "../Evaluations/EvaluationCardView/EvaluationVotePanel" +import ParamsForm from "../Playground/ParamsForm/ParamsForm" const {Title} = Typography @@ -78,6 +79,7 @@ const useStyles = createUseStyles({ "& button": { marginLeft: 10, }, + marginTop: "0.75rem", }, recordInput: { marginBottom: 10, @@ -337,22 +339,29 @@ const SingleModelEvaluationTable: React.FC = ({ dataIndex: "inputs", render: (text: any, record: SingleModelEvaluationRow, rowIndex: number) => (
- {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) => ( -
- handleInputChange(e, record.id, index)} - /> -
- ))} + {evaluation.testset.testsetChatColumn ? ( + evaluation.testset.csvdata[rowIndex][ + evaluation.testset.testsetChatColumn + ] || " - " + ) : ( + + 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, + })) || [] + } + /> + )}
diff --git a/agenta-web/src/components/EvaluationTable/WebhookEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/WebhookEvaluationTable.tsx index 9f8001f65a..cf7776838f 100644 --- a/agenta-web/src/components/EvaluationTable/WebhookEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/WebhookEvaluationTable.tsx @@ -25,10 +25,11 @@ import {EvaluationFlow} from "@/lib/enums" import {evaluateWithWebhook} from "@/lib/services/evaluations" import {createUseStyles} from "react-jss" import {globalErrorHandler} from "@/lib/helpers/errorHandler" -import {isValidUrl} from "@/lib/helpers/validators" +import {isValidHttpUrl} from "@/lib/helpers/validators" import SecondaryButton from "../SecondaryButton/SecondaryButton" import {exportWebhookEvaluationData} from "@/lib/helpers/evaluate" import {contentToChatMessageString, testsetRowToChatMessages} from "@/lib/helpers/testset" +import ParamsForm from "../Playground/ParamsForm/ParamsForm" const {Title} = Typography @@ -144,13 +145,10 @@ const WebhookEvaluationTable: React.FC = ({ setAccuracy(avg * 100) }, [rows]) - const handleInputChange = ( - e: React.ChangeEvent, - 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) } @@ -302,22 +300,25 @@ const WebhookEvaluationTable: React.FC = ({ dataIndex: "inputs", render: (_: any, record: WebhookEvaluationTableRow, rowIndex: number) => (
- {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) => ( -
- handleInputChange(e, record.id, index)} - /> -
- ))} + {evaluation.testset.testsetChatColumn ? ( + evaluation.testset.csvdata[rowIndex][ + evaluation.testset.testsetChatColumn + ] || " - " + ) : ( + + handleInputChange(value, name, rowIndex) + } + inputParams={ + variantData[0].inputParams?.map((item) => ({ + ...item, + value: record.inputs.find((ip) => ip.input_name === item.name) + ?.input_value, + })) || [] + } + /> + )}
), }, @@ -442,7 +443,7 @@ const WebhookEvaluationTable: React.FC = ({ { validator: (_, value) => new Promise((res, rej) => - isValidUrl(value) + isValidHttpUrl(value) ? res("") : rej("Please enter a valid url"), ), @@ -455,12 +456,7 @@ const WebhookEvaluationTable: React.FC = ({ )}
-
"editable-row"} - /> +
) diff --git a/agenta-web/src/components/Evaluations/EvaluationCardView/index.tsx b/agenta-web/src/components/Evaluations/EvaluationCardView/index.tsx index ed1e9476a1..6de7ffc6ee 100644 --- a/agenta-web/src/components/Evaluations/EvaluationCardView/index.tsx +++ b/agenta-web/src/components/Evaluations/EvaluationCardView/index.tsx @@ -22,6 +22,8 @@ import {testsetRowToChatMessages} from "@/lib/helpers/testset" import {safeParse} from "@/lib/helpers/utils" import {debounce} from "lodash" import {EvaluationType} from "@/lib/enums" +import ParamsForm from "@/components/Playground/ParamsForm/ParamsForm" +import {useVariants} from "@/lib/hooks/useVariant" export const VARIANT_COLORS = [ "#297F87", // "#722ed1", @@ -132,6 +134,7 @@ interface Props { onInputChange: Function updateEvaluationScenarioData: (id: string, data: Partial) => void evaluation: Evaluation + variantData: ReturnType } const EvaluationCardView: React.FC = ({ @@ -142,6 +145,7 @@ const EvaluationCardView: React.FC = ({ onInputChange, updateEvaluationScenarioData, evaluation, + variantData, }) => { const classes = useStyles() const {token} = theme.useToken() @@ -338,20 +342,30 @@ const EvaluationCardView: React.FC = ({ - {isChat ? ( -
- -
- ) : ( - - )} + + isChat + ? onChatChange(value) + : onInputChange( + {target: {value}} as any, + scenarioId, + scenario.inputs.findIndex((ip) => ip.input_name === name), + ) + } + inputParams={ + isChat + ? [{name: "chat", value: chat} as any] + : variantData[0].inputParams?.map((item) => ({ + ...item, + value: scenario.inputs.find( + (ip) => ip.input_name === item.name, + )?.input_value, + })) || [] + } + key={scenarioId} + useChatDefaultValue + />
diff --git a/agenta-web/src/components/Playground/ParamsForm/ParamsForm.tsx b/agenta-web/src/components/Playground/ParamsForm/ParamsForm.tsx new file mode 100644 index 0000000000..b102625fe8 --- /dev/null +++ b/agenta-web/src/components/Playground/ParamsForm/ParamsForm.tsx @@ -0,0 +1,107 @@ +import React from "react" +import ChatInputs from "@/components/ChatInputs/ChatInputs" +import {GenericObject, Parameter} from "@/lib/Types" +import {renameVariables} from "@/lib/helpers/utils" +import {Form, Image, Input} from "antd" +import {createUseStyles} from "react-jss" + +const useStyles = createUseStyles({ + form: { + width: "100%", + "& .ant-form-item": { + marginBottom: "0px", + }, + }, + formItemRow: { + display: "flex", + gap: "0.5rem", + alignItems: "flex-start", + marginTop: "1rem", + + "& .ant-input": { + marginTop: 1, + }, + }, + cover: { + objectFit: "cover", + borderRadius: 6, + }, +}) + +interface Props { + inputParams: (Parameter & {value: any})[] + onFinish?: (values: GenericObject) => void + onParamChange?: (name: string, value: any) => void + isChatVariant?: boolean + useChatDefaultValue?: boolean +} + +const ParamsForm: React.FC = ({ + inputParams, + onFinish, + onParamChange, + isChatVariant, + useChatDefaultValue, +}) => { + const classes = useStyles() + const [form] = Form.useForm() + + const chat = inputParams.find((param) => param.name === "chat")?.value + + return isChatVariant ? ( + onParamChange?.("chat", val)} + /> + ) : ( +
+ {/*@ts-ignore*/} + {(_, formInstance) => + inputParams.map((param, index) => { + const type = param.type === "file_url" ? "url" : param.type + return ( + +
+ {type === "url" && + param.value && + formInstance.getFieldError(param.name).length === 0 && ( + + )} + onParamChange?.(param.name, e.target.value)} + autoSize={{minRows: 2, maxRows: 8}} + /> +
+
+ ) + }) + } + + ) +} + +export default ParamsForm diff --git a/agenta-web/src/components/Playground/Views/TestView.tsx b/agenta-web/src/components/Playground/Views/TestView.tsx index ba34c49c78..fc3588057a 100644 --- a/agenta-web/src/components/Playground/Views/TestView.tsx +++ b/agenta-web/src/components/Playground/Views/TestView.tsx @@ -1,9 +1,9 @@ import React, {useState} from "react" -import {Button, Input, Card, Row, Col, Space} from "antd" +import {Button, Input, Card, Row, Col, Space, Form} from "antd" import {CaretRightOutlined, PlusOutlined} from "@ant-design/icons" import {callVariant} from "@/lib/services/api" import {ChatMessage, ChatRole, GenericObject, Parameter, Variant} from "@/lib/Types" -import {randString, removeKeys, renameVariables, safeParse} from "@/lib/helpers/utils" +import {randString, removeKeys} from "@/lib/helpers/utils" import LoadTestsModal from "../LoadTestsModal" import AddToTestSetDrawer from "../AddToTestSetDrawer/AddToTestSetDrawer" import {DeleteOutlined} from "@ant-design/icons" @@ -11,10 +11,12 @@ import {getErrorMessage} from "@/lib/helpers/errorHandler" import {createUseStyles} from "react-jss" import CopyButton from "@/components/CopyButton/CopyButton" import {useRouter} from "next/router" -import ChatInputs, {getDefaultNewMessage} from "@/components/ChatInputs/ChatInputs" +import {getDefaultNewMessage} from "@/components/ChatInputs/ChatInputs" import {v4 as uuidv4} from "uuid" import {testsetRowToChatMessages} from "@/lib/helpers/testset" +import ParamsForm from "../ParamsForm/ParamsForm" +const {TextArea} = Input const LOADING_TEXT = "Loading..." const useStylesBox = createUseStyles({ @@ -110,18 +112,16 @@ const BoxComponent: React.FC = ({ isChatVariant = false, }) => { const classes = useStylesBox() - const {TextArea} = Input const loading = result === LOADING_TEXT + const [form] = Form.useForm() if (!inputParams) { return
Loading...
} - const inputParamsNames = inputParams.map((param) => param.name) - const handleAddToTestset = () => { const params: Record = {} - inputParamsNames.forEach((name) => { + inputParams.forEach(({name}) => { params[name] = testData[name] || "" }) params.correct_answer = result @@ -142,22 +142,16 @@ const BoxComponent: React.FC = ({ - {isChatVariant ? ( - onInputParamChange("chat", val)} - /> - ) : ( - inputParamsNames.map((key, index) => ( -