import React, { useState, useEffect } from 'react' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faAngleDown, faAngleUp } from '@fortawesome/free-solid-svg-icons' import { SetVariableMappings, VariableMappings, Config, SetConfig } from '../types/types' import JsonBox from './JsonBox' // Types for SettingsPanel type SettingsPanelProps = { config: Config setConfig: SetConfig variableMappings: VariableMappings setVariableMappings: SetVariableMappings isValidJson: boolean setIsValidJson: (arg0: boolean) => void isValidRegex: boolean setIsValidRegex: (arg0: boolean) => void } const SettingsPanel = ({ config, setConfig, isValidJson, setIsValidJson, isValidRegex, setIsValidRegex, }: SettingsPanelProps) => { const [showConfig, setShowConfig] = useState(true) useEffect(() => { try { console.log('trying regex') new RegExp(config.generation_parameters.regex_string) setIsValidRegex(true) } catch (e) { setIsValidRegex(false) } }, [config.generation_parameters.regex_string]) return (
{showConfig && (
setConfig((prev) => ({ ...prev, system_prompt: e.target.value, })) } /> { setConfig((prev) => ({ ...prev, generation_parameters: { ...prev.generation_parameters, sampling_temperature: parseFloat(e.target.value), }, })) }} onBlur={(e) => { if (e.target.value === '' || e.target.value === null) { setConfig((prev) => ({ ...prev, generation_parameters: { ...prev.generation_parameters, sampling_temperature: 1.0, }, })) } }} placeholder='1.0' /> { setConfig((prev) => ({ ...prev, generation_parameters: { ...prev.generation_parameters, sampling_topp: parseFloat(e.target.value), }, })) }} onBlur={(e) => { if (e.target.value === '' || e.target.value === null) { setConfig((prev) => ({ ...prev, generation_parameters: { ...prev.generation_parameters, sampling_topp: 1.0, }, })) } }} placeholder='1.0' /> { setConfig((prev) => ({ ...prev, generation_parameters: { ...prev.generation_parameters, sampling_topk: parseFloat(e.target.value), }, })) }} onBlur={(e) => { if (e.target.value === '' || e.target.value === null) { setConfig((prev) => ({ ...prev, generation_parameters: { ...prev.generation_parameters, sampling_topk: 10, }, })) } }} min={0} placeholder='10' /> { setConfig((prev) => ({ ...prev, generation_parameters: { ...prev.generation_parameters, max_new_tokens: parseFloat(e.target.value), }, })) }} onBlur={(e) => { if (e.target.value === '' || e.target.value === null) { setConfig((prev) => ({ ...prev, generation_parameters: { ...prev.generation_parameters, max_new_tokens: 300, }, })) } }} min={1} placeholder='300' /> setConfig((prev) => ({ ...prev, generation_parameters: { ...prev.generation_parameters, regex_string: e.target.value, }, })) } placeholder='Regex string' /> {!isValidRegex &&

Invalid Regex

}
)} {/* {showTemplateVariables && false &&
{Object.entries(variableMappings).map(([variable, value]) => (
setVariableMappings((prev) => ({ ...prev, [variable]: e.target.value }))} />
))}
} {showGenerationPlaceholders &&
}*/}
) } export default SettingsPanel