From a0ceea52580ad0aac4bbd908728ac123edf374e8 Mon Sep 17 00:00:00 2001 From: AbdBarho Date: Sat, 22 Apr 2023 17:28:10 +0200 Subject: [PATCH 1/4] Fix saving model between chats --- website/src/components/Chat/ChatConfigForm.tsx | 13 ++++++++++--- website/src/components/Chat/ChatConfigSaver.tsx | 9 +++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/website/src/components/Chat/ChatConfigForm.tsx b/website/src/components/Chat/ChatConfigForm.tsx index 94032cefda..560b6e0773 100644 --- a/website/src/components/Chat/ChatConfigForm.tsx +++ b/website/src/components/Chat/ChatConfigForm.tsx @@ -17,7 +17,7 @@ import { Tooltip, } from "@chakra-ui/react"; import { useTranslation } from "next-i18next"; -import { ChangeEvent, memo, useCallback, useState } from "react"; +import { ChangeEvent, memo, SyntheticEvent, useCallback, useState } from "react"; import { Controller, useFormContext, useWatch } from "react-hook-form"; import { ChatConfigFormData, SamplingParameters } from "src/types/Chat"; @@ -85,7 +85,7 @@ export const ChatConfigForm = memo(function ChatConfigForm() { const { t } = useTranslation("chat"); const { modelInfos } = useChatContext(); - const { control, register, reset, getValues } = useFormContext(); + const { control, register, reset, getValues, setValue } = useFormContext(); const selectedModel = useWatch({ name: "model_config_name", control: control }); const presets = modelInfos.find((model) => model.name === selectedModel)!.parameter_configs; const [selectedPresetName, setSelectedPresetName] = useState( @@ -105,11 +105,18 @@ export const ChatConfigForm = memo(function ChatConfigForm() { [presets, reset, selectedModel] ); + // I have no idea why we need to do this manually, it seems that the model name keeps resetting if we are just using + // react-form default "register" + const handleModelChange = useCallback( + (e: SyntheticEvent) => setValue("model_config_name", e.currentTarget.value), + [setValue] + ); + return ( {t("model")} - {modelInfos.map(({ name }) => (