fixed error handling

This commit is contained in:
Jennifer Player 2024-03-11 11:46:49 -04:00 committed by psychedelicious
parent 6369ccd05e
commit 5ad048a161
7 changed files with 31 additions and 21 deletions

View File

@ -261,11 +261,16 @@ async def get_hugging_face_models(
hugging_face_repo: str = Query(description="Hugging face repo to search for models", default=None),
) -> List[AnyHttpUrl]:
get_hugging_face_models = ApiDependencies.invoker.services.model_manager.install.get_hugging_face_models
get_hugging_face_models(hugging_face_repo)
result = get_hugging_face_models(
source=hugging_face_repo,
)
try:
result = get_hugging_face_models(
source=hugging_face_repo,
)
except ValueError as e:
raise HTTPException(
status_code=400,
detail=f"{e}",
)
return result

View File

@ -239,7 +239,11 @@ class ModelInstallService(ModelInstallServiceBase):
if not access_token:
self._logger.info("No HuggingFace access token present; some models may not be downloadable.")
metadata = HuggingFaceMetadataFetch(self._session).from_id(source)
try:
metadata = HuggingFaceMetadataFetch(self._session).from_id(source)
except:
raise ValueError("No HuggingFace repository found")
assert isinstance(metadata, ModelMetadataWithFiles)
urls: List[AnyHttpUrl] = []

View File

@ -858,7 +858,7 @@
"settings": "Settings",
"showExisting": "Show Existing",
"sigmoid": "Sigmoid",
"simpleModelPlaceholder": "URL or path to a local file",
"simpleModelPlaceholder": "URL or path to a local file or diffusers folder",
"simpleModelDesc": "Provide a path to a local Diffusers model, local checkpoint / safetensors model a HuggingFace Repo ID, or a checkpoint/diffusers model URL.",
"source": "Source",
"statusConverting": "Converting",

View File

@ -51,21 +51,20 @@ export const HuggingFaceForm = () => {
const getModels = useCallback(async () => {
_getHuggingFaceModels(huggingFaceRepo)
.unwrap()
.then((response) => {
if (response.data?.some((result) => result.endsWith('model_index.json'))) {
if (response.some((result: string) => result.endsWith('model_index.json'))) {
handleInstallModel(huggingFaceRepo);
setDisplayResults(false);
} else if (response.data?.length === 1 && response.data[0]) {
handleInstallModel(response.data[0]);
} else if (response.length === 1 && response[0]) {
handleInstallModel(response[0]);
setDisplayResults(false);
} else {
setDisplayResults(true);
}
})
.catch((error) => {
if (error) {
setErrorMessage(error.data.detail);
}
setErrorMessage(error.data.detail || '');
});
}, [_getHuggingFaceModels, handleInstallModel, huggingFaceRepo]);

View File

@ -4,7 +4,7 @@ import { addToast } from 'features/system/store/systemSlice';
import { makeToast } from 'features/system/util/makeToast';
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { IoAdd } from 'react-icons/io5';
import { PiPlusBold } from 'react-icons/pi';
import { useInstallModelMutation } from 'services/api/endpoints/models';
type Props = {
@ -51,7 +51,7 @@ export const HuggingFaceResultItem = ({ result }: Props) => {
</Flex>
<Box>
<Tooltip label={t('modelManager.quickAdd')}>
<IconButton aria-label={t('modelManager.quickAdd')} icon={<IoAdd />} onClick={handleQuickAdd} />
<IconButton aria-label={t('modelManager.quickAdd')} icon={<PiPlusBold />} onClick={handleQuickAdd} />
</Tooltip>
</Box>
</Flex>

View File

@ -17,11 +17,13 @@ export const ScanModelsForm = () => {
const [_scanFolder, { isLoading, data }] = useLazyScanFolderQuery();
const scanFolder = useCallback(async () => {
_scanFolder({ scan_path: scanPath }).catch((error) => {
if (error) {
setErrorMessage(error.data.detail);
}
});
_scanFolder({ scan_path: scanPath })
.unwrap()
.catch((error) => {
if (error) {
setErrorMessage(error.data.detail);
}
});
}, [_scanFolder, scanPath]);
const handleSetScanPath: ChangeEventHandler<HTMLInputElement> = useCallback(

View File

@ -4,7 +4,7 @@ import { addToast } from 'features/system/store/systemSlice';
import { makeToast } from 'features/system/util/makeToast';
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { IoAdd } from 'react-icons/io5';
import { PiPlusBold } from 'react-icons/pi';
import type { ScanFolderResponse } from 'services/api/endpoints/models';
import { useInstallModelMutation } from 'services/api/endpoints/models';
@ -55,7 +55,7 @@ export const ScanModelResultItem = ({ result }: Props) => {
<Badge>{t('common.installed')}</Badge>
) : (
<Tooltip label={t('modelManager.quickAdd')}>
<IconButton aria-label={t('modelManager.quickAdd')} icon={<IoAdd />} onClick={handleQuickAdd} />
<IconButton aria-label={t('modelManager.quickAdd')} icon={<PiPlusBold />} onClick={handleQuickAdd} />
</Tooltip>
)}
</Box>