Skip to content

Commit

Permalink
feat: import and start service from hugging face
Browse files Browse the repository at this point in the history
  • Loading branch information
agatha197 committed Sep 22, 2024
1 parent f07e70d commit aeb9e63
Show file tree
Hide file tree
Showing 22 changed files with 181 additions and 38 deletions.
94 changes: 76 additions & 18 deletions react/src/components/ImportFromHuggingFaceModal.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { baiSignedRequestWithPromise } from '../helper';
import { useSuspendedBackendaiClient } from '../hooks';
import { useSuspenseTanQuery } from '../hooks/reactQueryAlias';
import { useTanMutation } from '../hooks/reactQueryAlias';
import { useBAINotificationState } from '../hooks/useBAINotification';
import BAIModal, { BAIModalProps } from './BAIModal';
import Flex from './Flex';
import { FilterOutlined } from '@ant-design/icons';
import { useToggle } from 'ahooks';
import {
App,
Button,
Card,
Empty,
Expand Down Expand Up @@ -69,11 +72,13 @@ const ImportFromHuggingFaceModal: React.FC<ImportFromHuggingFaceModalProps> = ({
}) => {
const { t } = useTranslation();
const { token } = theme.useToken();
const { message } = App.useApp();
const baiClient = useSuspendedBackendaiClient();
const formRef = useRef<FormInstance<Service>>(null);
const [isImportOnly, { toggle: toggleIsImportOnly }] = useToggle(false);
const [huggingFaceURL, setHuggingFaceURL] = useState<string | undefined>();
const [typedURL, setTypedURL] = useState('');
const baiClient = useSuspendedBackendaiClient();
const [, { upsertNotification }] = useBAINotificationState();

const [isPendingCheck, startCheckTransition] = useTransition();
const huggingFaceModelInfo = useSuspenseTanQuery<{
Expand Down Expand Up @@ -121,6 +126,27 @@ const ImportFromHuggingFaceModal: React.FC<ImportFromHuggingFaceModalProps> = ({
}
}, [baiModalProps.open]);

const importAndStartService = useTanMutation({
mutationFn: (values: {
huggingFaceUrl: string;
importOnly?: boolean;
serviceName?: string;
folderName?: string;
}) => {
return baiSignedRequestWithPromise({
method: 'POST',
url: '/services/_/huggingface/models',
body: {
huggingface_url: values.huggingFaceUrl,
import_only: values?.importOnly,
service_name: values?.serviceName,
folder_name: values?.folderName,
},
client: baiClient,
});
},
});

// validate when huggingFaceModelInfo is updated
useEffect(() => {
if (huggingFaceModelInfo.data.url) {
Expand All @@ -132,8 +158,43 @@ const ImportFromHuggingFaceModal: React.FC<ImportFromHuggingFaceModalProps> = ({
formRef.current
?.validateFields()
.then((values) => {
// TODO: Implement import from Hugging Face
onRequestClose();
importAndStartService.mutate(
{
huggingFaceUrl: values.url,
importOnly: isImportOnly,
serviceName: values.service_name || undefined,
folderName: values.folder_name || undefined,
},
{
onSuccess(data: any) {
if (data?.folder?.id && data?.folder?.name) {
upsertNotification({
key: 'ImportFromHuggingFaceModal' + data.folder.id,
description: `${t('data.modelStore.NewModelStoreFolderHasBeenCreated')}: ${data.folder.name}`,
open: true,
duration: 0,
toText: t('data.modelStore.OpenFolder'),
to: `/data?tab=model-store&folder=${data.folder.id}`,
});
}
if (data?.service?.endpoint_id && data?.service?.name) {
upsertNotification({
key: 'ImportFromHuggingFaceModal' + data.service.endpoint_id,
description: `${t('data.modelStore.NewServiceHasBeenCreated')}: ${data.service.name}`,
open: true,
duration: 0,
toText: t('data.modelStore.ViewServiceInfo'),
to: `/serving/${data.service.endpoint_id}`,
});
}
onRequestClose();
},
onError(e) {
message.error(e.message || t('dialog.ErrorOccurred'));
onRequestClose();
},
},
);
})
.catch(() => {});
};
Expand All @@ -153,22 +214,19 @@ const ImportFromHuggingFaceModal: React.FC<ImportFromHuggingFaceModalProps> = ({
<BAIModal
title={t('data.modelStore.ImportFromHuggingFace')}
centered
footer={
<Button
type="primary"
htmlType="submit"
onClick={handleOnClick}
disabled={
!shouldSkipURLCheck ||
(!_.isEmpty(huggingFaceModelInfo.data?.pipeline_tag) &&
huggingFaceModelInfo.data?.pipeline_tag !== 'text-generation')
}
>
{isImportOnly
? t('data.modelStore.Import')
: t('data.modelStore.ImportAndStartService')}
</Button>
confirmLoading={importAndStartService.isPending}
okText={
isImportOnly
? t('data.modelStore.Import')
: t('data.modelStore.ImportAndStartService')
}
onOk={handleOnClick}
okButtonProps={{
disabled:
!shouldSkipURLCheck ||
(!_.isEmpty(huggingFaceModelInfo.data?.pipeline_tag) &&
huggingFaceModelInfo.data?.pipeline_tag !== 'text-generation'),
}}
onCancel={onRequestClose}
destroyOnClose
{...baiModalProps}
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,11 @@
"InvalidHuggingFaceUrl": "Ungültige Hugging Face URL.",
"ServiceName": "Dienstname",
"ModelStoreFolderName": "Name des Modellspeicherordners",
"NotSupportedModel": "Das Modell wird nicht unterstützt. \nBitte nutzen Sie das LLM-Modell."
"NotSupportedModel": "Das Modell wird nicht unterstützt. \nBitte nutzen Sie das LLM-Modell.",
"NewModelStoreFolderHasBeenCreated": "Ein neuer Modellspeicherordner wurde erstellt",
"NewServiceHasBeenCreated": "Ein neuer Dienst wurde erstellt",
"OpenFolder": "Ordner öffnen",
"ViewServiceInfo": "Serviceinformationen anzeigen"
}
},
"dialog": {
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/el.json
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,12 @@
"ModelName": "Όνομα μοντέλου",
"Author": "Συγγραφέας",
"InvalidHuggingFaceUrl": "Μη έγκυρη διεύθυνση URL Hugging Face.",
"ServiceName": "Όνομα υπηρεσίας",
"ModelStoreFolderName": "Όνομα φακέλου καταστήματος μοντέλου",
"ServiceName": "Όνομα υπηρεσίας",
"NewModelStoreFolderHasBeenCreated": "Δημιουργήθηκε ένας νέος φάκελος καταστήματος μοντέλων",
"NewServiceHasBeenCreated": "Μια νέα υπηρεσία δημιουργήθηκε",
"OpenFolder": "Άνοιγμα φακέλου",
"ViewServiceInfo": "Προβολή πληροφοριών υπηρεσίας",
"NotSupportedModel": "Το μοντέλο δεν υποστηρίζεται. \nΧρησιμοποιήστε το μοντέλο LLM."
}
},
Expand Down
5 changes: 5 additions & 0 deletions resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,11 @@
"InvalidHuggingFaceUrl": "Invalid Hugging Face URL.",
"ModelStoreFolderName": "Model store folder name",
"ServiceName": "Service name",
"HuggingFaceURL": "Higging Face",
"NewModelStoreFolderHasBeenCreated": "A new model store folder has been created",
"NewServiceHasBeenCreated": "A new service has been created",
"OpenFolder": "Open folder",
"ViewServiceInfo": "View service info",
"NotSupportedModel": "The model is not supported. Please use the LLM model."
}
},
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,12 @@
"ModelName": "Nombre del modelo",
"Author": "Autor",
"InvalidHuggingFaceUrl": "URL Hugging Face no válida.",
"ServiceName": "Nombre del servicio",
"ModelStoreFolderName": "Nombre de la carpeta de la tienda de modelos",
"ServiceName": "Nombre del servicio",
"NewModelStoreFolderHasBeenCreated": "Se ha creado una nueva carpeta de tienda de modelos.",
"NewServiceHasBeenCreated": "Se ha creado un nuevo servicio.",
"OpenFolder": "Abrir carpeta",
"ViewServiceInfo": "Ver información del servicio",
"NotSupportedModel": "El modelo no es compatible. \nUtilice el modelo LLM."
}
},
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,12 @@
"ModelName": "Mallin nimi",
"Author": "Kirjoittaja",
"InvalidHuggingFaceUrl": "Virheellinen Hugging Face URL-osoite.",
"ServiceName": "Palvelun nimi",
"ModelStoreFolderName": "Mallin tallennuskansion nimi",
"ServiceName": "Palvelun nimi",
"NewModelStoreFolderHasBeenCreated": "Uusi mallikauppakansio on luotu",
"NewServiceHasBeenCreated": "Uusi palvelu on luotu",
"OpenFolder": "Avaa kansio",
"ViewServiceInfo": "Katso palvelutiedot",
"NotSupportedModel": "Mallia ei tueta. \nKäytä LLM-mallia."
}
},
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,12 @@
"ModelName": "Nom du modèle",
"Author": "Auteur",
"InvalidHuggingFaceUrl": "URL Hugging Face non valide.",
"ServiceName": "Nom du service",
"ModelStoreFolderName": "Nom du dossier du magasin de modèles",
"ServiceName": "Nom du service",
"NewModelStoreFolderHasBeenCreated": "Un nouveau dossier de magasin de modèles a été créé",
"NewServiceHasBeenCreated": "Un nouveau service a été créé",
"OpenFolder": "Ouvrir le dossier",
"ViewServiceInfo": "Afficher les informations sur les services",
"NotSupportedModel": "Le modèle n'est pas pris en charge. \nVeuillez utiliser le modèle LLM."
}
},
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,12 @@
"ModelName": "Nama model",
"Author": "Penulis",
"InvalidHuggingFaceUrl": "URL Hugging Face tidak valid.",
"ServiceName": "Nama layanan",
"ModelStoreFolderName": "Nama folder penyimpanan model",
"ServiceName": "Nama layanan",
"NewModelStoreFolderHasBeenCreated": "Folder penyimpanan model baru telah dibuat",
"NewServiceHasBeenCreated": "Layanan baru telah dibuat",
"OpenFolder": "Buka map",
"ViewServiceInfo": "Lihat info layanan",
"NotSupportedModel": "Model ini tidak didukung. \nSilakan gunakan model LLM."
}
},
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,12 @@
"ModelName": "Nome del modello",
"Author": "Autore",
"InvalidHuggingFaceUrl": "URL Hugging Face non valido.",
"ServiceName": "Nome del servizio",
"ModelStoreFolderName": "Nome della cartella dell'archivio modelli",
"ServiceName": "Nome del servizio",
"NewModelStoreFolderHasBeenCreated": "È stata creata una nuova cartella dell'archivio modelli",
"NewServiceHasBeenCreated": "È stato creato un nuovo servizio",
"OpenFolder": "Apri cartella",
"ViewServiceInfo": "Visualizza le informazioni sul servizio",
"NotSupportedModel": "Il modello non è supportato. \nSi prega di utilizzare il modello LLM."
}
},
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,12 @@
"ModelName": "モデル名",
"Author": "著者",
"InvalidHuggingFaceUrl": "無効なHugging Face URLです。",
"ServiceName": "サービス名",
"ModelStoreFolderName": "モデルストアフォルダー名",
"ServiceName": "サービス名",
"NewModelStoreFolderHasBeenCreated": "新しいモデル ストア フォルダーが作成されました",
"NewServiceHasBeenCreated": "新しいサービスが作成されました",
"OpenFolder": "フォルダーを開く",
"ViewServiceInfo": "サービス情報を見る",
"NotSupportedModel": "このモデルはサポートされていません。 \nLLMモデルを使用してください。"
}
},
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -905,8 +905,12 @@
"Author": "작성자",
"InvalidHuggingFaceUrl": "유효한 Hugging Face URL을 입력해주세요",
"PleaseClickCheckButton": "확인 버튼을 클릭해주세요",
"ServiceName": "서비스 이름",
"ModelStoreFolderName": "모델 저장소 폴더 이름",
"ServiceName": "서비스 이름",
"NewModelStoreFolderHasBeenCreated": "새 모델 저장소 폴더가 생성되었습니다.",
"NewServiceHasBeenCreated": "새로운 서비스가 생성되었습니다",
"OpenFolder": "폴더 열기",
"ViewServiceInfo": "서비스 정보 보기",
"NotSupportedModel": "해당 모델은 지원되지 않습니다. \nLLM 모델을 사용하세요."
}
},
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/mn.json
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,12 @@
"CheckHuggingFaceUrl": "Шалгах",
"ModelName": "Загварын нэр",
"InvalidHuggingFaceUrl": "Хүчингүй Hugging Face URL.",
"ServiceName": "Үйлчилгээний нэр",
"ModelStoreFolderName": "Загварын дэлгүүрийн хавтасны нэр",
"ServiceName": "Үйлчилгээний нэр",
"NewModelStoreFolderHasBeenCreated": "Шинэ загварын дэлгүүрийн хавтас үүсгэгдсэн",
"NewServiceHasBeenCreated": "Шинэ үйлчилгээ бий болсон",
"OpenFolder": "Фолдер нээх",
"ViewServiceInfo": "Үйлчилгээний мэдээллийг харах",
"NotSupportedModel": "Энэ загварыг дэмждэггүй. \nLLM загварыг ашиглана уу."
}
},
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/ms.json
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,12 @@
"ModelName": "Nama model",
"Author": "Pengarang",
"InvalidHuggingFaceUrl": "URL Hugging Face tidak sah.",
"ServiceName": "Nama perkhidmatan",
"ModelStoreFolderName": "Nama folder kedai model",
"ServiceName": "Nama perkhidmatan",
"NewModelStoreFolderHasBeenCreated": "Folder kedai model baharu telah dibuat",
"NewServiceHasBeenCreated": "Perkhidmatan baharu telah dibuat",
"OpenFolder": "Buka folder",
"ViewServiceInfo": "Lihat maklumat perkhidmatan",
"NotSupportedModel": "Model tidak disokong. \nSila gunakan model LLM."
}
},
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,12 @@
"ModelName": "Nazwa modelu",
"Author": "Autor",
"InvalidHuggingFaceUrl": "Nieprawidłowy adres URL Hugging Face.",
"ServiceName": "Nazwa usługi",
"ModelStoreFolderName": "Nazwa folderu sklepu modelu",
"ServiceName": "Nazwa usługi",
"NewModelStoreFolderHasBeenCreated": "Utworzono nowy folder sklepu z modelami",
"NewServiceHasBeenCreated": "Powstał nowy serwis",
"OpenFolder": "Otwórz folder",
"ViewServiceInfo": "Wyświetl informacje o usłudze",
"NotSupportedModel": "Model nie jest obsługiwany. \nProszę skorzystać z modelu LLM."
}
},
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,12 @@
"ModelName": "Nome do modelo",
"Author": "Autor",
"InvalidHuggingFaceUrl": "URL Hugging Face inválido.",
"ServiceName": "Nome do serviço",
"ModelStoreFolderName": "Nome da pasta de armazenamento de modelos",
"ServiceName": "Nome do serviço",
"NewModelStoreFolderHasBeenCreated": "Uma nova pasta de armazenamento de modelos foi criada",
"NewServiceHasBeenCreated": "Um novo serviço foi criado",
"OpenFolder": "Abrir pasta",
"ViewServiceInfo": "Ver informações de serviço",
"NotSupportedModel": "O modelo não é suportado. \nPor favor, use o modelo LLM."
}
},
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,12 @@
"ModelName": "Nome do modelo",
"Author": "Autor",
"InvalidHuggingFaceUrl": "URL Hugging Face inválido.",
"ServiceName": "Nome do serviço",
"ModelStoreFolderName": "Nome da pasta de armazenamento de modelos",
"ServiceName": "Nome do serviço",
"NewModelStoreFolderHasBeenCreated": "Uma nova pasta de armazenamento de modelos foi criada",
"NewServiceHasBeenCreated": "Um novo serviço foi criado",
"OpenFolder": "Abrir pasta",
"ViewServiceInfo": "Ver informações de serviço",
"NotSupportedModel": "O modelo não é suportado. \nPor favor, use o modelo LLM."
}
},
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,12 @@
"ModelName": "Название модели",
"Author": "Автор",
"InvalidHuggingFaceUrl": "Неверный URL-адрес Hugging Face.",
"ServiceName": "Название службы",
"ModelStoreFolderName": "Имя папки хранилища моделей",
"ServiceName": "Название службы",
"NewModelStoreFolderHasBeenCreated": "Создана новая папка хранилища моделей.",
"NewServiceHasBeenCreated": "Создан новый сервис",
"OpenFolder": "Открыть папку",
"ViewServiceInfo": "Посмотреть информацию об услуге",
"NotSupportedModel": "Модель не поддерживается. \nПожалуйста, используйте модель LLM."
}
},
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/th.json
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,12 @@
"ModelName": "ชื่อรุ่น",
"Author": "ผู้เขียน",
"InvalidHuggingFaceUrl": "URL Hugging Face ไม่ถูกต้อง",
"ServiceName": "ชื่อบริการ",
"ModelStoreFolderName": "ชื่อโฟลเดอร์ร้านค้าโมเดล",
"ServiceName": "ชื่อบริการ",
"NewModelStoreFolderHasBeenCreated": "สร้างโฟลเดอร์ร้านค้าโมเดลใหม่แล้ว",
"NewServiceHasBeenCreated": "มีการสร้างบริการใหม่แล้ว",
"OpenFolder": "เปิดโฟลเดอร์",
"ViewServiceInfo": "ดูข้อมูลบริการ",
"NotSupportedModel": "ไม่รองรับโมเดลนี้ \nกรุณาใช้แบบจำลอง LLM"
}
},
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,12 @@
"ModelName": "Model adı",
"Author": "Yazar",
"InvalidHuggingFaceUrl": "Geçersiz Hugging Face URL'si.",
"ServiceName": "Hizmet adı",
"ModelStoreFolderName": "Model deposu klasör adı",
"ServiceName": "Hizmet adı",
"NewModelStoreFolderHasBeenCreated": "Yeni bir model mağazası klasörü oluşturuldu",
"NewServiceHasBeenCreated": "Yeni bir hizmet oluşturuldu",
"OpenFolder": "Klasörü aç",
"ViewServiceInfo": "Hizmet bilgilerini görüntüle",
"NotSupportedModel": "Model desteklenmiyor. \nLütfen LLM modelini kullanın."
}
},
Expand Down
Loading

0 comments on commit aeb9e63

Please sign in to comment.