mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-24 03:41:56 +03:00
fix(settings): select proper brain model (#943)
* fix(settings): select proper brain model * feat(settings): save model on change
This commit is contained in:
parent
d1dfd6c7ec
commit
3a44f54d6b
@ -46,7 +46,7 @@ export const SettingsTab = ({ brainId }: SettingsTabProps): JSX.Element => {
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
void handleSubmit();
|
||||
void handleSubmit(true);
|
||||
}}
|
||||
className="my-10 mb-0 flex flex-col items-center gap-2"
|
||||
ref={formRef}
|
||||
@ -101,6 +101,9 @@ export const SettingsTab = ({ brainId }: SettingsTabProps): JSX.Element => {
|
||||
id="model"
|
||||
{...register("model")}
|
||||
className="px-5 py-2 dark:bg-gray-700 bg-gray-200 rounded-md"
|
||||
onChange={() => {
|
||||
void handleSubmit(false); // Trigger form submission
|
||||
}}
|
||||
>
|
||||
{(openAiKey !== undefined ? paidModels : freeModels).map(
|
||||
(availableModel) => (
|
||||
|
@ -90,6 +90,13 @@ export const useSettingsTab = ({ brainId }: UseSettingsTabProps) => {
|
||||
// eslint-disable-next-line
|
||||
if (Boolean(brain[key])) setValue(key, brain[key]);
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
if (brain.model !== undefined) {
|
||||
setValue("model", brain.model);
|
||||
}
|
||||
},50);
|
||||
|
||||
};
|
||||
useEffect(() => {
|
||||
void fetchBrain();
|
||||
@ -103,7 +110,7 @@ export const useSettingsTab = ({ brainId }: UseSettingsTabProps) => {
|
||||
const handleKeyPress = (event: KeyboardEvent) => {
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
void handleSubmit();
|
||||
void handleSubmit(true);
|
||||
}
|
||||
};
|
||||
|
||||
@ -196,10 +203,9 @@ export const useSettingsTab = ({ brainId }: UseSettingsTabProps) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
const handleSubmit = async (checkDirty:boolean) => {
|
||||
const hasChanges = Object.keys(dirtyFields).length > 0;
|
||||
|
||||
if (!hasChanges) {
|
||||
if (!hasChanges && checkDirty) {
|
||||
return;
|
||||
}
|
||||
const { name: isNameDirty } = dirtyFields;
|
||||
|
Loading…
Reference in New Issue
Block a user