From 56875172386ebf7e72d039c21b933a416ee7f9f3 Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Sun, 1 Dec 2024 15:52:52 +0530 Subject: [PATCH] feat: Add save functionality for system prompt and model settings --- .../Settings/CurrentChatModelSettings.tsx | 56 ++++++++++++------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/src/components/Common/Settings/CurrentChatModelSettings.tsx b/src/components/Common/Settings/CurrentChatModelSettings.tsx index 2914266..d626c14 100644 --- a/src/components/Common/Settings/CurrentChatModelSettings.tsx +++ b/src/components/Common/Settings/CurrentChatModelSettings.tsx @@ -5,15 +5,17 @@ import { useStoreChatModelSettings } from "@/store/model" import { useQuery } from "@tanstack/react-query" import { Collapse, + Divider, Drawer, Form, Input, InputNumber, Modal, Skeleton, - Switch + Switch, + Button } from "antd" -import React from "react" +import React, { useState, useCallback } from "react" import { useTranslation } from "react-i18next" type Props = { @@ -31,6 +33,19 @@ export const CurrentChatModelSettings = ({ const [form] = Form.useForm() const cUserSettings = useStoreChatModelSettings() const { selectedSystemPrompt } = useMessageOption() + + const savePrompt = useCallback((value: string) => { + cUserSettings.setX('systemPrompt', value) + }, [cUserSettings]) + + const saveSettings = useCallback((values: any) => { + Object.entries(values).forEach(([key, value]) => { + if (key !== 'systemPrompt') { + cUserSettings.setX(key, value) + } + }) + }, [cUserSettings]) + const { isPending: isLoading } = useQuery({ queryKey: ["fetchModelConfig2", open], queryFn: async () => { @@ -68,19 +83,12 @@ export const CurrentChatModelSettings = ({ <> {!isLoading ? (
{ - Object.entries(values).forEach(([key, value]) => { - cUserSettings.setX(key, value) - setOpen(false) - }) - }} form={form} - layout="vertical"> + layout="vertical" + onFinish={(values) => { + saveSettings(values) + setOpen(false) + }}> {useDrawer && ( <> savePrompt(e.target.value)} /> + )} + + @@ -140,6 +152,8 @@ export const CurrentChatModelSettings = ({ /> + + - - + ) : ( @@ -209,7 +223,8 @@ export const CurrentChatModelSettings = ({ open={open} onClose={() => setOpen(false)} width={500} - title={t("currentChatModelSettings")}> + title={t("currentChatModelSettings")} + > {renderBody()} ) @@ -221,7 +236,8 @@ export const CurrentChatModelSettings = ({ open={open} onOk={() => setOpen(false)} onCancel={() => setOpen(false)} - footer={null}> + footer={null} + > {renderBody()} )