From 10021987aa106be929e2d79acbefeb61337c767e Mon Sep 17 00:00:00 2001 From: aakrem Date: Fri, 17 May 2024 22:24:15 +0200 Subject: [PATCH 1/2] advanced settings in a separate component --- .../evaluators/AdvancedSettings.tsx | 71 +++++++++++++++++++ .../evaluators/NewEvaluatorModal.tsx | 39 +++------- 2 files changed, 79 insertions(+), 31 deletions(-) create mode 100644 agenta-web/src/components/pages/evaluations/evaluators/AdvancedSettings.tsx diff --git a/agenta-web/src/components/pages/evaluations/evaluators/AdvancedSettings.tsx b/agenta-web/src/components/pages/evaluations/evaluators/AdvancedSettings.tsx new file mode 100644 index 0000000000..0c8d4cfc6d --- /dev/null +++ b/agenta-web/src/components/pages/evaluations/evaluators/AdvancedSettings.tsx @@ -0,0 +1,71 @@ +import React, {useState, useEffect} from "react" +import {Form, Input, Collapse} from "antd" +import {CaretRightOutlined} from "@ant-design/icons" +import {createUseStyles} from "react-jss" + +type AdvancedSettings = { + correct_answer_keys: string[] +} + +const useStyles = createUseStyles((theme: any) => ({ + label: { + display: "flex", + alignItems: "center", + gap: "0.5rem", + }, +})) + +type AdvancedSettingsProps = { + settings: {key: string; label: string; default: string[]; required?: boolean}[] + form: any +} + +const AdvancedSettings: React.FC = ({settings, form}) => { + const classes = useStyles() + const [isCollapsed, setIsCollapsed] = useState(true) + + const handleCollapseChange = (key: string[]) => { + setIsCollapsed(!key.length) + } + + useEffect(() => { + // Initialize the form with default values for advanced settings + const initialValues = settings.reduce((acc, field) => { + acc[field.key] = field.default + return acc + }, {}) + form.setFieldsValue({advancedSettings: initialValues}) + }, [form, settings]) + + console.log("Passed settings to AdvancedSettings:", settings) + + return ( + } + className={"my-[10px]"} + onChange={handleCollapseChange} + > + + {settings.map((field) => ( + + {field.label} + + } + rules={[ + {required: field.required ?? true, message: "This field is required"}, + ]} + > + {field.key === "correct_answer_keys" && } + + ))} + + + ) +} + +export default AdvancedSettings diff --git a/agenta-web/src/components/pages/evaluations/evaluators/NewEvaluatorModal.tsx b/agenta-web/src/components/pages/evaluations/evaluators/NewEvaluatorModal.tsx index 1cf22cd2d7..546fa9e815 100644 --- a/agenta-web/src/components/pages/evaluations/evaluators/NewEvaluatorModal.tsx +++ b/agenta-web/src/components/pages/evaluations/evaluators/NewEvaluatorModal.tsx @@ -35,6 +35,7 @@ import Link from "next/link" import React, {useEffect, useMemo, useState} from "react" import {createUseStyles} from "react-jss" import {ColumnsType} from "antd/es/table" +import AdvancedSettings from "./AdvancedSettings" const useStyles = createUseStyles((theme: JSSTheme) => ({ label: { @@ -170,7 +171,7 @@ const DynamicFormField: React.FC = ({ return ( <> - {label !== "Correct Answer" ? ( + {label !== "Correct Answer" && ( = ({ /> ) : null} - ) : ( - <> - ( - - )} - className={"my-[10px]"} - items={[ - { - key: "1", - label: "Advanced Settings", - children: ( - - {label} - - } - initialValue={defaultVal} - rules={rules} - > - - - ), - }, - ]} - /> - )} {ExternalHelpInfo} @@ -309,6 +280,8 @@ const NewEvaluatorModal: React.FC = ({ } }, [newEvalModalConfigOpen]) + const advancedSettingsFields = evalFields.filter((field) => field.key === "correct_answer_keys") + const onSubmit = (values: CreateEvaluationConfigData) => { setSubmitLoading(true) if (!selectedEval?.key) throw new Error("No selected key") @@ -453,6 +426,10 @@ const NewEvaluatorModal: React.FC = ({ /> ))} + {advancedSettingsFields.length > 0 && ( + + )} +
{!editMode && ( From 7624354747612a17476ff4774f05fe7663ee7d8e Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Sat, 18 May 2024 10:32:51 +0100 Subject: [PATCH 2/2] bug fix --- .../services/evaluator_manager.py | 9 ------ .../evaluators/AdvancedSettings.tsx | 30 ++++++------------- .../evaluators/NewEvaluatorModal.tsx | 19 ++++++++++-- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/agenta-backend/agenta_backend/services/evaluator_manager.py b/agenta-backend/agenta_backend/services/evaluator_manager.py index de262987cc..d5b22279c7 100644 --- a/agenta-backend/agenta_backend/services/evaluator_manager.py +++ b/agenta-backend/agenta_backend/services/evaluator_manager.py @@ -80,15 +80,6 @@ async def create_evaluator_config( EvaluatorConfigDB: The newly created evaluator configuration object. """ app = await db_manager.fetch_app_by_id(app_id) - evaluator_config = evaluators.get_evaluator_by_key(evaluator_key) - - if evaluator_config is not None: - if "correct_answer_keys" in evaluator_config.get("settings_template", {}): - if settings_values is None: - settings_values = {} - settings_values["correct_answer_keys"] = evaluator_config[ - "settings_template" - ]["correct_answer_keys"]["default"] evaluator_config = await db_manager.create_evaluator_config( app=app, diff --git a/agenta-web/src/components/pages/evaluations/evaluators/AdvancedSettings.tsx b/agenta-web/src/components/pages/evaluations/evaluators/AdvancedSettings.tsx index 0c8d4cfc6d..b86c54d8b7 100644 --- a/agenta-web/src/components/pages/evaluations/evaluators/AdvancedSettings.tsx +++ b/agenta-web/src/components/pages/evaluations/evaluators/AdvancedSettings.tsx @@ -1,4 +1,4 @@ -import React, {useState, useEffect} from "react" +import React from "react" import {Form, Input, Collapse} from "antd" import {CaretRightOutlined} from "@ant-design/icons" import {createUseStyles} from "react-jss" @@ -16,41 +16,29 @@ const useStyles = createUseStyles((theme: any) => ({ })) type AdvancedSettingsProps = { - settings: {key: string; label: string; default: string[]; required?: boolean}[] - form: any + settings: Record[] } -const AdvancedSettings: React.FC = ({settings, form}) => { +const AdvancedSettings: React.FC = ({settings}) => { const classes = useStyles() - const [isCollapsed, setIsCollapsed] = useState(true) - const handleCollapseChange = (key: string[]) => { - setIsCollapsed(!key.length) - } - - useEffect(() => { - // Initialize the form with default values for advanced settings - const initialValues = settings.reduce((acc, field) => { - acc[field.key] = field.default - return acc - }, {}) - form.setFieldsValue({advancedSettings: initialValues}) - }, [form, settings]) - - console.log("Passed settings to AdvancedSettings:", settings) + const initialValues = settings.reduce((acc, field) => { + acc[field.key] = field.default + return acc + }, {}) return ( } className={"my-[10px]"} - onChange={handleCollapseChange} > {settings.map((field) => ( {field.label} diff --git a/agenta-web/src/components/pages/evaluations/evaluators/NewEvaluatorModal.tsx b/agenta-web/src/components/pages/evaluations/evaluators/NewEvaluatorModal.tsx index 546fa9e815..8114845751 100644 --- a/agenta-web/src/components/pages/evaluations/evaluators/NewEvaluatorModal.tsx +++ b/agenta-web/src/components/pages/evaluations/evaluators/NewEvaluatorModal.tsx @@ -285,10 +285,25 @@ const NewEvaluatorModal: React.FC = ({ const onSubmit = (values: CreateEvaluationConfigData) => { setSubmitLoading(true) if (!selectedEval?.key) throw new Error("No selected key") + const settingsValues = values.settings_values || {} + + if (settingsValues.correct_answer_keys) { + settingsValues.correct_answer_keys = Array.isArray(settingsValues.correct_answer_keys) + ? settingsValues.correct_answer_keys + : [settingsValues.correct_answer_keys] + } + + if ( + !settingsValues.correct_answer_keys && + selectedEval.settings_template.correct_answer_keys + ) { + settingsValues["correct_answer_keys"] = ["correct_answer"] + } + const data = { ...values, evaluator_key: selectedEval.key, - settings_values: values.settings_values || {}, + settings_values: settingsValues, } ;(editMode ? updateEvaluatorConfig(initialValues?.id!, data) @@ -427,7 +442,7 @@ const NewEvaluatorModal: React.FC = ({ ))} {advancedSettingsFields.length > 0 && ( - + )}