unstructured-platform-plugins 0.0.1__tar.gz → 0.0.3__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.1/unstructured_platform_plugins.egg-info → unstructured-platform-plugins-0.0.3}/PKG-INFO +1 -1
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/test/test_schema.py +11 -3
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/test/test_utils.py +1 -1
- unstructured-platform-plugins-0.0.3/unstructured_platform_plugins/__version__.py +1 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/unstructured_platform_plugins/etl_uvicorn/api_generator.py +8 -2
- unstructured-platform-plugins-0.0.3/unstructured_platform_plugins/etl_uvicorn/otel.py +107 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/unstructured_platform_plugins/etl_uvicorn/utils.py +5 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/unstructured_platform_plugins/schema/json_schema.py +9 -2
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3/unstructured_platform_plugins.egg-info}/PKG-INFO +1 -1
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/unstructured_platform_plugins.egg-info/SOURCES.txt +1 -0
- unstructured-platform-plugins-0.0.3/unstructured_platform_plugins.egg-info/requires.txt +8 -0
- unstructured-platform-plugins-0.0.1/unstructured_platform_plugins/__version__.py +0 -1
- unstructured-platform-plugins-0.0.1/unstructured_platform_plugins.egg-info/requires.txt +0 -6
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/LICENSE +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/LICENSE.md +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/README.md +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/pyproject.toml +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/setup.cfg +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/setup.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/test/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/test/assets/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/test/assets/async_typed_dict_response.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/test/assets/dataclass_response.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/test/assets/empty_input_and_response.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/test/assets/hash_function.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/test/assets/improper_function.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/test/assets/pydantic_response_class_method.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/test/assets/simple_hash_class.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/test/assets/simple_hash_lambda.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/test/assets/simple_hash_value.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/test/assets/typed_dict_response.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/unstructured_platform_plugins/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/unstructured_platform_plugins/etl_uvicorn/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/unstructured_platform_plugins/etl_uvicorn/main.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/unstructured_platform_plugins/schema/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/unstructured_platform_plugins/schema/model.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/unstructured_platform_plugins/schema/usage.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/unstructured_platform_plugins/schema/utils.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/unstructured_platform_plugins/type_hints.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/unstructured_platform_plugins/validate_api.py +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/unstructured_platform_plugins.egg-info/dependency_links.txt +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/unstructured_platform_plugins.egg-info/entry_points.txt +0 -0
- {unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/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.3
|
|
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.1 → unstructured-platform-plugins-0.0.3}/test/test_schema.py
RENAMED
|
@@ -7,7 +7,7 @@ from typing import Any, Optional, Union
|
|
|
7
7
|
import pytest
|
|
8
8
|
from pydantic import BaseModel
|
|
9
9
|
from typing_extensions import TypedDict
|
|
10
|
-
from
|
|
10
|
+
from unstructured_ingest.v2.interfaces import FileData
|
|
11
11
|
|
|
12
12
|
import unstructured_platform_plugins.schema.json_schema as js
|
|
13
13
|
from unstructured_platform_plugins.etl_uvicorn.utils import get_input_schema
|
|
@@ -507,7 +507,7 @@ def test_file_data():
|
|
|
507
507
|
],
|
|
508
508
|
"default": None,
|
|
509
509
|
},
|
|
510
|
-
"doc_type": {"type": "string", "
|
|
510
|
+
"doc_type": {"type": "string", "default": "file"},
|
|
511
511
|
"metadata": {
|
|
512
512
|
"type": "object",
|
|
513
513
|
"properties": {
|
|
@@ -554,6 +554,10 @@ def test_file_data():
|
|
|
554
554
|
],
|
|
555
555
|
"default": None,
|
|
556
556
|
},
|
|
557
|
+
"filesize_bytes": {
|
|
558
|
+
"anyOf": [{"type": "integer"}, {"type": "null"}],
|
|
559
|
+
"default": None,
|
|
560
|
+
},
|
|
557
561
|
},
|
|
558
562
|
"required": [],
|
|
559
563
|
},
|
|
@@ -599,7 +603,7 @@ def test_file_data():
|
|
|
599
603
|
],
|
|
600
604
|
"default": None,
|
|
601
605
|
},
|
|
602
|
-
"doc_type": {"type": "string", "
|
|
606
|
+
"doc_type": {"type": "string", "default": "file"},
|
|
603
607
|
"metadata": {
|
|
604
608
|
"type": "object",
|
|
605
609
|
"properties": {
|
|
@@ -643,6 +647,10 @@ def test_file_data():
|
|
|
643
647
|
],
|
|
644
648
|
"default": None,
|
|
645
649
|
},
|
|
650
|
+
"filesize_bytes": {
|
|
651
|
+
"anyOf": [{"type": "integer"}, {"type": "null"}],
|
|
652
|
+
"default": None,
|
|
653
|
+
},
|
|
646
654
|
},
|
|
647
655
|
"required": [],
|
|
648
656
|
},
|
{unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/test/test_utils.py
RENAMED
|
@@ -4,7 +4,7 @@ from enum import Enum
|
|
|
4
4
|
|
|
5
5
|
import pytest
|
|
6
6
|
from pydantic import BaseModel
|
|
7
|
-
from
|
|
7
|
+
from unstructured_ingest.v2.interfaces import FileData
|
|
8
8
|
from uvicorn.importer import import_from_string
|
|
9
9
|
|
|
10
10
|
from unstructured_platform_plugins.etl_uvicorn import utils
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.3" # pragma: no cover
|
|
@@ -6,10 +6,12 @@ import logging
|
|
|
6
6
|
from typing import Any, Callable, Optional
|
|
7
7
|
|
|
8
8
|
from fastapi import FastAPI, status
|
|
9
|
+
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
|
|
9
10
|
from pydantic import BaseModel
|
|
10
11
|
from starlette.responses import RedirectResponse
|
|
11
12
|
from uvicorn.importer import import_from_string
|
|
12
13
|
|
|
14
|
+
from unstructured_platform_plugins.etl_uvicorn.otel import get_metric_provider, get_trace_provider
|
|
13
15
|
from unstructured_platform_plugins.etl_uvicorn.utils import (
|
|
14
16
|
get_func,
|
|
15
17
|
get_input_schema,
|
|
@@ -122,8 +124,8 @@ def generate_fast_api(
|
|
|
122
124
|
|
|
123
125
|
else:
|
|
124
126
|
|
|
125
|
-
@fastapi_app.post("/invoke", response_model=
|
|
126
|
-
async def run_job() ->
|
|
127
|
+
@fastapi_app.post("/invoke", response_model=InvokeResponse)
|
|
128
|
+
async def run_job() -> InvokeResponse:
|
|
127
129
|
logger.debug(f"invoking function without inputs: {func}")
|
|
128
130
|
return await wrap_fn(
|
|
129
131
|
func=func,
|
|
@@ -170,4 +172,8 @@ def generate_fast_api(
|
|
|
170
172
|
except TypeError as e:
|
|
171
173
|
raise TypeError(f"failed to validate function schema: {e}") from e
|
|
172
174
|
|
|
175
|
+
FastAPIInstrumentor.instrument_app(
|
|
176
|
+
fastapi_app, tracer_provider=get_trace_provider(), meter_provider=get_metric_provider()
|
|
177
|
+
)
|
|
178
|
+
|
|
173
179
|
return fastapi_app
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import Literal, TypedDict
|
|
3
|
+
|
|
4
|
+
from opentelemetry.environment_variables import OTEL_METRICS_EXPORTER, OTEL_TRACES_EXPORTER
|
|
5
|
+
from opentelemetry.sdk.environment_variables import OTEL_SERVICE_NAME
|
|
6
|
+
from opentelemetry.sdk.metrics import MeterProvider
|
|
7
|
+
from opentelemetry.sdk.metrics.export import (
|
|
8
|
+
ConsoleMetricExporter,
|
|
9
|
+
MetricReader,
|
|
10
|
+
PeriodicExportingMetricReader,
|
|
11
|
+
)
|
|
12
|
+
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
|
|
13
|
+
from opentelemetry.sdk.trace import TracerProvider
|
|
14
|
+
from opentelemetry.sdk.trace.export import (
|
|
15
|
+
ConsoleSpanExporter,
|
|
16
|
+
SimpleSpanProcessor,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
TraceExporterType = Literal["otlp", "jaeger", "zipkin", "console"]
|
|
20
|
+
MetricExporterType = Literal["otlp", "prometheus", "none"]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class OtelSettings(TypedDict):
|
|
24
|
+
service_name: str
|
|
25
|
+
trace_exporters: list[TraceExporterType]
|
|
26
|
+
metric_exporters: list[MetricExporterType]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def get_settings() -> OtelSettings:
|
|
30
|
+
service_name = os.environ.get(OTEL_SERVICE_NAME, "unknown_service")
|
|
31
|
+
trace_exporters = os.environ.get(OTEL_TRACES_EXPORTER)
|
|
32
|
+
trace_exporters = trace_exporters.split(",") if trace_exporters else []
|
|
33
|
+
|
|
34
|
+
metric_exporters = os.environ.get(OTEL_METRICS_EXPORTER)
|
|
35
|
+
metric_exporters = metric_exporters.split(",") if metric_exporters else []
|
|
36
|
+
return OtelSettings(
|
|
37
|
+
service_name=service_name,
|
|
38
|
+
trace_exporters=trace_exporters,
|
|
39
|
+
metric_exporters=metric_exporters,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def get_trace_provider() -> TracerProvider:
|
|
44
|
+
settings = get_settings()
|
|
45
|
+
print(settings)
|
|
46
|
+
provider = TracerProvider(resource=Resource({SERVICE_NAME: settings["service_name"]}))
|
|
47
|
+
|
|
48
|
+
for trace_exporter_type in settings["trace_exporters"]:
|
|
49
|
+
_add_trace_exporter(exporter_type=trace_exporter_type, provider=provider)
|
|
50
|
+
|
|
51
|
+
return provider
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def get_metric_provider() -> MeterProvider:
|
|
55
|
+
settings = get_settings()
|
|
56
|
+
readers = []
|
|
57
|
+
for metric_exporter_type in settings["metric_exporters"]:
|
|
58
|
+
readers.append(_get_metrics_reader(exporter_type=metric_exporter_type))
|
|
59
|
+
return MeterProvider(
|
|
60
|
+
resource=Resource({SERVICE_NAME: settings["service_name"]}), metric_readers=readers
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _add_trace_exporter(exporter_type: TraceExporterType, provider: TracerProvider):
|
|
65
|
+
if exporter_type == "otlp":
|
|
66
|
+
_add_traces_otlp_exporter(
|
|
67
|
+
provider,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
elif exporter_type == "console":
|
|
71
|
+
_add_traces_console_exporter(provider)
|
|
72
|
+
else:
|
|
73
|
+
raise NotImplementedError(f"{exporter_type} implementation not supported yet")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _get_metrics_reader(exporter_type: MetricExporterType) -> MetricReader:
|
|
77
|
+
if exporter_type == "otlp":
|
|
78
|
+
return _get_metric_otlp_reader()
|
|
79
|
+
if exporter_type == "console":
|
|
80
|
+
return _get_metric_console_reader()
|
|
81
|
+
raise NotImplementedError(f"{exporter_type} implementation not supported yet")
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _add_traces_console_exporter(provider: TracerProvider) -> None:
|
|
85
|
+
exporter = ConsoleSpanExporter()
|
|
86
|
+
processor = SimpleSpanProcessor(exporter)
|
|
87
|
+
provider.add_span_processor(processor)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _add_traces_otlp_exporter(provider: TracerProvider) -> None:
|
|
91
|
+
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
|
|
92
|
+
|
|
93
|
+
exporter = OTLPSpanExporter()
|
|
94
|
+
processor = SimpleSpanProcessor(exporter)
|
|
95
|
+
provider.add_span_processor(processor)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _get_metric_otlp_reader() -> MetricReader:
|
|
99
|
+
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter
|
|
100
|
+
|
|
101
|
+
exporter = OTLPMetricExporter()
|
|
102
|
+
return PeriodicExportingMetricReader(exporter)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _get_metric_console_reader() -> MetricReader:
|
|
106
|
+
exporter = ConsoleMetricExporter()
|
|
107
|
+
return PeriodicExportingMetricReader(exporter)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import inspect
|
|
2
2
|
from dataclasses import is_dataclass
|
|
3
3
|
from enum import EnumMeta
|
|
4
|
+
from inspect import Parameter
|
|
4
5
|
from types import GenericAlias, NoneType
|
|
5
6
|
from typing import Any, Callable, Optional
|
|
6
7
|
|
|
@@ -58,6 +59,10 @@ def get_input_schema(func: Callable, omit: Optional[list[str]] = None) -> dict:
|
|
|
58
59
|
parameters = get_typed_parameters(func)
|
|
59
60
|
if omit:
|
|
60
61
|
parameters = [p for p in parameters if p.name not in omit]
|
|
62
|
+
# Omit self if wrapping method
|
|
63
|
+
parameters = [
|
|
64
|
+
p for p in parameters if not (p.param_type is Parameter.empty and p.name == "self")
|
|
65
|
+
]
|
|
61
66
|
return parameters_to_json_schema(parameters)
|
|
62
67
|
|
|
63
68
|
|
|
@@ -4,11 +4,11 @@ from enum import Enum, EnumMeta
|
|
|
4
4
|
from inspect import Parameter
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
from types import GenericAlias, NoneType, UnionType
|
|
7
|
-
from typing import Any, Optional, Type, Union, _UnionGenericAlias
|
|
7
|
+
from typing import Any, Literal, Optional, Type, Union, _UnionGenericAlias
|
|
8
8
|
|
|
9
9
|
from pydantic import BaseModel, create_model
|
|
10
10
|
from pydantic.fields import FieldInfo, PydanticUndefined
|
|
11
|
-
from
|
|
11
|
+
from unstructured_ingest.v2.interfaces import FileData
|
|
12
12
|
|
|
13
13
|
from unstructured_platform_plugins.schema.utils import TypedParameter
|
|
14
14
|
from unstructured_platform_plugins.type_hints import get_type_hints
|
|
@@ -37,6 +37,13 @@ def is_typed_dict(val: Any) -> bool:
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
def type_to_json_schema(t: Type, args: Optional[tuple[Any, ...]] = None) -> dict:
|
|
40
|
+
if t is Literal:
|
|
41
|
+
arg_types = [type(a) for a in args]
|
|
42
|
+
if len(set(arg_types)) != 1:
|
|
43
|
+
raise TypeError(
|
|
44
|
+
"Literal must be of a single type. Defined with: {}".format(", ".join(arg_types))
|
|
45
|
+
)
|
|
46
|
+
t = arg_types[0]
|
|
40
47
|
resp = {"type": types_map[t]}
|
|
41
48
|
if t is list and args:
|
|
42
49
|
list_type = args[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.3
|
|
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
|
|
@@ -31,6 +31,7 @@ unstructured_platform_plugins.egg-info/top_level.txt
|
|
|
31
31
|
unstructured_platform_plugins/etl_uvicorn/__init__.py
|
|
32
32
|
unstructured_platform_plugins/etl_uvicorn/api_generator.py
|
|
33
33
|
unstructured_platform_plugins/etl_uvicorn/main.py
|
|
34
|
+
unstructured_platform_plugins/etl_uvicorn/otel.py
|
|
34
35
|
unstructured_platform_plugins/etl_uvicorn/utils.py
|
|
35
36
|
unstructured_platform_plugins/schema/__init__.py
|
|
36
37
|
unstructured_platform_plugins/schema/json_schema.py
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.0.1" # 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.1 → unstructured-platform-plugins-0.0.3}/test/__init__.py
RENAMED
|
File without changes
|
{unstructured-platform-plugins-0.0.1 → unstructured-platform-plugins-0.0.3}/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
|
|
File without changes
|