unstructured-platform-plugins 0.0.7__tar.gz → 0.0.9__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.7/unstructured_platform_plugins.egg-info → unstructured-platform-plugins-0.0.9}/PKG-INFO +1 -1
- unstructured-platform-plugins-0.0.9/test/assets/filedata_meta.py +33 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/test/test_schema.py +110 -3
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/test/test_utils.py +1 -1
- unstructured-platform-plugins-0.0.9/unstructured_platform_plugins/__version__.py +1 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/unstructured_platform_plugins/etl_uvicorn/api_generator.py +52 -6
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/unstructured_platform_plugins/etl_uvicorn/otel.py +0 -1
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/unstructured_platform_plugins/etl_uvicorn/utils.py +9 -5
- unstructured-platform-plugins-0.0.9/unstructured_platform_plugins/exceptions.py +4 -0
- unstructured-platform-plugins-0.0.9/unstructured_platform_plugins/schema/__init__.py +4 -0
- unstructured-platform-plugins-0.0.9/unstructured_platform_plugins/schema/filedata_meta.py +14 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/unstructured_platform_plugins/schema/json_schema.py +10 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9/unstructured_platform_plugins.egg-info}/PKG-INFO +1 -1
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/unstructured_platform_plugins.egg-info/SOURCES.txt +3 -0
- unstructured-platform-plugins-0.0.7/unstructured_platform_plugins/__version__.py +0 -1
- unstructured-platform-plugins-0.0.7/unstructured_platform_plugins/schema/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/LICENSE +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/LICENSE.md +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/README.md +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/pyproject.toml +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/setup.cfg +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/setup.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/test/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/test/assets/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/test/assets/async_typed_dict_response.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/test/assets/dataclass_response.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/test/assets/empty_input_and_response.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/test/assets/hash_function.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/test/assets/improper_function.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/test/assets/pydantic_response_class_method.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/test/assets/simple_hash_class.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/test/assets/simple_hash_lambda.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/test/assets/simple_hash_value.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/test/assets/typed_dict_response.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/unstructured_platform_plugins/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/unstructured_platform_plugins/etl_uvicorn/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/unstructured_platform_plugins/etl_uvicorn/main.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/unstructured_platform_plugins/schema/model.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/unstructured_platform_plugins/schema/usage.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/unstructured_platform_plugins/schema/utils.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/unstructured_platform_plugins/type_hints.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/unstructured_platform_plugins/validate_api.py +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/unstructured_platform_plugins.egg-info/dependency_links.txt +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/unstructured_platform_plugins.egg-info/entry_points.txt +0 -0
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/unstructured_platform_plugins.egg-info/requires.txt +3 -3
- {unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/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.9
|
|
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,33 @@
|
|
|
1
|
+
import math
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel
|
|
5
|
+
from unstructured_ingest.v2.interfaces import FileData
|
|
6
|
+
|
|
7
|
+
from unstructured_platform_plugins.schema import FileDataMeta, NewRecord
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Input(BaseModel):
|
|
11
|
+
m: int
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Output(BaseModel):
|
|
15
|
+
n: float
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def process_input(i: Input, file_data: FileData, filedata_meta: FileDataMeta) -> Optional[Output]:
|
|
19
|
+
if i.m > 10:
|
|
20
|
+
filedata_meta.terminate_current = True
|
|
21
|
+
new_content = [
|
|
22
|
+
NewRecord(
|
|
23
|
+
file_data=FileData(
|
|
24
|
+
identifier=str(i.m + x), connector_type=file_data.connector_type
|
|
25
|
+
),
|
|
26
|
+
contents=Output(n=float(i.m + x)),
|
|
27
|
+
)
|
|
28
|
+
for x in range(5)
|
|
29
|
+
]
|
|
30
|
+
filedata_meta.new_records.extend(new_content)
|
|
31
|
+
return None
|
|
32
|
+
else:
|
|
33
|
+
return Output(n=math.pi + i.m)
|
{unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/test/test_schema.py
RENAMED
|
@@ -560,10 +560,64 @@ def test_file_data():
|
|
|
560
560
|
},
|
|
561
561
|
},
|
|
562
562
|
"required": [],
|
|
563
|
+
"default": {
|
|
564
|
+
"type": "object",
|
|
565
|
+
"properties": {
|
|
566
|
+
"url": {
|
|
567
|
+
"anyOf": [{"type": "string"}, {"type": "null"}],
|
|
568
|
+
"default": None,
|
|
569
|
+
},
|
|
570
|
+
"version": {
|
|
571
|
+
"anyOf": [{"type": "string"}, {"type": "null"}],
|
|
572
|
+
"default": None,
|
|
573
|
+
},
|
|
574
|
+
"record_locator": {
|
|
575
|
+
"anyOf": [
|
|
576
|
+
{
|
|
577
|
+
"type": "object",
|
|
578
|
+
"items": {"key": {"type": "string"}, "value": {}},
|
|
579
|
+
},
|
|
580
|
+
{"type": "null"},
|
|
581
|
+
],
|
|
582
|
+
"default": None,
|
|
583
|
+
},
|
|
584
|
+
"date_created": {
|
|
585
|
+
"anyOf": [{"type": "string"}, {"type": "null"}],
|
|
586
|
+
"default": None,
|
|
587
|
+
},
|
|
588
|
+
"date_modified": {
|
|
589
|
+
"anyOf": [{"type": "string"}, {"type": "null"}],
|
|
590
|
+
"default": None,
|
|
591
|
+
},
|
|
592
|
+
"date_processed": {
|
|
593
|
+
"anyOf": [{"type": "string"}, {"type": "null"}],
|
|
594
|
+
"default": None,
|
|
595
|
+
},
|
|
596
|
+
"permissions_data": {
|
|
597
|
+
"anyOf": [
|
|
598
|
+
{
|
|
599
|
+
"type": "array",
|
|
600
|
+
"items": {
|
|
601
|
+
"type": "object",
|
|
602
|
+
"items": {"key": {"type": "string"}, "value": {}},
|
|
603
|
+
},
|
|
604
|
+
},
|
|
605
|
+
{"type": "null"},
|
|
606
|
+
],
|
|
607
|
+
"default": None,
|
|
608
|
+
},
|
|
609
|
+
"filesize_bytes": {
|
|
610
|
+
"anyOf": [{"type": "integer"}, {"type": "null"}],
|
|
611
|
+
"default": None,
|
|
612
|
+
},
|
|
613
|
+
},
|
|
614
|
+
"required": [],
|
|
615
|
+
},
|
|
563
616
|
},
|
|
564
617
|
"additional_metadata": {
|
|
565
618
|
"type": "object",
|
|
566
619
|
"items": {"key": {"type": "string"}, "value": {}},
|
|
620
|
+
"default": {},
|
|
567
621
|
},
|
|
568
622
|
"reprocess": {"type": "boolean", "default": False},
|
|
569
623
|
"local_download_path": {
|
|
@@ -571,7 +625,7 @@ def test_file_data():
|
|
|
571
625
|
"default": None,
|
|
572
626
|
},
|
|
573
627
|
},
|
|
574
|
-
"required": ["identifier", "connector_type"
|
|
628
|
+
"required": ["identifier", "connector_type"],
|
|
575
629
|
}
|
|
576
630
|
},
|
|
577
631
|
}
|
|
@@ -657,10 +711,64 @@ def test_file_data():
|
|
|
657
711
|
},
|
|
658
712
|
},
|
|
659
713
|
"required": [],
|
|
714
|
+
"default": {
|
|
715
|
+
"type": "object",
|
|
716
|
+
"properties": {
|
|
717
|
+
"url": {
|
|
718
|
+
"anyOf": [{"type": "string"}, {"type": "null"}],
|
|
719
|
+
"default": None,
|
|
720
|
+
},
|
|
721
|
+
"version": {
|
|
722
|
+
"anyOf": [{"type": "string"}, {"type": "null"}],
|
|
723
|
+
"default": None,
|
|
724
|
+
},
|
|
725
|
+
"record_locator": {
|
|
726
|
+
"anyOf": [
|
|
727
|
+
{
|
|
728
|
+
"type": "object",
|
|
729
|
+
"items": {"key": {"type": "string"}, "value": {}},
|
|
730
|
+
},
|
|
731
|
+
{"type": "null"},
|
|
732
|
+
],
|
|
733
|
+
"default": None,
|
|
734
|
+
},
|
|
735
|
+
"date_created": {
|
|
736
|
+
"anyOf": [{"type": "string"}, {"type": "null"}],
|
|
737
|
+
"default": None,
|
|
738
|
+
},
|
|
739
|
+
"date_modified": {
|
|
740
|
+
"anyOf": [{"type": "string"}, {"type": "null"}],
|
|
741
|
+
"default": None,
|
|
742
|
+
},
|
|
743
|
+
"date_processed": {
|
|
744
|
+
"anyOf": [{"type": "string"}, {"type": "null"}],
|
|
745
|
+
"default": None,
|
|
746
|
+
},
|
|
747
|
+
"permissions_data": {
|
|
748
|
+
"anyOf": [
|
|
749
|
+
{
|
|
750
|
+
"type": "array",
|
|
751
|
+
"items": {
|
|
752
|
+
"type": "object",
|
|
753
|
+
"items": {"key": {"type": "string"}, "value": {}},
|
|
754
|
+
},
|
|
755
|
+
},
|
|
756
|
+
{"type": "null"},
|
|
757
|
+
],
|
|
758
|
+
"default": None,
|
|
759
|
+
},
|
|
760
|
+
"filesize_bytes": {
|
|
761
|
+
"anyOf": [{"type": "integer"}, {"type": "null"}],
|
|
762
|
+
"default": None,
|
|
763
|
+
},
|
|
764
|
+
},
|
|
765
|
+
"required": [],
|
|
766
|
+
},
|
|
660
767
|
},
|
|
661
768
|
"additional_metadata": {
|
|
662
769
|
"type": "object",
|
|
663
770
|
"items": {"key": {"type": "string"}, "value": {}},
|
|
771
|
+
"default": {},
|
|
664
772
|
},
|
|
665
773
|
"reprocess": {"type": "boolean", "default": False},
|
|
666
774
|
"local_download_path": {
|
|
@@ -668,9 +776,8 @@ def test_file_data():
|
|
|
668
776
|
"default": None,
|
|
669
777
|
},
|
|
670
778
|
},
|
|
671
|
-
"required": ["identifier", "connector_type"
|
|
779
|
+
"required": ["identifier", "connector_type"],
|
|
672
780
|
},
|
|
673
781
|
}
|
|
674
|
-
|
|
675
782
|
assert output_schema == expected_output_schema
|
|
676
783
|
assert is_valid_response_dict(output_schema)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.9" # pragma: no cover
|
|
@@ -4,13 +4,14 @@ import inspect
|
|
|
4
4
|
import json
|
|
5
5
|
import logging
|
|
6
6
|
from functools import partial
|
|
7
|
-
from typing import Any, Callable, Optional
|
|
7
|
+
from typing import Any, Callable, Optional, Union
|
|
8
8
|
|
|
9
9
|
from fastapi import FastAPI, status
|
|
10
10
|
from fastapi.responses import StreamingResponse
|
|
11
11
|
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
|
|
12
|
-
from pydantic import BaseModel
|
|
12
|
+
from pydantic import BaseModel, Field, create_model
|
|
13
13
|
from starlette.responses import RedirectResponse
|
|
14
|
+
from unstructured_ingest.v2.interfaces import FileData
|
|
14
15
|
from uvicorn.config import LOG_LEVELS
|
|
15
16
|
from uvicorn.importer import import_from_string
|
|
16
17
|
|
|
@@ -23,10 +24,10 @@ from unstructured_platform_plugins.etl_uvicorn.utils import (
|
|
|
23
24
|
get_schema_dict,
|
|
24
25
|
map_inputs,
|
|
25
26
|
)
|
|
27
|
+
from unstructured_platform_plugins.schema import FileDataMeta, NewRecord, UsageData
|
|
26
28
|
from unstructured_platform_plugins.schema.json_schema import (
|
|
27
29
|
schema_to_base_model,
|
|
28
30
|
)
|
|
29
|
-
from unstructured_platform_plugins.schema.usage import UsageData
|
|
30
31
|
|
|
31
32
|
logger = logging.getLogger("uvicorn.error")
|
|
32
33
|
|
|
@@ -67,6 +68,30 @@ def check_precheck_func(precheck_func: Callable):
|
|
|
67
68
|
raise ValueError(f"no output should exist for precheck function, found: {outputs}")
|
|
68
69
|
|
|
69
70
|
|
|
71
|
+
def is_optional(t: Any) -> bool:
|
|
72
|
+
return (
|
|
73
|
+
hasattr(t, "__origin__")
|
|
74
|
+
and t.__origin__ is Union
|
|
75
|
+
and hasattr(t, "__args__")
|
|
76
|
+
and type(None) in t.__args__
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def update_filedata_model(new_type) -> BaseModel:
|
|
81
|
+
field_info = NewRecord.model_fields["contents"]
|
|
82
|
+
if is_optional(new_type):
|
|
83
|
+
field_info.default = None
|
|
84
|
+
new_record_model = create_model(
|
|
85
|
+
NewRecord.__name__, contents=(new_type, field_info), __base__=NewRecord
|
|
86
|
+
)
|
|
87
|
+
new_filedata_model = create_model(
|
|
88
|
+
FileDataMeta.__name__,
|
|
89
|
+
new_records=(list[new_record_model], Field(default_factory=list)),
|
|
90
|
+
__base__=FileDataMeta,
|
|
91
|
+
)
|
|
92
|
+
return new_filedata_model
|
|
93
|
+
|
|
94
|
+
|
|
70
95
|
def wrap_in_fastapi(
|
|
71
96
|
func: Callable,
|
|
72
97
|
plugin_id: str,
|
|
@@ -80,14 +105,16 @@ def wrap_in_fastapi(
|
|
|
80
105
|
fastapi_app = FastAPI()
|
|
81
106
|
|
|
82
107
|
response_type = get_output_sig(func)
|
|
108
|
+
filedata_meta_model = update_filedata_model(response_type)
|
|
83
109
|
|
|
84
110
|
class InvokeResponse(BaseModel):
|
|
85
111
|
usage: list[UsageData]
|
|
86
112
|
status_code: int
|
|
113
|
+
filedata_meta: filedata_meta_model
|
|
87
114
|
status_code_text: Optional[str] = None
|
|
88
115
|
output: Optional[response_type] = None
|
|
89
116
|
|
|
90
|
-
input_schema = get_input_schema(func, omit=["usage"])
|
|
117
|
+
input_schema = get_input_schema(func, omit=["usage", "filedata_meta"])
|
|
91
118
|
input_schema_model = schema_to_base_model(input_schema)
|
|
92
119
|
|
|
93
120
|
logging.getLogger("etl_uvicorn.fastapi")
|
|
@@ -96,11 +123,14 @@ def wrap_in_fastapi(
|
|
|
96
123
|
|
|
97
124
|
async def wrap_fn(func: Callable, kwargs: Optional[dict[str, Any]] = None) -> ResponseType:
|
|
98
125
|
usage: list[UsageData] = []
|
|
126
|
+
filedata_meta = FileDataMeta()
|
|
99
127
|
request_dict = kwargs if kwargs else {}
|
|
100
128
|
if "usage" in inspect.signature(func).parameters:
|
|
101
129
|
request_dict["usage"] = usage
|
|
102
130
|
else:
|
|
103
131
|
logger.warning("usage data not an expected parameter, omitting")
|
|
132
|
+
if "filedata_meta" in inspect.signature(func).parameters:
|
|
133
|
+
request_dict["filedata_meta"] = filedata_meta
|
|
104
134
|
try:
|
|
105
135
|
if inspect.isasyncgenfunction(func):
|
|
106
136
|
# Stream response if function is an async generator
|
|
@@ -108,17 +138,28 @@ def wrap_in_fastapi(
|
|
|
108
138
|
async def _stream_response():
|
|
109
139
|
async for output in func(**(request_dict or {})):
|
|
110
140
|
yield InvokeResponse(
|
|
111
|
-
usage=usage,
|
|
141
|
+
usage=usage,
|
|
142
|
+
filedata_meta=filedata_meta_model.model_validate(
|
|
143
|
+
filedata_meta.model_dump()
|
|
144
|
+
),
|
|
145
|
+
status_code=status.HTTP_200_OK,
|
|
146
|
+
output=output,
|
|
112
147
|
).model_dump_json() + "\n"
|
|
113
148
|
|
|
114
149
|
return StreamingResponse(_stream_response(), media_type="application/x-ndjson")
|
|
115
150
|
else:
|
|
116
151
|
output = await invoke_func(func=func, kwargs=request_dict)
|
|
117
|
-
return InvokeResponse(
|
|
152
|
+
return InvokeResponse(
|
|
153
|
+
usage=usage,
|
|
154
|
+
filedata_meta=filedata_meta_model.model_validate(filedata_meta.model_dump()),
|
|
155
|
+
status_code=status.HTTP_200_OK,
|
|
156
|
+
output=output,
|
|
157
|
+
)
|
|
118
158
|
except Exception as invoke_error:
|
|
119
159
|
logger.error(f"failed to invoke plugin: {invoke_error}", exc_info=True)
|
|
120
160
|
return InvokeResponse(
|
|
121
161
|
usage=usage,
|
|
162
|
+
filedata_meta=filedata_meta_model.model_validate(filedata_meta.model_dump()),
|
|
122
163
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
123
164
|
status_code_text=f"failed to invoke plugin: "
|
|
124
165
|
f"[{invoke_error.__class__.__name__}] {invoke_error}",
|
|
@@ -131,6 +172,11 @@ def wrap_in_fastapi(
|
|
|
131
172
|
log_func_and_body(func=func, body=request.json())
|
|
132
173
|
# Create dictionary from pydantic model while preserving underlying types
|
|
133
174
|
request_dict = {f: getattr(request, f) for f in request.model_fields}
|
|
175
|
+
# Map FileData back to original dataclass if present
|
|
176
|
+
if "file_data" in request_dict:
|
|
177
|
+
request_dict["file_data"] = FileData.from_dict(
|
|
178
|
+
request_dict["file_data"].model_dump()
|
|
179
|
+
)
|
|
134
180
|
map_inputs(func=func, raw_inputs=request_dict)
|
|
135
181
|
if logger.level == LOG_LEVELS.get("trace", logging.NOTSET):
|
|
136
182
|
logger.log(level=logger.level, msg=f"passing inputs to function: {request_dict}")
|
|
@@ -42,7 +42,6 @@ def get_settings() -> OtelSettings:
|
|
|
42
42
|
|
|
43
43
|
def get_trace_provider() -> TracerProvider:
|
|
44
44
|
settings = get_settings()
|
|
45
|
-
print(settings)
|
|
46
45
|
provider = TracerProvider(resource=Resource({SERVICE_NAME: settings["service_name"]}))
|
|
47
46
|
|
|
48
47
|
for trace_exporter_type in settings["trace_exporters"]:
|
|
@@ -16,6 +16,10 @@ from unstructured_platform_plugins.schema.utils import get_typed_parameters
|
|
|
16
16
|
from unstructured_platform_plugins.type_hints import get_type_hints
|
|
17
17
|
|
|
18
18
|
|
|
19
|
+
def is_optional(t: Any) -> bool:
|
|
20
|
+
return hasattr(t, "__origin__") and t.__origin__ is not None
|
|
21
|
+
|
|
22
|
+
|
|
19
23
|
def get_func(instance: Any, method_name: Optional[str] = None) -> Callable:
|
|
20
24
|
method_name = method_name or "__call__"
|
|
21
25
|
if inspect.isfunction(instance):
|
|
@@ -111,10 +115,10 @@ def map_inputs(func: Callable, raw_inputs: dict[str, Any]) -> dict[str, Any]:
|
|
|
111
115
|
and not isinstance(type_data, GenericAlias)
|
|
112
116
|
and issubclass(type_data, BaseModel)
|
|
113
117
|
):
|
|
114
|
-
|
|
118
|
+
field_value = raw_inputs[field_name]
|
|
119
|
+
if isinstance(field_value, BaseModel):
|
|
120
|
+
field_value = field_value.model_dump()
|
|
121
|
+
raw_inputs[field_name] = type_data.model_validate(field_value)
|
|
115
122
|
except Exception as e:
|
|
116
|
-
|
|
117
|
-
raise exception_type(
|
|
118
|
-
f"failed to map input for field {field_name}: {field_value}"
|
|
119
|
-
) from e
|
|
123
|
+
raise ValueError(f"failed to map input for field {field_name}: {field_value}") from e
|
|
120
124
|
return raw_inputs
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field
|
|
4
|
+
from unstructured_ingest.v2.interfaces import FileData
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class NewRecord(BaseModel):
|
|
8
|
+
file_data: FileData
|
|
9
|
+
contents: Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class FileDataMeta(BaseModel):
|
|
13
|
+
terminate_current: bool = False
|
|
14
|
+
new_records: list[NewRecord] = Field(default_factory=list)
|
|
@@ -113,6 +113,12 @@ def dataclass_to_json_schema(class_or_instance: Any) -> dict:
|
|
|
113
113
|
f_resp = to_json_schema(t)
|
|
114
114
|
if f.default is not MISSING:
|
|
115
115
|
f_resp["default"] = f.default.value if isinstance(f.default, Enum) else f.default
|
|
116
|
+
elif f.default_factory is not MISSING:
|
|
117
|
+
default = f.default_factory()
|
|
118
|
+
try:
|
|
119
|
+
f_resp["default"] = to_json_schema(default)
|
|
120
|
+
except Exception:
|
|
121
|
+
f_resp["default"] = default
|
|
116
122
|
else:
|
|
117
123
|
required.append(f.name)
|
|
118
124
|
properties[f.name] = f_resp
|
|
@@ -339,6 +345,10 @@ def schema_to_base_model(schema: dict, name: str = "reconstructed_model") -> Typ
|
|
|
339
345
|
t = schema_to_base_model_type(
|
|
340
346
|
json_type_name=json_type_name, name=k, type_info=entry_info
|
|
341
347
|
)
|
|
348
|
+
elif "properties" in v:
|
|
349
|
+
t = schema_to_base_model(schema=v, name=k)
|
|
350
|
+
elif not v:
|
|
351
|
+
t = schema_to_base_model(schema={"type": "null"}, name=k)
|
|
342
352
|
else:
|
|
343
353
|
json_type_name = v["type"]
|
|
344
354
|
t = schema_to_base_model_type(json_type_name=json_type_name, name=k, type_info=v)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: unstructured-platform-plugins
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.9
|
|
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
|
|
@@ -11,6 +11,7 @@ test/assets/__init__.py
|
|
|
11
11
|
test/assets/async_typed_dict_response.py
|
|
12
12
|
test/assets/dataclass_response.py
|
|
13
13
|
test/assets/empty_input_and_response.py
|
|
14
|
+
test/assets/filedata_meta.py
|
|
14
15
|
test/assets/hash_function.py
|
|
15
16
|
test/assets/improper_function.py
|
|
16
17
|
test/assets/pydantic_response_class_method.py
|
|
@@ -20,6 +21,7 @@ test/assets/simple_hash_value.py
|
|
|
20
21
|
test/assets/typed_dict_response.py
|
|
21
22
|
unstructured_platform_plugins/__init__.py
|
|
22
23
|
unstructured_platform_plugins/__version__.py
|
|
24
|
+
unstructured_platform_plugins/exceptions.py
|
|
23
25
|
unstructured_platform_plugins/type_hints.py
|
|
24
26
|
unstructured_platform_plugins/validate_api.py
|
|
25
27
|
unstructured_platform_plugins.egg-info/PKG-INFO
|
|
@@ -34,6 +36,7 @@ unstructured_platform_plugins/etl_uvicorn/main.py
|
|
|
34
36
|
unstructured_platform_plugins/etl_uvicorn/otel.py
|
|
35
37
|
unstructured_platform_plugins/etl_uvicorn/utils.py
|
|
36
38
|
unstructured_platform_plugins/schema/__init__.py
|
|
39
|
+
unstructured_platform_plugins/schema/filedata_meta.py
|
|
37
40
|
unstructured_platform_plugins/schema/json_schema.py
|
|
38
41
|
unstructured_platform_plugins/schema/model.py
|
|
39
42
|
unstructured_platform_plugins/schema/usage.py
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.0.7" # pragma: no cover
|
|
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.7 → unstructured-platform-plugins-0.0.9}/test/__init__.py
RENAMED
|
File without changes
|
{unstructured-platform-plugins-0.0.7 → unstructured-platform-plugins-0.0.9}/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
|
|
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
|