import { apiInterceptors, getModelList, startModel, stopModel } from '@/client/api'; import ModelForm from '@/components/model/model-form'; import BlurredCard, { InnerDropdown } from '@/new-components/common/blurredCard'; import ConstructLayout from '@/new-components/layout/Construct'; import { IModelData } from '@/types/model'; import { getModelIcon } from '@/utils/constants'; import { PlusOutlined } from '@ant-design/icons'; import { Button, Modal, Tag, message } from 'antd'; import moment from 'moment'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; function Models() { const { t } = useTranslation(); const [models, setModels] = useState>([]); const [isModalOpen, setIsModalOpen] = useState(false); const [loading, setLoading] = useState(false); async function getModels() { const [, res] = await apiInterceptors(getModelList()); setModels(res ?? []); } async function startTheModel(info: IModelData) { if (loading) return; const content = t(`confirm_start_model`) + info.model_name; showConfirm(t('start_model'), content, async () => { setLoading(true); const [, , res] = await apiInterceptors( startModel({ host: info.host, port: info.port, model: info.model_name, worker_type: info.worker_type, delete_after: false, params: {}, }), ); setLoading(false); if (res?.success) { message.success(t('start_model_success')); await getModels(); } }); } async function stopTheModel(info: IModelData, delete_after = false) { if (loading) return; const action = delete_after ? 'stop_and_delete' : 'stop'; const content = t(`confirm_${action}_model`) + info.model_name; showConfirm(t(`${action}_model`), content, async () => { setLoading(true); const [, , res] = await apiInterceptors( stopModel({ host: info.host, port: info.port, model: info.model_name, worker_type: info.worker_type, delete_after: delete_after, params: {}, }), ); setLoading(false); if (res?.success === true) { message.success(t(`${action}_model_success`)); await getModels(); } }); } const showConfirm = (title: string, content: string, onOk: () => Promise) => { Modal.confirm({ title, content, onOk: async () => { await onOk(); }, okButtonProps: { className: 'bg-button-gradient', }, }); }; useEffect(() => { getModels(); }, []); // TODO: unuesed function // const onSearch = useDebounceFn( // async (e: any) => { // const v = e.target.value; // await modelSearch({ model_name: v }); // }, // { wait: 500 }, // ).run; const returnLogo = (name: string) => { return getModelIcon(name); }; return (
{/* } placeholder={t('please_enter_the_keywords')} onChange={onSearch} onPressEnter={onSearch} allowClear className="w-[230px] h-[40px] border-1 border-white backdrop-filter backdrop-blur-lg bg-white bg-opacity-30 dark:border-[#6f7f95] dark:bg-[#6f7f95] dark:bg-opacity-60" /> */}
{models.map(item => (

Host:

{item.host}

Manage Host:

{item.manager_host}:{item.manager_port}

Last Heart Beat:

{moment(item.last_heartbeat).format('YYYY-MM-DD HH:mm:ss')}

} name={item.model_name} key={item.model_name} RightTop={ stopTheModel(item)}> {t('stop_model')} ), }, { key: 'start_model', label: ( startTheModel(item)}> {t('start_model')} ), }, { key: 'stop_and_delete_model', label: ( stopTheModel(item, true)}> {t('stop_and_delete_model')} ), }, ], }} /> } rightTopHover={false} Tags={
{item.healthy ? 'Healthy' : 'Unhealthy'} {item.worker_type}
} /> ))}
{ setIsModalOpen(false); }} footer={null} > { setIsModalOpen(false); }} onSuccess={() => { setIsModalOpen(false); getModels(); }} />
); } export default Models;