Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bekossy committed May 18, 2024
1 parent 1002198 commit 7624354
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 32 deletions.
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
@@ -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"
Expand All @@ -16,41 +16,29 @@ const useStyles = createUseStyles((theme: any) => ({
}))

type AdvancedSettingsProps = {
settings: {key: string; label: string; default: string[]; required?: boolean}[]
form: any
settings: Record<string, any>[]
}

const AdvancedSettings: React.FC<AdvancedSettingsProps> = ({settings, form}) => {
const AdvancedSettings: React.FC<AdvancedSettingsProps> = ({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 (
<Collapse
bordered={false}
expandIcon={({isActive}) => <CaretRightOutlined rotate={isActive ? 90 : 0} />}
className={"my-[10px]"}
onChange={handleCollapseChange}
>
<Collapse.Panel key="1" header="Advanced Settings">
{settings.map((field) => (
<Form.Item
key={field.key}
name={["advancedSettings", field.key]}
initialValue={initialValues.correct_answer_keys[0]}
name={["settings_values", "correct_answer_keys"]}
label={
<div className={classes.label}>
<span>{field.label}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,25 @@ const NewEvaluatorModal: React.FC<Props> = ({
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 @@ -427,7 +442,7 @@ const NewEvaluatorModal: React.FC<Props> = ({
))}

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

<Form.Item style={{marginBottom: 0}}>
Expand Down

0 comments on commit 7624354

Please sign in to comment.