|
9 | 9 | from fastapi import FastAPI, HTTPException, status |
10 | 10 | from fastapi.responses import StreamingResponse |
11 | 11 | from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor |
12 | | -from pydantic import BaseModel, Field, create_model |
| 12 | +from pydantic import BaseModel, Field, ValidationError, create_model |
13 | 13 | from starlette.responses import RedirectResponse |
14 | | -from unstructured_ingest.data_types.file_data import BatchFileData, FileData, file_data_from_dict |
15 | | -from unstructured_ingest.error import UnstructuredIngestError |
| 14 | +from utic_public_types.plugins.file_data import BatchFileData, FileData |
| 15 | +from utic_public_types.plugins.errors import UnstructuredIngestError |
16 | 16 | from uvicorn.config import LOG_LEVELS |
17 | 17 | from uvicorn.importer import import_from_string |
18 | 18 |
|
|
32 | 32 |
|
33 | 33 | FileDataType = Union[FileData, BatchFileData] |
34 | 34 |
|
| 35 | +logger = logging.getLogger("uvicorn.error") |
35 | 36 |
|
36 | | -class EtlApiException(Exception): |
37 | | - pass |
| 37 | + |
| 38 | +def file_data_from_dict(data: dict) -> FileData: |
| 39 | + try: |
| 40 | + return BatchFileData.model_validate(data) |
| 41 | + except ValidationError: |
| 42 | + logger.debug(f"{data} not valid for batch file data") |
| 43 | + return FileData.model_validate(data) |
38 | 44 |
|
39 | 45 |
|
40 | | -logger = logging.getLogger("uvicorn.error") |
| 46 | +class EtlApiException(Exception): |
| 47 | + pass |
41 | 48 |
|
42 | 49 |
|
43 | 50 | class MessageChannels(BaseModel): |
|
0 commit comments