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

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

Merged
merged 2 commits into from
Dec 18, 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
15 changes: 9 additions & 6 deletions api/server/services/Endpoints/agents/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,15 @@ const initializeAgentOptions = async ({
agent.endpoint = provider.toLowerCase();
}

const model_parameters = agent.model_parameters ?? { model: agent.model };
const _endpointOption = isInitialAgent
? endpointOption
: {
model_parameters,
};
const model_parameters = Object.assign(
{},
agent.model_parameters ?? { model: agent.model },
isInitialAgent === true ? endpointOption?.model_parameters : {},
);
const _endpointOption =
isInitialAgent === true
? Object.assign({}, endpointOption, { model_parameters })
: { model_parameters };

const options = await getOptions({
req,
Expand Down
6 changes: 3 additions & 3 deletions client/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ export type AgentPanelProps = {
};

export type AgentModelPanelProps = {
setActivePanel: React.Dispatch<React.SetStateAction<Panel>>;
providers: Option[];
models: Record<string, string[]>;
agent_id?: string;
providers: Option[];
models: Record<string, string[] | undefined>;
setActivePanel: React.Dispatch<React.SetStateAction<Panel>>;
};

export type AugmentedColumnDef<TData, TValue> = ColumnDef<TData, TValue> & DataColumnMeta;
Expand Down
28 changes: 22 additions & 6 deletions client/src/components/SidePanel/Agents/ModelPanel.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 =
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions client/src/localization/languages/Eng.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export default {
com_ui_provider: 'Provider',
com_ui_model: 'Model',
com_ui_region: 'Region',
com_ui_reset_var: 'Reset {0}',
com_ui_model_parameters: 'Model Parameters',
com_ui_model_save_success: 'Model parameters saved successfully',
com_ui_select_model: 'Select a model',
Expand Down
Loading