import { useMemo } from 'react'; import { useRecoilValue } from 'recoil'; import TextareaAutosize from 'react-textarea-autosize'; import { useAvailablePluginsQuery } from 'librechat-data-provider/react-query'; import { Input, Label, Slider, HoverCard, InputNumber, SelectDropDown, HoverCardTrigger, } from '@librechat/client'; import type { TModelSelectProps, OnInputNumberChange } from '~/common'; import type { TPlugin } from 'librechat-data-provider'; import { removeFocusOutlines, defaultTextProps, removeFocusRings, processPlugins, selectPlugins, optionText, cn, } from '~/utils'; import OptionHoverAlt from '~/components/SidePanel/Parameters/OptionHover'; import MultiSelectDropDown from '~/components/Input/ModelSelect/MultiSelectDropDown'; import { useLocalize, useDebouncedInput } from '~/hooks'; import OptionHover from './OptionHover'; import { ESide } from '~/common'; import store from '~/store'; export default function Settings({ conversation, setOption, setTools, checkPluginSelection, models, readonly, }: TModelSelectProps & { setTools: (newValue: string, remove?: boolean | undefined) => void; checkPluginSelection: (value: string) => boolean; }) { const localize = useLocalize(); const availableTools = useRecoilValue(store.availableTools); const { data: allPlugins } = useAvailablePluginsQuery({ select: selectPlugins, }); const conversationTools: TPlugin[] = useMemo(() => { if (!conversation?.tools) { return []; } return processPlugins(conversation.tools, allPlugins?.map); }, [conversation, allPlugins]); const availablePlugins = useMemo(() => { if (!availableTools) { return []; } return Object.values(availableTools); }, [availableTools]); const { model, modelLabel, chatGptLabel, promptPrefix, temperature, top_p: topP, frequency_penalty: freqP, presence_penalty: presP, maxContextTokens, } = conversation ?? {}; const [setChatGptLabel, chatGptLabelValue] = useDebouncedInput({ setOption, optionKey: 'chatGptLabel', initialValue: modelLabel ?? chatGptLabel, }); const [setPromptPrefix, promptPrefixValue] = useDebouncedInput({ setOption, optionKey: 'promptPrefix', initialValue: promptPrefix, }); const [setTemperature, temperatureValue] = useDebouncedInput({ setOption, optionKey: 'temperature', initialValue: temperature, }); const [setTopP, topPValue] = useDebouncedInput({ setOption, optionKey: 'top_p', initialValue: topP, }); const [setFreqP, freqPValue] = useDebouncedInput({ setOption, optionKey: 'frequency_penalty', initialValue: freqP, }); const [setPresP, presPValue] = useDebouncedInput({ setOption, optionKey: 'presence_penalty', initialValue: presP, }); const [setMaxContextTokens, maxContextTokensValue] = useDebouncedInput( { setOption, optionKey: 'maxContextTokens', initialValue: maxContextTokens, }, ); const setModel = setOption('model'); if (!conversation) { return null; } return (
<>
setChatGptLabel(e.target.value ?? null)} placeholder={localize('com_endpoint_openai_custom_name_placeholder')} className={cn( defaultTextProps, 'flex h-10 max-h-10 w-full resize-none px-3 py-2', removeFocusOutlines, )} />
setPromptPrefix(e.target.value ?? null)} placeholder={localize( 'com_endpoint_plug_set_custom_instructions_for_gpt_placeholder', )} className={cn( defaultTextProps, 'flex max-h-[138px] min-h-[100px] w-full resize-none px-3 py-2', )} />
setTemperature(Number(value))} max={2} min={0} step={0.01} controls={false} className={cn( defaultTextProps, cn( optionText, 'reset-rc-number-input reset-rc-number-input-text-right h-auto w-12 border-0 group-hover/temp:border-gray-200', ), )} />
setTemperature(value[0])} onDoubleClick={() => setTemperature(0.8)} max={2} min={0} step={0.01} className="flex h-4 w-full" aria-labelledby="temp-int" />
setTopP(Number(value))} max={1} min={0} step={0.01} controls={false} className={cn( defaultTextProps, cn( optionText, 'reset-rc-number-input reset-rc-number-input-text-right h-auto w-12 border-0 group-hover/temp:border-gray-200', ), )} />
setTopP(value[0])} onDoubleClick={() => setTopP(1)} max={1} min={0} step={0.01} className="flex h-4 w-full" aria-labelledby="top-p-int" />
setFreqP(Number(value))} max={2} min={-2} step={0.01} controls={false} className={cn( defaultTextProps, cn( optionText, 'reset-rc-number-input reset-rc-number-input-text-right h-auto w-12 border-0 group-hover/temp:border-gray-200', ), )} />
setFreqP(value[0])} onDoubleClick={() => setFreqP(0)} max={2} min={-2} step={0.01} className="flex h-4 w-full" aria-labelledby="freq-penalty-int" />
setPresP(Number(value))} max={2} min={-2} step={0.01} controls={false} className={cn( defaultTextProps, cn( optionText, 'reset-rc-number-input reset-rc-number-input-text-right h-auto w-12 border-0 group-hover/temp:border-gray-200', ), )} />
setPresP(value[0])} onDoubleClick={() => setPresP(0)} max={2} min={-2} step={0.01} className="flex h-4 w-full" aria-labelledby="pres-penalty-int" />
); }