import { activeBotAtom } from '@/_helpers/atoms/Bot.atom' import { useAtomValue } from 'jotai' import React, { useEffect, useState } from 'react' import ExpandableHeader from '../ExpandableHeader' import { useDebouncedCallback } from 'use-debounce' import useUpdateBot from '@/_hooks/useUpdateBot' import ProgressSetting from '../ProgressSetting' import { set } from 'react-hook-form' const delayBeforeUpdateInMs = 1000 const BotSetting: React.FC = () => { const activeBot = useAtomValue(activeBotAtom) const [temperature, setTemperature] = useState(0) const [maxTokens, setMaxTokens] = useState(0) const [frequencyPenalty, setFrequencyPenalty] = useState(0) const [presencePenalty, setPresencePenalty] = useState(0) useEffect(() => { if (!activeBot) return setMaxTokens(activeBot.maxTokens ?? 0) setTemperature(activeBot.customTemperature ?? 0) setFrequencyPenalty(activeBot.frequencyPenalty ?? 0) setPresencePenalty(activeBot.presencePenalty ?? 0) }, [activeBot?._id]) const { updateBot } = useUpdateBot() const debouncedTemperature = useDebouncedCallback((value) => { if (!activeBot) return if (activeBot.customTemperature === value) return updateBot(activeBot, { customTemperature: value }) }, delayBeforeUpdateInMs) const debouncedMaxToken = useDebouncedCallback((value) => { if (!activeBot) return if (activeBot.maxTokens === value) return updateBot(activeBot, { maxTokens: value }) }, delayBeforeUpdateInMs) const debouncedFreqPenalty = useDebouncedCallback((value) => { if (!activeBot) return if (activeBot.frequencyPenalty === value) return updateBot(activeBot, { frequencyPenalty: value }) }, delayBeforeUpdateInMs) const debouncedPresencePenalty = useDebouncedCallback((value) => { if (!activeBot) return if (activeBot.presencePenalty === value) return updateBot(activeBot, { presencePenalty: value }) }, delayBeforeUpdateInMs) const debouncedSystemPrompt = useDebouncedCallback((value) => { if (!activeBot) return if (activeBot.systemPrompt === value) return updateBot(activeBot, { systemPrompt: value }) }, delayBeforeUpdateInMs) if (!activeBot) return null return (