🐛 fix: Correct Model Parameters Merging and Panel UI (#5038)

* fix: Model Panel, watching wrong form field

* fix: Refactor agent initialization to merge model parameters correctly
This commit is contained in:
Danny Avila 2024-12-18 13:53:59 -05:00 committed by GitHub
parent 000641c619
commit f873587e5f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 35 additions and 15 deletions

View file

@ -1,7 +1,7 @@
import React, { useMemo, useEffect } from 'react';
import { ChevronLeft } from 'lucide-react';
import { ChevronLeft, RotateCcw } from 'lucide-react';
import { getSettingsKeys } from 'librechat-data-provider';
import { useFormContext, Controller } from 'react-hook-form';
import { useFormContext, useWatch, Controller } from 'react-hook-form';
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
import type * as t from 'librechat-data-provider';
import type { AgentForm, AgentModelPanelProps, StringOption } from '~/common';
@ -19,10 +19,11 @@ export default function Parameters({
}: AgentModelPanelProps) {
const localize = useLocalize();
const { control, setValue, watch } = useFormContext<AgentForm>();
const modelParameters = watch('model_parameters');
const providerOption = watch('provider');
const model = watch('model');
const { control, setValue } = useFormContext<AgentForm>();
const model = useWatch({ control, name: 'model' });
const providerOption = useWatch({ control, name: 'provider' });
const modelParameters = useWatch({ control, name: 'model_parameters' });
const provider = useMemo(() => {
const value =
@ -71,6 +72,10 @@ export default function Parameters({
setValue(`model_parameters.${optionKey}`, value);
};
const handleResetParameters = () => {
setValue('model_parameters', {} as t.AgentModelParameters);
};
return (
<div className="scrollbar-gutter-stable h-full min-h-[50vh] overflow-auto pb-12 text-sm">
<div className="model-panel relative flex flex-col items-center px-16 py-6 text-center">
@ -209,6 +214,17 @@ export default function Parameters({
);
})}
</div>
{/* Reset Parameters Button */}
<div className="mt-6 flex justify-center">
<button
type="button"
onClick={handleResetParameters}
className="btn btn-neutral flex w-full items-center justify-center gap-2 px-4 py-2 text-sm"
>
<RotateCcw className="h-4 w-4" />
{localize('com_ui_reset_var', localize('com_ui_model_parameters'))}
</button>
</div>
</div>
)}
</div>