CzRger hace 4 meses
padre
commit
d09e993a40

+ 1 - 1
web/app/components/skill/log/index.tsx

@@ -10,7 +10,7 @@ const LogIndex = () => {
   const [limit, setLimit] = useState<number>(10)
   const { data, mutate }: any = useSWR(
     {
-      url: '/xxx',
+      url: '/intentions/train_tasks',
       params: {
         page: page + 1,
         limit,

+ 27 - 4
web/app/components/skill/log/list.tsx

@@ -3,6 +3,9 @@ import Pagination, { type Props as PaginationProps } from '@/app/components/base
 import type { FC } from 'react'
 import Button from '@/app/components/base/button'
 import cn from '@/utils/classnames'
+import { useTranslation } from 'react-i18next'
+import useTimestamp from '@/hooks/use-timestamp'
+import { downloadLogFile } from '@/service/common'
 
 type PageListProps = {
   list: []
@@ -15,12 +18,27 @@ const LogPageList: FC<PageListProps> = ({
   pagination,
   onUpdate,
 }) => {
+  const { t } = useTranslation()
+  const { formatTime } = useTimestamp()
+  const statusMap = new Map([
+    ['CREATED', '创建'],
+    ['TRAINING', '训练中'],
+    ['COMPLETED', '完成'],
+  ])
+  const handleDownload = async (item: any) => {
+    await downloadLogFile({
+      url: `/intentions/train_tasks/download/${item.id}`,
+      fileName: item.name,
+    })
+  }
   return (
     <div className='relative flex h-full w-full flex-col'>
       <div className='relative grow overflow-x-auto'>
         <table className={'mt-3 w-full min-w-[700px] max-w-full border-collapse border-0 text-sm'}>
           <thead className="h-8 border-b border-divider-subtle text-xs font-medium uppercase leading-8 text-text-tertiary">
             <tr>
+              <td>训练任务</td>
+              <td>训练状态</td>
               <td>训练语料数据集版本</td>
               <td>训练时间</td>
               <td>训练模型结果版本</td>
@@ -33,11 +51,16 @@ const LogPageList: FC<PageListProps> = ({
                 key={item.id}
                 className={'h-8 border-b border-divider-subtle hover:bg-background-default-hover'}
               >
-                <td>{item.version}</td>
-                <td>{item.time}</td>
-                <td>{item.version}</td>
+                <td>{item.name}</td>
+                <td>{statusMap.get(item.status)}</td>
+                <td>{item.dataset_info.version}</td>
+                <td>{formatTime(item.created_at, t('datasetHitTesting.dateTimeFormat') as string)}</td>
+                <td>{item.model_info.version}</td>
                 <td className="flex justify-center gap-2">
-                  <Button variant='ghost-accent' size='small' className={cn('shrink-0')}>
+                  <Button variant='ghost-accent' size='small' className={cn('shrink-0')} onClick={(e) => {
+                    e.stopPropagation()
+                    handleDownload(item)
+                  }}>
                     下载
                   </Button>
                 </td>

+ 6 - 20
web/service/common.ts

@@ -442,26 +442,12 @@ export const fetchStatistic = ({ url, params }: any) => {
 
 export const fetchLog = ({ url, params }: any) => {
   console.log('查询训练日志列表', url, params)
-  // return get(url, { params })
-  return new Promise((resolve) => {
-    setTimeout(() => {
-      const arr: any = []
-      for (let i = 1; i < 10; i++) {
-        arr.push({
-          id: i,
-          version: `${i}.${i}.${i}`,
-          time: '2022-02-02 02:21:23',
-        })
-      }
-      resolve({
-        data: [],
-        has_more: false,
-        limit: 10,
-        total: 0,
-        page: 1,
-      })
-    }, 1000)
-  })
+  return get(url, { params })
+}
+
+export const downloadLogFile = ({ url, fileName }: any) => {
+  console.log('下载训练日志文件', url, fileName)
+  return download(url, {}, { fileName })
 }
 
 export const fetchIntentType = ({ url, params }: any) => {