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

advanced settings in a separate component #1665

Merged
merged 2 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 0 additions & 9 deletions agenta-backend/agenta_backend/services/evaluator_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React 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: Record<string, any>[]
}

const AdvancedSettings: React.FC<AdvancedSettingsProps> = ({settings}) => {
const classes = useStyles()

const initialValues = settings.reduce((acc, field) => {
acc[field.key] = field.default
return acc
}, {})

return (
<Collapse
bordered={false}
expandIcon={({isActive}) => <CaretRightOutlined rotate={isActive ? 90 : 0} />}
className={"my-[10px]"}
>
<Collapse.Panel key="1" header="Advanced Settings">
{settings.map((field) => (
<Form.Item
key={field.key}
initialValue={initialValues.correct_answer_keys[0]}
name={["settings_values", "correct_answer_keys"]}
label={
<div className={classes.label}>
<span>{field.label}</span>
</div>
}
rules={[
{required: field.required ?? true, message: "This field is required"},
]}
>
{field.key === "correct_answer_keys" && <Input />}
</Form.Item>
))}
</Collapse.Panel>
</Collapse>
)
}

export default AdvancedSettings
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -170,7 +171,7 @@ const DynamicFormField: React.FC<DynamicFormFieldProps> = ({

return (
<>
{label !== "Correct Answer" ? (
{label !== "Correct Answer" && (
<Form.Item
name={name}
label={
Expand Down Expand Up @@ -213,36 +214,6 @@ const DynamicFormField: React.FC<DynamicFormFieldProps> = ({
/>
) : null}
</Form.Item>
) : (
<>
<Collapse
bordered={false}
expandIcon={({isActive}) => (
<CaretRightOutlined rotate={isActive ? 90 : 0} />
)}
className={"my-[10px]"}
items={[
{
key: "1",
label: "Advanced Settings",
children: (
<Form.Item
name={name}
label={
<div className={classes.label}>
<span>{label}</span>
</div>
}
initialValue={defaultVal}
rules={rules}
>
<Input className="w-[50%]" />
</Form.Item>
),
},
]}
/>
</>
)}

{ExternalHelpInfo}
Expand Down Expand Up @@ -309,13 +280,30 @@ const NewEvaluatorModal: React.FC<Props> = ({
}
}, [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")
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)
Expand Down Expand Up @@ -453,6 +441,10 @@ const NewEvaluatorModal: React.FC<Props> = ({
/>
))}

{advancedSettingsFields.length > 0 && (
<AdvancedSettings settings={advancedSettingsFields} />
)}

<Form.Item style={{marginBottom: 0}}>
<div className={classes.evalBtnContainer}>
{!editMode && (
Expand Down
Loading