fix: no request, search model

This commit is contained in:
jialin
2024-10-15 17:52:02 +08:00
parent 8fbdb884c7
commit a47f7cc0ce
10 changed files with 150 additions and 83 deletions
+4
View File
@@ -136,6 +136,10 @@
position: relative; position: relative;
} }
.font-size-0 {
font-size: 0;
}
.font-size-12 { .font-size-12 {
font-size: var(--font-size-base); font-size: var(--font-size-base);
} }
+2 -1
View File
@@ -4,13 +4,14 @@
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: flex-start; justify-content: flex-start;
height: 68px; min-height: 68px;
word-break: break-word; word-break: break-word;
min-width: 20px; min-width: 20px;
overflow: hidden; overflow: hidden;
.cell-content { .cell-content {
max-width: 100%; max-width: 100%;
line-height: 18px;
} }
&-left { &-left {
+1
View File
@@ -65,6 +65,7 @@ html {
--color-progress-green: rgba(84, 204, 152, 100%); --color-progress-green: rgba(84, 204, 152, 100%);
--color-border-1: rgba(217, 217, 217, 100%); --color-border-1: rgba(217, 217, 217, 100%);
--ant-rate-star-color: #fadb14; --ant-rate-star-color: #fadb14;
--color-fill-mask: rgba(255, 255, 255, 60%);
// ======== input ============ // ======== input ============
--ant-input-active-shadow: 0 0 0 2px rgba(5, 255, 105, 6%); --ant-input-active-shadow: 0 0 0 2px rgba(5, 255, 105, 6%);
--ant-input-active-border-color: #007bff; --ant-input-active-border-color: #007bff;
@@ -3,6 +3,7 @@ import { PageActionType } from '@/config/types';
import { CloseOutlined } from '@ant-design/icons'; import { CloseOutlined } from '@ant-design/icons';
import { useIntl } from '@umijs/max'; import { useIntl } from '@umijs/max';
import { Button, Drawer } from 'antd'; import { Button, Drawer } from 'antd';
import { debounce } from 'lodash';
import { memo, useCallback, useEffect, useRef, useState } from 'react'; import { memo, useCallback, useEffect, useRef, useState } from 'react';
import { modelSourceMap } from '../config'; import { modelSourceMap } from '../config';
import { FormData, ListItem } from '../config/types'; import { FormData, ListItem } from '../config/types';
@@ -53,6 +54,7 @@ const AddModal: React.FC<AddModalProps> = (props) => {
}, []); }, []);
const handleOnSelectModel = (item: any) => { const handleOnSelectModel = (item: any) => {
handleSelectModelFile({ fakeName: '' });
setSelectedModel(item); setSelectedModel(item);
}; };
@@ -60,12 +62,14 @@ const AddModal: React.FC<AddModalProps> = (props) => {
form.current?.submit?.(); form.current?.submit?.();
}; };
const debounceFetchModelFiles = debounce(() => {
modelFileRef.current?.fetchModelFiles?.();
}, 300);
const handleSetIsGGUF = (flag: boolean) => { const handleSetIsGGUF = (flag: boolean) => {
setIsGGUF(flag); setIsGGUF(flag);
if (flag) { if (flag) {
setTimeout(() => { debounceFetchModelFiles();
modelFileRef.current?.fetchModelFiles?.();
}, 50);
} }
}; };
+72 -66
View File
@@ -261,7 +261,7 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
}, []); }, []);
return ( return (
<div> <div className="files-wrap">
<TitleWrapper> <TitleWrapper>
<span className="title"> <span className="title">
{intl.formatMessage({ id: 'models.available.files' })} ( {intl.formatMessage({ id: 'models.available.files' })} (
@@ -282,83 +282,89 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
style={{ width: '120px' }} style={{ width: '120px' }}
></Select> ></Select>
</TitleWrapper> </TitleWrapper>
{dataSource.loading && (
<div className="spin-wrapper">
<Spin
spinning={dataSource.loading}
style={{ height: '100%', width: '100%' }}
></Spin>
</div>
)}
<SimpleBar <SimpleBar
style={{ style={{
height: collapsed ? 'max-content' : 'calc(100vh - 300px)' height: collapsed ? 'max-content' : 'calc(100vh - 300px)'
}} }}
> >
<div style={{ padding: '16px 24px' }}> <div style={{ padding: '16px 24px' }}>
<Spin spinning={dataSource.loading} style={{ minHeight: 100 }}> {dataSource.fileList.length ? (
{dataSource.fileList.length ? ( <Row gutter={[16, 24]}>
<Row gutter={[16, 24]}> {_.map(dataSource.fileList, (item: any) => {
{_.map(dataSource.fileList, (item: any) => { return (
return ( <Col span={24} key={item.path}>
<Col span={24} key={item.path}> <div
<div className={classNames('hf-model-file', {
className={classNames('hf-model-file', { active: item.path === current
active: item.path === current })}
})} tabIndex={0}
tabIndex={0} onClick={() => handleSelectModelFile(item)}
onClick={() => handleSelectModelFile(item)} onKeyDown={(e) => handleOnEnter(e, item)}
onKeyDown={(e) => handleOnEnter(e, item)} >
> <div className="title">{item.path}</div>
<div className="title">{item.path}</div> <div className="tags">
<div className="tags"> <Tag
<Tag className="tag-item"
className="tag-item" color="green"
color="green" style={{
style={{ marginRight: 0
marginRight: 0 }}
>
<span style={{ opacity: 0.65 }}>
{convertFileSize(item.size)}
</span>
</Tag>
{getModelQuantizationType(item)}
{item.parts && item.parts.length > 1 && (
<Tooltip
overlayInnerStyle={{
width: 180,
padding: 0
}} }}
title={
<FileParts fileList={item.parts}></FileParts>
}
> >
<span style={{ opacity: 0.65 }}> <Tag
{convertFileSize(item.size)} className="tag-item"
</span> color="purple"
</Tag> style={{
{getModelQuantizationType(item)} marginRight: 0
{item.parts && item.parts.length > 1 && (
<Tooltip
overlayInnerStyle={{
width: 180,
padding: 0
}} }}
title={
<FileParts fileList={item.parts}></FileParts>
}
> >
<Tag <span style={{ opacity: 1 }}>
className="tag-item" <InfoCircleOutlined className="m-r-5" />
color="purple" {item.parts.length} parts
style={{ </span>
marginRight: 0 </Tag>
}} </Tooltip>
> )}
<span style={{ opacity: 1 }}>
<InfoCircleOutlined className="m-r-5" />
{item.parts.length} parts
</span>
</Tag>
</Tooltip>
)}
</div>
</div> </div>
</Col> </div>
); </Col>
);
})}
</Row>
) : (
!dataSource.loading &&
!dataSource.fileList.length && (
<Empty
imageStyle={{ height: 'auto', marginTop: '20px' }}
image={Empty.PRESENTED_IMAGE_SIMPLE}
description={intl.formatMessage({
id: 'models.search.nofiles'
})} })}
</Row> />
) : ( )
!dataSource.loading && )}
!dataSource.fileList.length && (
<Empty
imageStyle={{ height: 'auto', marginTop: '20px' }}
image={Empty.PRESENTED_IMAGE_SIMPLE}
description={intl.formatMessage({
id: 'models.search.nofiles'
})}
/>
)
)}
</Spin>
</div> </div>
</SimpleBar> </SimpleBar>
</div> </div>
@@ -136,7 +136,6 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
} }
axiosTokenRef.current?.abort?.(); axiosTokenRef.current?.abort?.();
axiosTokenRef.current = new AbortController(); axiosTokenRef.current = new AbortController();
if (dataSource.loading) return;
const sort = sortType ?? dataSource.sortType; const sort = sortType ?? dataSource.sortType;
try { try {
setDataSource((pre) => { setDataSource((pre) => {
@@ -208,7 +207,6 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
}; };
const handleFilterGGUFChange = (e: any) => { const handleFilterGGUFChange = (e: any) => {
console.log('filterggufChange:', e.target.checked);
filterGGUFRef.current = e.target.checked; filterGGUFRef.current = e.target.checked;
handleOnSearchRepo(); handleOnSearchRepo();
}; };
+10 -6
View File
@@ -522,20 +522,24 @@ const Models: React.FC<ModelsProps> = ({
return ( return (
<span <span
className="flex-center flex-wrap" className="flex-center flex-wrap"
style={{ maxWidth: '100%' }} style={{
maxWidth: '100%',
lineHeight:
record.reranker || record.embedding_only
? '24px'
: 'inherit'
}}
> >
<AutoTooltip ghost> <AutoTooltip ghost>
<span className="m-r-5">{text}</span> <span className="m-r-5">{text}</span>
</AutoTooltip> </AutoTooltip>
{record.reranker && ( {record.reranker && (
<span> <span className="font-size-0">
<Tag style={{ margin: 0 }} color="geekblue"> <Tag style={{ margin: 0 }}>Reranker</Tag>
Reranker
</Tag>
</span> </span>
)} )}
{record.embedding_only && !record.reranker && ( {record.embedding_only && !record.reranker && (
<span> <span className="font-size-0">
<Tag style={{ margin: 0 }} color="geekblue"> <Tag style={{ margin: 0 }} color="geekblue">
Embedding Only Embedding Only
</Tag> </Tag>
@@ -45,6 +45,23 @@
} }
} }
.files-wrap {
position: relative;
.spin-wrapper {
position: absolute;
left: 0;
right: 0;
height: 100%;
z-index: 100;
bottom: 0;
top: 0;
padding-top: 150px;
text-align: center;
background-color: var(--color-fill-mask);
}
}
.wrapper { .wrapper {
padding: 16px @padding; padding: 16px @padding;
} }
+10 -3
View File
@@ -23,12 +23,19 @@ const ThumbImg: React.FC<{
<div className="thumb-list-wrap"> <div className="thumb-list-wrap">
{_.map(dataList, (item: any) => { {_.map(dataList, (item: any) => {
return ( return (
<span key={item.uid} className="thumb-img"> <span
key={item.uid}
className="thumb-img"
style={{
width: item.width,
height: item.height
}}
>
<span className="img"> <span className="img">
<Image <Image
src={item.dataUrl} src={item.dataUrl}
width={56} width={item.width}
height={56} height={item.height}
preview={{ preview={{
mask: <EyeOutlined /> mask: <EyeOutlined />
}} }}
+27 -2
View File
@@ -3,11 +3,12 @@ import { useIntl } from '@umijs/max';
import { Button, Tooltip, Upload } from 'antd'; import { Button, Tooltip, Upload } from 'antd';
import type { UploadFile } from 'antd/es/upload'; import type { UploadFile } from 'antd/es/upload';
import { RcFile } from 'antd/es/upload'; import { RcFile } from 'antd/es/upload';
import { debounce } from 'lodash'; import { debounce, round } from 'lodash';
import React, { useCallback, useRef } from 'react'; import React, { useCallback, useRef } from 'react';
interface UploadImgProps { interface UploadImgProps {
size?: 'small' | 'middle' | 'large'; size?: 'small' | 'middle' | 'large';
height?: number;
handleUpdateImgList: ( handleUpdateImgList: (
imgList: { dataUrl: string; uid: number | string }[] imgList: { dataUrl: string; uid: number | string }[]
) => void; ) => void;
@@ -15,6 +16,7 @@ interface UploadImgProps {
const UploadImg: React.FC<UploadImgProps> = ({ const UploadImg: React.FC<UploadImgProps> = ({
handleUpdateImgList, handleUpdateImgList,
height = 100,
size = 'small' size = 'small'
}) => { }) => {
const intl = useIntl(); const intl = useIntl();
@@ -36,6 +38,22 @@ const UploadImg: React.FC<UploadImgProps> = ({
[handleUpdateImgList, intl] [handleUpdateImgList, intl]
); );
const getImgDimensions = useCallback(
(file: any): Promise<{ ratio: number }> => {
return new Promise((resolve) => {
const img = new Image();
img.onload = () => {
resolve({ ratio: round(img.width / img.height, 2) });
};
img.onerror = () => {
resolve({ ratio: 1 });
};
img.src = URL.createObjectURL(file);
});
},
[]
);
const handleChange = useCallback( const handleChange = useCallback(
async (info: any) => { async (info: any) => {
const { fileList } = info; const { fileList } = info;
@@ -44,7 +62,12 @@ const UploadImg: React.FC<UploadImgProps> = ({
fileList.map(async (item: UploadFile) => { fileList.map(async (item: UploadFile) => {
if (item.originFileObj && !item.url) { if (item.originFileObj && !item.url) {
const base64 = await getBase64(item.originFileObj as RcFile); const base64 = await getBase64(item.originFileObj as RcFile);
const { ratio } = await getImgDimensions(
item.originFileObj as RcFile
);
item.url = base64; item.url = base64;
item.ratio = ratio;
} }
return item; return item;
}) })
@@ -56,7 +79,9 @@ const UploadImg: React.FC<UploadImgProps> = ({
.map((item: UploadFile) => { .map((item: UploadFile) => {
return { return {
dataUrl: item.url as string, dataUrl: item.url as string,
uid: item.uid uid: item.uid,
height: height,
width: height * item.ratio
}; };
}); });