import {Dropdown, Input, Label, Option, Select, Switch} from '@fluentui/react-components'; import {AddCircle20Regular, DataUsageSettings20Regular, Delete20Regular, Save20Regular} from '@fluentui/react-icons'; import React, {FC} from 'react'; import {Section} from '../components/Section'; import {Labeled} from '../components/Labeled'; import {ToolTipButton} from '../components/ToolTipButton'; import commonStore, {ApiParameters, Device, ModelParameters, Precision} from '../stores/commonStore'; import {observer} from 'mobx-react-lite'; import {toast} from 'react-toastify'; import {ValuedSlider} from '../components/ValuedSlider'; import {NumberInput} from '../components/NumberInput'; import {Page} from '../components/Page'; import {useNavigate} from 'react-router'; import {RunButton} from '../components/RunButton'; import {updateConfig} from '../apis'; export const Configs: FC = observer(() => { const [selectedIndex, setSelectedIndex] = React.useState(commonStore.currentModelConfigIndex); const [selectedConfig, setSelectedConfig] = React.useState(commonStore.modelConfigs[selectedIndex]); const navigate = useNavigate(); const updateSelectedIndex = (newIndex: number) => { setSelectedIndex(newIndex); setSelectedConfig(commonStore.modelConfigs[newIndex]); // if you don't want to update the config used by the current startup in real time, comment out this line commonStore.setCurrentConfigIndex(newIndex); }; const setSelectedConfigName = (newName: string) => { setSelectedConfig({...selectedConfig, name: newName}); }; const setSelectedConfigApiParams = (newParams: Partial) => { setSelectedConfig({ ...selectedConfig, apiParameters: { ...selectedConfig.apiParameters, ...newParams } }); }; const setSelectedConfigModelParams = (newParams: Partial) => { setSelectedConfig({ ...selectedConfig, modelParameters: { ...selectedConfig.modelParameters, ...newParams } }); }; const onClickSave = () => { commonStore.setModelConfig(selectedIndex, selectedConfig); updateConfig({ max_tokens: selectedConfig.apiParameters.maxResponseToken, temperature: selectedConfig.apiParameters.temperature, top_p: selectedConfig.apiParameters.topP, presence_penalty: selectedConfig.apiParameters.presencePenalty, frequency_penalty: selectedConfig.apiParameters.frequencyPenalty }); toast('Config Saved', {autoClose: 300, type: 'success'}); }; return (
{ if (data.optionValue) { updateSelectedIndex(Number(data.optionValue)); } }}> {commonStore.modelConfigs.map((config, index) => )} } onClick={() => { commonStore.createModelConfig(); updateSelectedIndex(commonStore.modelConfigs.length - 1); }}/> } onClick={() => { commonStore.deleteModelConfig(selectedIndex); updateSelectedIndex(Math.min(selectedIndex, commonStore.modelConfigs.length - 1)); }}/> } onClick={onClickSave}/>
{ setSelectedConfigName(data.value); }}/>
{ setSelectedConfigApiParams({ apiPort: data.value }); }}/> }/> { setSelectedConfigApiParams({ maxResponseToken: data.value }); }}/> }/> { setSelectedConfigApiParams({ temperature: data.value }); }}/> }/> { setSelectedConfigApiParams({ topP: data.value }); }}/> }/> { setSelectedConfigApiParams({ presencePenalty: data.value }); }}/> }/> { setSelectedConfigApiParams({ frequencyPenalty: data.value }); }}/> }/>
} />
} onClick={() => { navigate({pathname: '/models'}); }}/> }/> { if (data.optionText) { setSelectedConfigModelParams({ device: data.optionText as Device }); } }}> }/> { if (data.optionText) { setSelectedConfigModelParams({ precision: data.optionText as Precision }); } }}> }/> { setSelectedConfigModelParams({ storedLayers: data.value }); }}/> }/> { setSelectedConfigModelParams({ enableHighPrecisionForLastLayer: data.checked }); }}/> }/> } />
}/> ); });