import { activeBotAtom } from '@helpers/atoms/Bot.atom' import { useAtomValue } from 'jotai' import React, { useState } from 'react' import ExpandableHeader from '../ExpandableHeader' import { useDebouncedCallback } from 'use-debounce' import useUpdateBot from '@hooks/useUpdateBot' import { formatTwoDigits } from '@utils/converter' const delayBeforeUpdateInMs = 1000 const BotSetting: React.FC = () => { const activeBot = useAtomValue(activeBotAtom) const [temperature, setTemperature] = useState( activeBot?.customTemperature ?? 0 ) const [maxTokens, setMaxTokens] = useState(activeBot?.maxTokens ?? 0) const [frequencyPenalty, setFrequencyPenalty] = useState( activeBot?.frequencyPenalty ?? 0 ) const [presencePenalty, setPresencePenalty] = useState( activeBot?.presencePenalty ?? 0 ) 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 (
Max tokens
Frequency penalty
Presence penalty
Temperature