fix(settings): select proper brain model (#943)

* fix(settings): select proper brain model

* feat(settings): save model on change
This commit is contained in:
Gustavo J. Maciel 2023-08-18 06:12:17 -04:00 committed by GitHub
parent d1dfd6c7ec
commit 3a44f54d6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -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) => (

View File

@ -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;