2323 get_schema_dict ,
2424 map_inputs ,
2525)
26- from unstructured_platform_plugins .exceptions import UnrecoverableException
26+ from unstructured_platform_plugins .schema import FileDataMeta , UsageData
2727from unstructured_platform_plugins .schema .json_schema import (
2828 schema_to_base_model ,
2929)
30- from unstructured_platform_plugins .schema .usage import UsageData
3130
3231logger = logging .getLogger ("uvicorn.error" )
3332
@@ -85,10 +84,11 @@ def wrap_in_fastapi(
8584 class InvokeResponse (BaseModel ):
8685 usage : list [UsageData ]
8786 status_code : int
87+ filedata_meta : FileDataMeta
8888 status_code_text : Optional [str ] = None
8989 output : Optional [response_type ] = None
9090
91- input_schema = get_input_schema (func , omit = ["usage" ])
91+ input_schema = get_input_schema (func , omit = ["usage" , "filedata_meta" ])
9292 input_schema_model = schema_to_base_model (input_schema )
9393
9494 logging .getLogger ("etl_uvicorn.fastapi" )
@@ -97,36 +97,41 @@ class InvokeResponse(BaseModel):
9797
9898 async def wrap_fn (func : Callable , kwargs : Optional [dict [str , Any ]] = None ) -> ResponseType :
9999 usage : list [UsageData ] = []
100+ filedata_meta = FileDataMeta ()
100101 request_dict = kwargs if kwargs else {}
101102 if "usage" in inspect .signature (func ).parameters :
102103 request_dict ["usage" ] = usage
103104 else :
104- logger .debug ("usage data not an expected parameter, omitting" )
105+ logger .warning ("usage data not an expected parameter, omitting" )
106+ if "filedata_meta" in inspect .signature (func ).parameters :
107+ request_dict ["filedata_meta" ] = filedata_meta
105108 try :
106109 if inspect .isasyncgenfunction (func ):
107110 # Stream response if function is an async generator
108111
109112 async def _stream_response ():
110113 async for output in func (** (request_dict or {})):
111114 yield InvokeResponse (
112- usage = usage , status_code = status .HTTP_200_OK , output = output
115+ usage = usage ,
116+ filedata_meta = filedata_meta ,
117+ status_code = status .HTTP_200_OK ,
118+ output = output ,
113119 ).model_dump_json () + "\n "
114120
115121 return StreamingResponse (_stream_response (), media_type = "application/x-ndjson" )
116122 else :
117- try :
118- output = await invoke_func (func = func , kwargs = request_dict )
119- return InvokeResponse (
120- usage = usage , status_code = status .HTTP_200_OK , output = output
121- )
122- except UnrecoverableException as ex :
123- # Thrower of this exception is responsible for logging necessary information
124- logger .info ("Unrecoverable error occurred during plugin invocation" )
125- return InvokeResponse (usage = usage , status_code = 512 , status_code_text = ex .message )
123+ output = await invoke_func (func = func , kwargs = request_dict )
124+ return InvokeResponse (
125+ usage = usage ,
126+ filedata_meta = filedata_meta ,
127+ status_code = status .HTTP_200_OK ,
128+ output = output ,
129+ )
126130 except Exception as invoke_error :
127131 logger .error (f"failed to invoke plugin: { invoke_error } " , exc_info = True )
128132 return InvokeResponse (
129133 usage = usage ,
134+ filedata_meta = filedata_meta ,
130135 status_code = status .HTTP_500_INTERNAL_SERVER_ERROR ,
131136 status_code_text = f"failed to invoke plugin: "
132137 f"[{ invoke_error .__class__ .__name__ } ] { invoke_error } " ,
0 commit comments