Skip to content

Commit

Permalink
Merge pull request #301 from langchain-ai/nc/15apr/render-config-defa…
Browse files Browse the repository at this point in the history
…ults-when-editing

When editing existing bot render config defaults
  • Loading branch information
nfcampos authored Apr 15, 2024
2 parents 735fd45 + 325acac commit 12b556f
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions frontend/src/components/Config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,21 @@ const ORDER = [
"agent_type",
];

function assignDefaults(
config: ConfigInterface["config"] | undefined | null,
configDefaults: Schemas["configDefaults"],
) {
return config
? {
...config,
configurable: {
...configDefaults?.configurable,
...config.configurable,
},
}
: configDefaults;
}

export function Config(props: {
className?: string;
configSchema: Schemas["configSchema"];
Expand All @@ -487,7 +502,7 @@ export function Config(props: {
edit?: boolean;
}) {
const [values, setValues] = useState(
props.config?.config ?? props.configDefaults,
assignDefaults(props.config?.config, props.configDefaults),
);
const [selectedTools, setSelectedTools] = useState<Tool[]>([]);
const typeKey = "type";
Expand Down Expand Up @@ -526,7 +541,7 @@ export function Config(props: {
};

useEffect(() => {
setValues(props.config?.config ?? props.configDefaults);
setValues(assignDefaults(props.config?.config, props.configDefaults));
}, [props.config, props.configDefaults]);
useEffect(() => {
if (dropzone.acceptedFiles.length > 0) {
Expand Down

0 comments on commit 12b556f

Please sign in to comment.