unstructured-platform-plugins 0.0.5__tar.gz → 0.0.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {unstructured-platform-plugins-0.0.5/unstructured_platform_plugins.egg-info → unstructured-platform-plugins-0.0.7}/PKG-INFO +1 -1
- unstructured-platform-plugins-0.0.7/unstructured_platform_plugins/__version__.py +1 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/unstructured_platform_plugins/etl_uvicorn/api_generator.py +52 -29
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7/unstructured_platform_plugins.egg-info}/PKG-INFO +1 -1
- unstructured-platform-plugins-0.0.5/unstructured_platform_plugins/__version__.py +0 -1
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/LICENSE +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/LICENSE.md +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/README.md +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/pyproject.toml +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/setup.cfg +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/setup.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/test/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/test/assets/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/test/assets/async_typed_dict_response.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/test/assets/dataclass_response.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/test/assets/empty_input_and_response.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/test/assets/hash_function.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/test/assets/improper_function.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/test/assets/pydantic_response_class_method.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/test/assets/simple_hash_class.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/test/assets/simple_hash_lambda.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/test/assets/simple_hash_value.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/test/assets/typed_dict_response.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/test/test_schema.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/test/test_utils.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/unstructured_platform_plugins/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/unstructured_platform_plugins/etl_uvicorn/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/unstructured_platform_plugins/etl_uvicorn/main.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/unstructured_platform_plugins/etl_uvicorn/otel.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/unstructured_platform_plugins/etl_uvicorn/utils.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/unstructured_platform_plugins/schema/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/unstructured_platform_plugins/schema/json_schema.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/unstructured_platform_plugins/schema/model.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/unstructured_platform_plugins/schema/usage.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/unstructured_platform_plugins/schema/utils.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/unstructured_platform_plugins/type_hints.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/unstructured_platform_plugins/validate_api.py +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/unstructured_platform_plugins.egg-info/SOURCES.txt +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/unstructured_platform_plugins.egg-info/dependency_links.txt +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/unstructured_platform_plugins.egg-info/entry_points.txt +0 -0
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/unstructured_platform_plugins.egg-info/requires.txt +3 -3
- {unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/unstructured_platform_plugins.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: unstructured-platform-plugins
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.7
|
|
4
4
|
Summary: A utility library that provides tools around unstructured plugin development
|
|
5
5
|
Home-page: https://github.com/Unstructured-IO/unstructured-platform-plugins
|
|
6
6
|
License: Apache-2.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.7" # pragma: no cover
|
|
@@ -7,6 +7,7 @@ from functools import partial
|
|
|
7
7
|
from typing import Any, Callable, Optional
|
|
8
8
|
|
|
9
9
|
from fastapi import FastAPI, status
|
|
10
|
+
from fastapi.responses import StreamingResponse
|
|
10
11
|
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
|
|
11
12
|
from pydantic import BaseModel
|
|
12
13
|
from starlette.responses import RedirectResponse
|
|
@@ -66,30 +67,11 @@ def check_precheck_func(precheck_func: Callable):
|
|
|
66
67
|
raise ValueError(f"no output should exist for precheck function, found: {outputs}")
|
|
67
68
|
|
|
68
69
|
|
|
69
|
-
def
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
precheck_str: Optional[str] = None,
|
|
75
|
-
precheck_method: Optional[str] = None,
|
|
76
|
-
) -> FastAPI:
|
|
77
|
-
instance = import_from_string(app)
|
|
78
|
-
func = get_func(instance, method_name)
|
|
79
|
-
if id_str:
|
|
80
|
-
id_ref = import_from_string(id_str)
|
|
81
|
-
plugin_id = get_plugin_id(instance=id_ref, method_name=id_method)
|
|
82
|
-
else:
|
|
83
|
-
plugin_id = hashlib.sha256(
|
|
84
|
-
json.dumps(get_schema_dict(func), sort_keys=True).encode()
|
|
85
|
-
).hexdigest()[:32]
|
|
86
|
-
|
|
87
|
-
precheck_func = None
|
|
88
|
-
if precheck_str:
|
|
89
|
-
precheck_instance = import_from_string(precheck_str)
|
|
90
|
-
precheck_func = get_func(precheck_instance, precheck_method)
|
|
91
|
-
elif precheck_method:
|
|
92
|
-
precheck_func = get_func(instance, precheck_method)
|
|
70
|
+
def wrap_in_fastapi(
|
|
71
|
+
func: Callable,
|
|
72
|
+
plugin_id: str,
|
|
73
|
+
precheck_func: Optional[Callable] = None,
|
|
74
|
+
):
|
|
93
75
|
if precheck_func is not None:
|
|
94
76
|
check_precheck_func(precheck_func=precheck_func)
|
|
95
77
|
|
|
@@ -110,7 +92,9 @@ def generate_fast_api(
|
|
|
110
92
|
|
|
111
93
|
logging.getLogger("etl_uvicorn.fastapi")
|
|
112
94
|
|
|
113
|
-
|
|
95
|
+
ResponseType = StreamingResponse if inspect.isasyncgenfunction(func) else InvokeResponse
|
|
96
|
+
|
|
97
|
+
async def wrap_fn(func: Callable, kwargs: Optional[dict[str, Any]] = None) -> ResponseType:
|
|
114
98
|
usage: list[UsageData] = []
|
|
115
99
|
request_dict = kwargs if kwargs else {}
|
|
116
100
|
if "usage" in inspect.signature(func).parameters:
|
|
@@ -118,8 +102,19 @@ def generate_fast_api(
|
|
|
118
102
|
else:
|
|
119
103
|
logger.warning("usage data not an expected parameter, omitting")
|
|
120
104
|
try:
|
|
121
|
-
|
|
122
|
-
|
|
105
|
+
if inspect.isasyncgenfunction(func):
|
|
106
|
+
# Stream response if function is an async generator
|
|
107
|
+
|
|
108
|
+
async def _stream_response():
|
|
109
|
+
async for output in func(**(request_dict or {})):
|
|
110
|
+
yield InvokeResponse(
|
|
111
|
+
usage=usage, status_code=status.HTTP_200_OK, output=output
|
|
112
|
+
).model_dump_json() + "\n"
|
|
113
|
+
|
|
114
|
+
return StreamingResponse(_stream_response(), media_type="application/x-ndjson")
|
|
115
|
+
else:
|
|
116
|
+
output = await invoke_func(func=func, kwargs=request_dict)
|
|
117
|
+
return InvokeResponse(usage=usage, status_code=status.HTTP_200_OK, output=output)
|
|
123
118
|
except Exception as invoke_error:
|
|
124
119
|
logger.error(f"failed to invoke plugin: {invoke_error}", exc_info=True)
|
|
125
120
|
return InvokeResponse(
|
|
@@ -132,7 +127,7 @@ def generate_fast_api(
|
|
|
132
127
|
if input_schema_model.model_fields:
|
|
133
128
|
|
|
134
129
|
@fastapi_app.post("/invoke", response_model=InvokeResponse)
|
|
135
|
-
async def run_job(request: input_schema_model) ->
|
|
130
|
+
async def run_job(request: input_schema_model) -> ResponseType:
|
|
136
131
|
log_func_and_body(func=func, body=request.json())
|
|
137
132
|
# Create dictionary from pydantic model while preserving underlying types
|
|
138
133
|
request_dict = {f: getattr(request, f) for f in request.model_fields}
|
|
@@ -144,7 +139,7 @@ def generate_fast_api(
|
|
|
144
139
|
else:
|
|
145
140
|
|
|
146
141
|
@fastapi_app.post("/invoke", response_model=InvokeResponse)
|
|
147
|
-
async def run_job() ->
|
|
142
|
+
async def run_job() -> ResponseType:
|
|
148
143
|
log_func_and_body(func=func)
|
|
149
144
|
return await wrap_fn(
|
|
150
145
|
func=func,
|
|
@@ -196,3 +191,31 @@ def generate_fast_api(
|
|
|
196
191
|
)
|
|
197
192
|
|
|
198
193
|
return fastapi_app
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def generate_fast_api(
|
|
197
|
+
app: str,
|
|
198
|
+
method_name: Optional[str] = None,
|
|
199
|
+
id_str: Optional[str] = None,
|
|
200
|
+
id_method: Optional[str] = None,
|
|
201
|
+
precheck_str: Optional[str] = None,
|
|
202
|
+
precheck_method: Optional[str] = None,
|
|
203
|
+
) -> FastAPI:
|
|
204
|
+
instance = import_from_string(app)
|
|
205
|
+
func = get_func(instance, method_name)
|
|
206
|
+
if id_str:
|
|
207
|
+
id_ref = import_from_string(id_str)
|
|
208
|
+
plugin_id = get_plugin_id(instance=id_ref, method_name=id_method)
|
|
209
|
+
else:
|
|
210
|
+
plugin_id = hashlib.sha256(
|
|
211
|
+
json.dumps(get_schema_dict(func), sort_keys=True).encode()
|
|
212
|
+
).hexdigest()[:32]
|
|
213
|
+
|
|
214
|
+
precheck_func = None
|
|
215
|
+
if precheck_str:
|
|
216
|
+
precheck_instance = import_from_string(precheck_str)
|
|
217
|
+
precheck_func = get_func(precheck_instance, precheck_method)
|
|
218
|
+
elif precheck_method:
|
|
219
|
+
precheck_func = get_func(instance, precheck_method)
|
|
220
|
+
|
|
221
|
+
return wrap_in_fastapi(func=func, plugin_id=plugin_id, precheck_func=precheck_func)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: unstructured-platform-plugins
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.7
|
|
4
4
|
Summary: A utility library that provides tools around unstructured plugin development
|
|
5
5
|
Home-page: https://github.com/Unstructured-IO/unstructured-platform-plugins
|
|
6
6
|
License: Apache-2.0
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.0.5" # pragma: no cover
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/test/__init__.py
RENAMED
|
File without changes
|
{unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/test/assets/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/test/test_schema.py
RENAMED
|
File without changes
|
{unstructured-platform-plugins-0.0.5 → unstructured-platform-plugins-0.0.7}/test/test_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|