fix: model list not refresh

This commit is contained in:
jialin
2024-07-12 16:17:47 +08:00
parent d839464a05
commit 0a0b96735c
13 changed files with 63 additions and 35 deletions
+2 -4
View File
@@ -1,6 +1,6 @@
import { GPUStackVersionAtom } from '@/atoms/user'; import { GPUStackVersionAtom } from '@/atoms/user';
import { getAtomStorage } from '@/atoms/utils'; import { getAtomStorage } from '@/atoms/utils';
import VersionInfo from '@/components/version-info'; import VersionInfo, { modalConfig } from '@/components/version-info';
import externalLinks from '@/config/external-links'; import externalLinks from '@/config/external-links';
import { useIntl } from '@umijs/max'; import { useIntl } from '@umijs/max';
import { Button, Modal, Space } from 'antd'; import { Button, Modal, Space } from 'antd';
@@ -11,9 +11,7 @@ const Footer: React.FC = () => {
const showVersion = () => { const showVersion = () => {
Modal.info({ Modal.info({
icon: null, ...modalConfig,
centered: false,
width: 500,
content: <VersionInfo intl={intl} /> content: <VersionInfo intl={intl} />
}); });
}; };
@@ -36,8 +36,9 @@ const TableRow: React.FC<
const pollTimer = useRef<any>(null); const pollTimer = useRef<any>(null);
const chunkRequestRef = useRef<any>(null); const chunkRequestRef = useRef<any>(null);
const childrenDataRef = useRef<any[]>([]); const childrenDataRef = useRef<any[]>([]);
childrenDataRef.current = childrenData;
console.log('table row===='); console.log('table row====', record.name, firstLoad, expanded);
const { updateChunkedList } = useUpdateChunkedList({ const { updateChunkedList } = useUpdateChunkedList({
setDataList: setChildrenData setDataList: setChildrenData
// callback: (list) => renderChildren?.(list) // callback: (list) => renderChildren?.(list)
@@ -54,10 +55,6 @@ const TableRow: React.FC<
} }
}, [rowSelection]); }, [rowSelection]);
useEffect(() => {
childrenDataRef.current = childrenData;
}, [childrenData]);
// useEffect(() => { // useEffect(() => {
// if (expandedRowKeys?.includes(record[rowKey])) { // if (expandedRowKeys?.includes(record[rowKey])) {
// setExpanded(true); // setExpanded(true);
+4 -1
View File
@@ -69,7 +69,10 @@ const StatusTag: React.FC<StatusTagProps> = ({
}} }}
> >
{statusValue.message ? ( {statusValue.message ? (
<Tooltip title={statusValue.message}> <Tooltip
title={statusValue.message}
overlayInnerStyle={{ maxHeight: 200, overflow: 'auto' }}
>
<span className="m-r-5"> <span className="m-r-5">
<InfoCircleOutlined /> <InfoCircleOutlined />
</span> </span>
+1
View File
@@ -6,6 +6,7 @@
.img { .img {
margin-top: 16px; margin-top: 16px;
margin-bottom: 30px;
text-align: center; text-align: center;
height: 30px; height: 30px;
+8 -3
View File
@@ -13,9 +13,6 @@ const VersionInfo: React.FC<{ intl: any }> = ({ intl }) => {
<div className="img"> <div className="img">
<img src={Logo} alt="logo" /> <img src={Logo} alt="logo" />
</div> </div>
<div className="title">
{intl.formatMessage({ id: 'common.footer.version.title' })}
</div>
<div> <div>
<div className="ver"> <div className="ver">
<span className="label"> <span className="label">
@@ -36,4 +33,12 @@ const VersionInfo: React.FC<{ intl: any }> = ({ intl }) => {
); );
}; };
export const modalConfig = {
icon: null,
centered: false,
maskClosable: true,
footer: null,
width: 400
};
export default VersionInfo; export default VersionInfo;
+7
View File
@@ -1,3 +1,4 @@
import _ from 'lodash';
import { useRef } from 'react'; import { useRef } from 'react';
export default function useContainerScroll( export default function useContainerScroll(
@@ -8,8 +9,14 @@ export default function useContainerScroll(
const scroller = useRef(container); const scroller = useRef(container);
const optionsRef = useRef(options); const optionsRef = useRef(options);
const toBottomFlag = useRef(options?.toBottom); const toBottomFlag = useRef(options?.toBottom);
const debunceResetWheeled = _.debounce(() => {
isWheeled.current = false;
}, 5000);
const handleContentWheel = (e: any) => { const handleContentWheel = (e: any) => {
isWheeled.current = true; isWheeled.current = true;
debunceResetWheeled();
}; };
const scrollerRun = () => { const scrollerRun = () => {
+8 -3
View File
@@ -35,6 +35,7 @@ export function useUpdateChunkedList(options: {
const ids = data?.ids || []; const ids = data?.ids || [];
// CREATE // CREATE
if (data?.type === WatchEventType.CREATE) { if (data?.type === WatchEventType.CREATE) {
const newDataList = _.cloneDeep(dataList);
_.each(collections, (item: any) => { _.each(collections, (item: any) => {
const updateIndex = _.findIndex( const updateIndex = _.findIndex(
dataList, dataList,
@@ -42,12 +43,13 @@ export function useUpdateChunkedList(options: {
); );
if (updateIndex === -1) { if (updateIndex === -1) {
const updateItem = _.cloneDeep(item); const updateItem = _.cloneDeep(item);
options.setDataList?.((preDataList: any) => { newDataList.push(updateItem);
return _.concat(updateItem, preDataList);
});
} }
console.log('create=========', updateIndex, dataList, collections); console.log('create=========', updateIndex, dataList, collections);
}); });
options.setDataList?.(() => {
return newDataList;
});
} }
// DELETE // DELETE
if (data?.type === WatchEventType.DELETE) { if (data?.type === WatchEventType.DELETE) {
@@ -71,6 +73,9 @@ export function useUpdateChunkedList(options: {
if (updateIndex > -1) { if (updateIndex > -1) {
const updateItem = _.cloneDeep(item); const updateItem = _.cloneDeep(item);
updatedDataList[updateIndex] = updateItem; updatedDataList[updateIndex] = updateItem;
} else if (updateIndex === -1) {
const updateItem = _.cloneDeep(item);
updatedDataList.push(updateItem);
} }
}); });
+2 -4
View File
@@ -1,7 +1,7 @@
// @ts-nocheck // @ts-nocheck
import { userAtom } from '@/atoms/user'; import { userAtom } from '@/atoms/user';
import VersionInfo from '@/components/version-info'; import VersionInfo, { modalConfig } from '@/components/version-info';
import { logout } from '@/pages/login/apis'; import { logout } from '@/pages/login/apis';
import { useAccessMarkedRoutes } from '@@/plugin-access'; import { useAccessMarkedRoutes } from '@@/plugin-access';
import { useModel } from '@@/plugin-model'; import { useModel } from '@@/plugin-model';
@@ -105,9 +105,7 @@ export default (props: any) => {
const showVersion = () => { const showVersion = () => {
Modal.info({ Modal.info({
icon: null, ...modalConfig,
centered: false,
width: 500,
content: <VersionInfo intl={intl} /> content: <VersionInfo intl={intl} />
}); });
}; };
+3 -3
View File
@@ -18,11 +18,11 @@ export default {
'playground.params.temperature.tips': 'playground.params.temperature.tips':
'控制随机性:降低温度会导致更少的随机完成。当温度接近零时,模型将变得确定性和重复性。', '控制随机性:降低温度会导致更少的随机完成。当温度接近零时,模型将变得确定性和重复性。',
'playground.params.maxtokens.tips': 'playground.params.maxtokens.tips':
'生成的最大 token 数。输入标记和生成的标记的总长度受模型上下文长度的限制。', '生成的最大 token 数。输入的 token 和生成的 token 的总长度受模型上下文长度的限制。',
'playground.params.topp.tips': 'playground.params.topp.tips':
'通过核心采样控制多样性:0.5 表示考虑所有基于概率权重选项的一半。', '通过核心采样控制多样性:0.5 表示考虑所有基于概率权重选项的一半。',
'playground.params.seed.tips': 'playground.params.seed.tips':
'如果指定,我们的系统将尽最大努力进行确定性采样,以便使用相同种子和参数的重复请求应返回相同的结果。', '如果指定,我们的系统将尽最大努力进行确定性采样,以便使用相同 seed 和参数的重复请求应返回相同的结果。',
'playground.params.stop.tips': 'playground.params.stop.tips':
'停止序列是一个预定义或用户指定的文本字符串,当这些序列出现时,它会提示 AI 停止生成后续的标记。' '停止序列是一个预定义或用户指定的文本字符串,当这些序列出现时,它会提示 AI 停止生成后续的 token。'
}; };
+5 -4
View File
@@ -204,7 +204,7 @@ const Models: React.FC<ModelsProps> = ({
}); });
}; };
const getModelInstances = useCallback(async (row: any) => { const getModelInstances = async (row: any) => {
const params = { const params = {
id: row.id, id: row.id,
page: 1, page: 1,
@@ -212,7 +212,7 @@ const Models: React.FC<ModelsProps> = ({
}; };
const data = await queryModelInstancesList(params); const data = await queryModelInstancesList(params);
return data.items || []; return data.items || [];
}, []); };
const generateChildrenRequestAPI = (params: any) => { const generateChildrenRequestAPI = (params: any) => {
return `${MODELS_API}/${params.id}/instances`; return `${MODELS_API}/${params.id}/instances`;
@@ -249,14 +249,14 @@ const Models: React.FC<ModelsProps> = ({
[] []
); );
const renderChildren = (list: any) => { const renderChildren = useCallback((list: any) => {
return ( return (
<InstanceItem <InstanceItem
list={list} list={list}
handleChildSelect={handleChildSelect} handleChildSelect={handleChildSelect}
></InstanceItem> ></InstanceItem>
); );
}; }, []);
return ( return (
<> <>
@@ -371,6 +371,7 @@ const Models: React.FC<ModelsProps> = ({
showSorterTooltip={false} showSorterTooltip={false}
sorter={true} sorter={true}
render={(val, row) => { render={(val, row) => {
console.log('val=====', val, row['created_at'], row.name);
return dayjs(val).format('YYYY-MM-DD HH:mm:ss'); return dayjs(val).format('YYYY-MM-DD HH:mm:ss');
}} }}
/> />
+3 -5
View File
@@ -28,14 +28,12 @@ const Models: React.FC = () => {
}); });
// request data // request data
dataSourceRef.current = dataSource;
const { updateChunkedList } = useUpdateChunkedList({ const { updateChunkedList } = useUpdateChunkedList({
setDataList: setDataSource setDataList: setDataSource
}); });
useEffect(() => {
dataSourceRef.current = dataSource;
}, [dataSource]);
const fetchData = useCallback(async () => { const fetchData = useCallback(async () => {
axiosToken?.cancel?.(); axiosToken?.cancel?.();
axiosToken = createAxiosToken(); axiosToken = createAxiosToken();
@@ -44,7 +42,7 @@ const Models: React.FC = () => {
const params = { const params = {
..._.pickBy(queryParams, (val: any) => !!val) ..._.pickBy(queryParams, (val: any) => !!val)
}; };
const res = await queryModelsList(params, { const res: any = await queryModelsList(params, {
cancelToken: axiosToken.token cancelToken: axiosToken.token
}); });
console.log('res=======', res); console.log('res=======', res);
@@ -1,11 +1,12 @@
import TransitionWrapper from '@/components/transition'; import TransitionWrapper from '@/components/transition';
import HotKeys from '@/config/hotkeys'; import HotKeys from '@/config/hotkeys';
import useContainerScroll from '@/hooks/use-container-scorll';
import { fetchChunkedData, readStreamData } from '@/utils/fetch-chunk-data'; import { fetchChunkedData, readStreamData } from '@/utils/fetch-chunk-data';
import { EyeInvisibleOutlined, EyeOutlined } from '@ant-design/icons'; import { EyeInvisibleOutlined, EyeOutlined } from '@ant-design/icons';
import { useIntl } from '@umijs/max'; import { useIntl } from '@umijs/max';
import { Button, Input, Spin } from 'antd'; import { Button, Input, Spin } from 'antd';
import _ from 'lodash'; import _ from 'lodash';
import { useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
import { useHotkeys } from 'react-hotkeys-hook'; import { useHotkeys } from 'react-hotkeys-hook';
import { CHAT_API } from '../apis'; import { CHAT_API } from '../apis';
import { Roles } from '../config'; import { Roles } from '../config';
@@ -48,6 +49,15 @@ const MessageList: React.FC<MessageProps> = (props) => {
const systemRef = useRef<any>(null); const systemRef = useRef<any>(null);
const contentRef = useRef<any>(''); const contentRef = useRef<any>('');
const controllerRef = useRef<any>(null); const controllerRef = useRef<any>(null);
const scroller = useRef<any>(null);
const { updateScrollerPosition, handleContentWheel } = useContainerScroll(
scroller,
{ toBottom: true }
);
useEffect(() => {
updateScrollerPosition();
}, [messageList]);
const handleSystemMessageChange = (e: any) => { const handleSystemMessageChange = (e: any) => {
setSystemMessage(e.target.value); setSystemMessage(e.target.value);
@@ -208,7 +218,11 @@ const MessageList: React.FC<MessageProps> = (props) => {
return ( return (
<div className="ground-left"> <div className="ground-left">
<div className="message-list-wrap"> <div
className="message-list-wrap"
ref={scroller}
onWheel={handleContentWheel}
>
<div style={{ marginBottom: 40 }}> <div style={{ marginBottom: 40 }}>
<TransitionWrapper <TransitionWrapper
header={renderLabel()} header={renderLabel()}
@@ -1,5 +1,6 @@
import { useIntl } from '@umijs/max'; import { useIntl } from '@umijs/max';
import { Space, Tooltip } from 'antd'; import { Space, Tooltip } from 'antd';
import _ from 'lodash';
import '../style/reference-params.less'; import '../style/reference-params.less';
interface ReferenceParamsProps { interface ReferenceParamsProps {
@@ -43,7 +44,7 @@ const ReferenceParams = (props: ReferenceParamsProps) => {
<span> <span>
{intl.formatMessage({ id: 'playground.tokenoutput' })}:{' '} {intl.formatMessage({ id: 'playground.tokenoutput' })}:{' '}
{usage.tokens_per_second} Tokens/s {_.round(usage.tokens_per_second, 2)} Tokens/s
</span> </span>
</div> </div>
); );