unstructured-platform-plugins 0.0.3__tar.gz → 0.0.6__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.3/unstructured_platform_plugins.egg-info → unstructured-platform-plugins-0.0.6}/PKG-INFO +1 -1
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/test/test_schema.py +8 -0
- unstructured-platform-plugins-0.0.6/unstructured_platform_plugins/__version__.py +1 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/unstructured_platform_plugins/etl_uvicorn/api_generator.py +42 -9
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6/unstructured_platform_plugins.egg-info}/PKG-INFO +1 -1
- unstructured-platform-plugins-0.0.3/unstructured_platform_plugins/__version__.py +0 -1
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/LICENSE +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/LICENSE.md +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/README.md +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/pyproject.toml +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/setup.cfg +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/setup.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/test/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/test/assets/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/test/assets/async_typed_dict_response.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/test/assets/dataclass_response.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/test/assets/empty_input_and_response.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/test/assets/hash_function.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/test/assets/improper_function.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/test/assets/pydantic_response_class_method.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/test/assets/simple_hash_class.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/test/assets/simple_hash_lambda.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/test/assets/simple_hash_value.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/test/assets/typed_dict_response.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/test/test_utils.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/unstructured_platform_plugins/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/unstructured_platform_plugins/etl_uvicorn/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/unstructured_platform_plugins/etl_uvicorn/main.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/unstructured_platform_plugins/etl_uvicorn/otel.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/unstructured_platform_plugins/etl_uvicorn/utils.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/unstructured_platform_plugins/schema/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/unstructured_platform_plugins/schema/json_schema.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/unstructured_platform_plugins/schema/model.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/unstructured_platform_plugins/schema/usage.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/unstructured_platform_plugins/schema/utils.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/unstructured_platform_plugins/type_hints.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/unstructured_platform_plugins/validate_api.py +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/unstructured_platform_plugins.egg-info/SOURCES.txt +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/unstructured_platform_plugins.egg-info/dependency_links.txt +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/unstructured_platform_plugins.egg-info/entry_points.txt +0 -0
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/unstructured_platform_plugins.egg-info/requires.txt +3 -3
- {unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/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.6
|
|
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
|
{unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/test/test_schema.py
RENAMED
|
@@ -566,6 +566,10 @@ def test_file_data():
|
|
|
566
566
|
"items": {"key": {"type": "string"}, "value": {}},
|
|
567
567
|
},
|
|
568
568
|
"reprocess": {"type": "boolean", "default": False},
|
|
569
|
+
"local_download_path": {
|
|
570
|
+
"anyOf": [{"type": "string"}, {"type": "null"}],
|
|
571
|
+
"default": None,
|
|
572
|
+
},
|
|
569
573
|
},
|
|
570
574
|
"required": ["identifier", "connector_type", "metadata", "additional_metadata"],
|
|
571
575
|
}
|
|
@@ -659,6 +663,10 @@ def test_file_data():
|
|
|
659
663
|
"items": {"key": {"type": "string"}, "value": {}},
|
|
660
664
|
},
|
|
661
665
|
"reprocess": {"type": "boolean", "default": False},
|
|
666
|
+
"local_download_path": {
|
|
667
|
+
"anyOf": [{"type": "string"}, {"type": "null"}],
|
|
668
|
+
"default": None,
|
|
669
|
+
},
|
|
662
670
|
},
|
|
663
671
|
"required": ["identifier", "connector_type", "metadata", "additional_metadata"],
|
|
664
672
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.6" # pragma: no cover
|
|
@@ -3,12 +3,15 @@ import hashlib
|
|
|
3
3
|
import inspect
|
|
4
4
|
import json
|
|
5
5
|
import logging
|
|
6
|
+
from functools import partial
|
|
6
7
|
from typing import Any, Callable, Optional
|
|
7
8
|
|
|
8
9
|
from fastapi import FastAPI, status
|
|
10
|
+
from fastapi.responses import StreamingResponse
|
|
9
11
|
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
|
|
10
12
|
from pydantic import BaseModel
|
|
11
13
|
from starlette.responses import RedirectResponse
|
|
14
|
+
from uvicorn.config import LOG_LEVELS
|
|
12
15
|
from uvicorn.importer import import_from_string
|
|
13
16
|
|
|
14
17
|
from unstructured_platform_plugins.etl_uvicorn.otel import get_metric_provider, get_trace_provider
|
|
@@ -28,12 +31,28 @@ from unstructured_platform_plugins.schema.usage import UsageData
|
|
|
28
31
|
logger = logging.getLogger("uvicorn.error")
|
|
29
32
|
|
|
30
33
|
|
|
34
|
+
def log_func_and_body(func: Callable, body: Optional[str] = None) -> None:
|
|
35
|
+
msg = None
|
|
36
|
+
if logger.level == LOG_LEVELS.get("debug", logging.NOTSET):
|
|
37
|
+
if not body:
|
|
38
|
+
msg = f"invoking function without inputs: {func.__name__}"
|
|
39
|
+
else:
|
|
40
|
+
msg = f"invoking function {func.__name__} with body"
|
|
41
|
+
elif logger.level == LOG_LEVELS.get("trace", logging.NOTSET):
|
|
42
|
+
if not body:
|
|
43
|
+
msg = f"invoking function without inputs: {func}"
|
|
44
|
+
else:
|
|
45
|
+
msg = f"invoking function {func} with body: {body}"
|
|
46
|
+
if msg:
|
|
47
|
+
logger.log(level=logger.level, msg=msg)
|
|
48
|
+
|
|
49
|
+
|
|
31
50
|
async def invoke_func(func: Callable, kwargs: Optional[dict[str, Any]] = None) -> Any:
|
|
32
51
|
kwargs = kwargs or {}
|
|
33
52
|
if inspect.iscoroutinefunction(func):
|
|
34
53
|
return await func(**kwargs)
|
|
35
54
|
else:
|
|
36
|
-
return func
|
|
55
|
+
return await asyncio.get_event_loop().run_in_executor(None, partial(func, **kwargs))
|
|
37
56
|
|
|
38
57
|
|
|
39
58
|
def check_precheck_func(precheck_func: Callable):
|
|
@@ -92,7 +111,9 @@ def generate_fast_api(
|
|
|
92
111
|
|
|
93
112
|
logging.getLogger("etl_uvicorn.fastapi")
|
|
94
113
|
|
|
95
|
-
|
|
114
|
+
ResponseType = StreamingResponse if inspect.isasyncgenfunction(func) else InvokeResponse
|
|
115
|
+
|
|
116
|
+
async def wrap_fn(func: Callable, kwargs: Optional[dict[str, Any]] = None) -> ResponseType:
|
|
96
117
|
usage: list[UsageData] = []
|
|
97
118
|
request_dict = kwargs if kwargs else {}
|
|
98
119
|
if "usage" in inspect.signature(func).parameters:
|
|
@@ -100,8 +121,19 @@ def generate_fast_api(
|
|
|
100
121
|
else:
|
|
101
122
|
logger.warning("usage data not an expected parameter, omitting")
|
|
102
123
|
try:
|
|
103
|
-
|
|
104
|
-
|
|
124
|
+
if inspect.isasyncgenfunction(func):
|
|
125
|
+
# Stream response if function is an async generator
|
|
126
|
+
|
|
127
|
+
async def _stream_response():
|
|
128
|
+
async for output in func(**(request_dict or {})):
|
|
129
|
+
yield InvokeResponse(
|
|
130
|
+
usage=usage, status_code=status.HTTP_200_OK, output=output
|
|
131
|
+
).model_dump_json() + "\n"
|
|
132
|
+
|
|
133
|
+
return StreamingResponse(_stream_response(), media_type="application/x-ndjson")
|
|
134
|
+
else:
|
|
135
|
+
output = await invoke_func(func=func, kwargs=request_dict)
|
|
136
|
+
return InvokeResponse(usage=usage, status_code=status.HTTP_200_OK, output=output)
|
|
105
137
|
except Exception as invoke_error:
|
|
106
138
|
logger.error(f"failed to invoke plugin: {invoke_error}", exc_info=True)
|
|
107
139
|
return InvokeResponse(
|
|
@@ -114,19 +146,20 @@ def generate_fast_api(
|
|
|
114
146
|
if input_schema_model.model_fields:
|
|
115
147
|
|
|
116
148
|
@fastapi_app.post("/invoke", response_model=InvokeResponse)
|
|
117
|
-
async def run_job(request: input_schema_model) ->
|
|
118
|
-
|
|
149
|
+
async def run_job(request: input_schema_model) -> ResponseType:
|
|
150
|
+
log_func_and_body(func=func, body=request.json())
|
|
119
151
|
# Create dictionary from pydantic model while preserving underlying types
|
|
120
152
|
request_dict = {f: getattr(request, f) for f in request.model_fields}
|
|
121
153
|
map_inputs(func=func, raw_inputs=request_dict)
|
|
122
|
-
logger.
|
|
154
|
+
if logger.level == LOG_LEVELS.get("trace", logging.NOTSET):
|
|
155
|
+
logger.log(level=logger.level, msg=f"passing inputs to function: {request_dict}")
|
|
123
156
|
return await wrap_fn(func=func, kwargs=request_dict)
|
|
124
157
|
|
|
125
158
|
else:
|
|
126
159
|
|
|
127
160
|
@fastapi_app.post("/invoke", response_model=InvokeResponse)
|
|
128
|
-
async def run_job() ->
|
|
129
|
-
|
|
161
|
+
async def run_job() -> ResponseType:
|
|
162
|
+
log_func_and_body(func=func)
|
|
130
163
|
return await wrap_fn(
|
|
131
164
|
func=func,
|
|
132
165
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: unstructured-platform-plugins
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.6
|
|
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.3" # 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.3 → unstructured-platform-plugins-0.0.6}/test/__init__.py
RENAMED
|
File without changes
|
{unstructured-platform-plugins-0.0.3 → unstructured-platform-plugins-0.0.6}/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.3 → unstructured-platform-plugins-0.0.6}/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
|