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 21, 2024
1 parent 7bab3a6 commit b72d152
Show file tree
Hide file tree
Showing 22 changed files with 167 additions and 22 deletions.
64 changes: 62 additions & 2 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,7 +158,41 @@ const ImportFromHuggingFaceModal: React.FC<ImportFromHuggingFaceModalProps> = ({
formRef.current
?.validateFields()
.then((values) => {
// TODO: Implement import from Hugging Face
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,
message: `${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,
message: `${t('data.modelStore.NewModelStoreServiceHasBeenCreated')}: ${data.service.name}`,
open: true,
duration: 0,
toText: t('data.modelStore.ViewServiceInfo'),
to: `/serving/${data.service.endpoint_id}`,
});
}
},
onError(e) {
message.error(e.message || t('dialog.ErrorOccurred'));
},
},
);
onRequestClose();
})
.catch(() => {});
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": "Neuer Modellspeicherordner wurde erstellt",
"NewModelStoreServiceHasBeenCreated": "Es wurde ein neuer Modellshop-Service 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": "Δημιουργήθηκε νέος φάκελος καταστήματος μοντέλου",
"NewModelStoreServiceHasBeenCreated": "Δημιουργήθηκε νέο μοντέλο υπηρεσίας καταστήματος",
"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": "New model store folder has been created",
"NewModelStoreServiceHasBeenCreated": "New model store 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.",
"NewModelStoreServiceHasBeenCreated": "Se ha creado un nuevo modelo de servicio de tienda.",
"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",
"NewModelStoreServiceHasBeenCreated": "Uusi mallimyymälä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éé",
"NewModelStoreServiceHasBeenCreated": "Un nouveau service de magasin de modèles 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",
"NewModelStoreServiceHasBeenCreated": "Layanan toko model 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",
"NewModelStoreServiceHasBeenCreated": "È stato creato un nuovo servizio di negozio di modelli",
"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": "新しいモデルストアフォルダーが作成されました",
"NewModelStoreServiceHasBeenCreated": "新しいモデルの店舗サービスが誕生しました",
"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": "새 모델 저장소 폴더가 생성되었습니다.",
"NewModelStoreServiceHasBeenCreated": "새로운 모델스토어 서비스가 생성되었습니다",
"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": "Шинэ загварын дэлгүүрийн хавтас үүсгэсэн",
"NewModelStoreServiceHasBeenCreated": "Шинэ загварын дэлгүүрийн үйлчилгээ бий боллоо",
"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",
"NewModelStoreServiceHasBeenCreated": "Perkhidmatan kedai model 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",
"NewModelStoreServiceHasBeenCreated": "Powstał nowy serwis sklepu modelowego",
"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": "Nova pasta de loja de modelos foi criada",
"NewModelStoreServiceHasBeenCreated": "Novo modelo de serviço de loja 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": "Nova pasta de loja de modelos foi criada",
"NewModelStoreServiceHasBeenCreated": "Novo modelo de serviço de loja 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": "Создана новая папка хранилища моделей.",
"NewModelStoreServiceHasBeenCreated": "Создан новый сервис магазина моделей",
"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": "สร้างโฟลเดอร์ร้านค้าโมเดลใหม่แล้ว",
"NewModelStoreServiceHasBeenCreated": "สร้างบริการร้านค้ารูปแบบใหม่แล้ว",
"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 model mağazası klasörü oluşturuldu",
"NewModelStoreServiceHasBeenCreated": "Yeni model mağaza hizmeti oluşturuldu",
"OpenFolder": "Klasörü aç",
"ViewServiceInfo": "Hizmet bilgilerini görüntüle",
"NotSupportedModel": "Model desteklenmiyor. \nLütfen LLM modelini kullanın."
}
},
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,12 @@
"ModelName": "Tên mẫu",
"Author": "Tác giả",
"InvalidHuggingFaceUrl": "URL Hugging Face không hợp lệ.",
"ServiceName": "Tên dịch vụ",
"ModelStoreFolderName": "Tên thư mục lưu trữ mô hình",
"ServiceName": "Tên dịch vụ",
"NewModelStoreFolderHasBeenCreated": "Thư mục lưu trữ mô hình mới đã được tạo",
"NewModelStoreServiceHasBeenCreated": "Dịch vụ cửa hàng mẫu mới đã được tạo",
"OpenFolder": "Mở thư mục",
"ViewServiceInfo": "Xem thông tin dịch vụ",
"NotSupportedModel": "Mô hình không được hỗ trợ. \nVui lòng sử dụng mô hình LLM."
}
},
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,11 @@
"InvalidHuggingFaceUrl": "Hugging Face URL 无效。",
"ServiceName": "服务名称",
"ModelStoreFolderName": "模型存储文件夹名称",
"NotSupportedModel": "不支持该型号。\n请使用LLM模型。"
"NotSupportedModel": "不支持该型号。\n请使用LLM模型。",
"NewModelStoreFolderHasBeenCreated": "新的模型存储文件夹已创建",
"NewModelStoreServiceHasBeenCreated": "打造门店服务新模式",
"OpenFolder": "打开文件夹",
"ViewServiceInfo": "查看服务信息"
}
},
"dialog": {
Expand Down
6 changes: 5 additions & 1 deletion resources/i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,11 @@
"InvalidHuggingFaceUrl": "Hugging Face URL 无效。",
"ServiceName": "服務名稱",
"ModelStoreFolderName": "模型儲存資料夾名稱",
"NotSupportedModel": "不支援該型號。\n請使用LLM模型。"
"NotSupportedModel": "不支援該型號。\n請使用LLM模型。",
"NewModelStoreFolderHasBeenCreated": "新的模型儲存資料夾已創建",
"NewModelStoreServiceHasBeenCreated": "打造門市服務新模式",
"OpenFolder": "打開資料夾",
"ViewServiceInfo": "查看服務資訊"
}
},
"dialog": {
Expand Down

0 comments on commit b72d152

Please sign in to comment.