Skip to content

Commit

Permalink
remove unnecessary code.
Browse files Browse the repository at this point in the history
  • Loading branch information
yomybaby authored and agatha197 committed Sep 20, 2024
1 parent 32b402d commit 9bc96f2
Showing 1 changed file with 2 additions and 73 deletions.
75 changes: 2 additions & 73 deletions react/src/components/ImportFromHuggingFaceModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { baiSignedRequestWithPromise } from '../helper';
import { useSuspendedBackendaiClient } from '../hooks';
import { useSuspenseTanQuery } from '../hooks/reactQueryAlias';
import BAIModal, { BAIModalProps } from './BAIModal';
import Flex from './Flex';
import { useToggle } from 'ahooks';
Expand All @@ -14,7 +11,7 @@ import {
Typography,
} from 'antd';
import _ from 'lodash';
import React, { useEffect, useRef, useState, useTransition } from 'react';
import React, { useRef } from 'react';
import { useTranslation } from 'react-i18next';

type Service = {
Expand All @@ -35,59 +32,11 @@ const ImportFromHuggingFaceModal: React.FC<ImportFromHuggingFaceModalProps> = ({
const { token } = theme.useToken();
const formRef = useRef<FormInstance<Service>>(null);
const [isImportOnly, { toggle: toggleIsImportOnly }] = useToggle(false);
const [huggingFaceURL, setHuggingFaceURL] = useState<string | undefined>();
const baiClient = useSuspendedBackendaiClient();

const [isPendingCheck, startCheckTransition] = useTransition();
const hugginFaceModelInfo = useSuspenseTanQuery<{
author?: string;
model_name?: string;
markdown?: string;
isError?: boolean;
url?: string;
}>({
queryKey: ['huggingFaceReadme', huggingFaceURL],
queryFn: () => {
if (_.isEmpty(huggingFaceURL)) return Promise.resolve({});
return baiSignedRequestWithPromise({
method: 'GET',
url: `/services/_/huggingface/models?huggingface_url=${huggingFaceURL}`,
client: baiClient,
})
.then((result: any) => {
return {
...result,
url: huggingFaceURL,
};
})
.catch(() => {
// TODO: handle error more gracefully
return {
isError: true,
url: huggingFaceURL,
};
});
},
});
const isHuggingfaceURLExisted = !_.isEmpty(
hugginFaceModelInfo.data.model_name,
);

// validate when huggingFaceModelInfo is updated
useEffect(() => {
if (hugginFaceModelInfo.data.url) {
formRef.current?.validateFields().catch(() => {});
}
}, [hugginFaceModelInfo.data.url]);

const handleOnClick = () => {
formRef.current
?.validateFields()
.then((values) => {
startCheckTransition(() => {
setHuggingFaceURL(values?.url);
});

// TODO: Implement import from Hugging Face
// onRequestClose();
})
Expand All @@ -99,12 +48,7 @@ const ImportFromHuggingFaceModal: React.FC<ImportFromHuggingFaceModalProps> = ({
title={t('data.modelStore.ImportFromHuggingFace')}
centered
footer={
<Button
type="primary"
htmlType="submit"
onClick={handleOnClick}
loading={isPendingCheck}
>
<Button type="primary" htmlType="submit" onClick={handleOnClick}>
{isImportOnly
? t('data.modelStore.Import')
: t('data.modelStore.ImportAndStartService')}
Expand All @@ -128,21 +72,6 @@ const ImportFromHuggingFaceModal: React.FC<ImportFromHuggingFaceModalProps> = ({
pattern: /^https:\/\/huggingface.co\/.*/,
message: t('data.modelStore.StartWithHuggingFaceUrl'),
},
{
validator: async (_, value) => {
if (
!isHuggingfaceURLExisted &&
hugginFaceModelInfo.data?.isError &&
hugginFaceModelInfo.data.url === value
) {
return Promise.reject(
t('data.modelStore.InvalidHuggingFaceUrl'),
);
} else {
return Promise.resolve();
}
},
},
]}
>
<Input />
Expand Down

0 comments on commit 9bc96f2

Please sign in to comment.