agenta 0.57.0__py3-none-any.whl → 0.63.2__py3-none-any.whl
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.
- agenta/__init__.py +12 -3
- agenta/client/__init__.py +4 -4
- agenta/client/backend/__init__.py +4 -4
- agenta/client/backend/api_keys/client.py +2 -2
- agenta/client/backend/billing/client.py +2 -2
- agenta/client/backend/billing/raw_client.py +2 -2
- agenta/client/backend/client.py +56 -48
- agenta/client/backend/core/client_wrapper.py +2 -2
- agenta/client/backend/core/file.py +3 -1
- agenta/client/backend/core/http_client.py +3 -3
- agenta/client/backend/core/pydantic_utilities.py +13 -3
- agenta/client/backend/human_evaluations/client.py +2 -2
- agenta/client/backend/human_evaluations/raw_client.py +2 -2
- agenta/client/backend/organization/client.py +46 -34
- agenta/client/backend/organization/raw_client.py +32 -26
- agenta/client/backend/raw_client.py +26 -26
- agenta/client/backend/testsets/client.py +18 -18
- agenta/client/backend/testsets/raw_client.py +30 -30
- agenta/client/backend/types/__init__.py +4 -4
- agenta/client/backend/types/account_request.py +3 -1
- agenta/client/backend/types/account_response.py +3 -1
- agenta/client/backend/types/agenta_node_dto.py +3 -1
- agenta/client/backend/types/agenta_nodes_response.py +3 -1
- agenta/client/backend/types/agenta_root_dto.py +3 -1
- agenta/client/backend/types/agenta_roots_response.py +3 -1
- agenta/client/backend/types/agenta_tree_dto.py +3 -1
- agenta/client/backend/types/agenta_trees_response.py +3 -1
- agenta/client/backend/types/aggregated_result.py +3 -1
- agenta/client/backend/types/analytics_response.py +3 -1
- agenta/client/backend/types/annotation.py +6 -4
- agenta/client/backend/types/annotation_create.py +3 -1
- agenta/client/backend/types/annotation_edit.py +3 -1
- agenta/client/backend/types/annotation_link.py +3 -1
- agenta/client/backend/types/annotation_link_response.py +3 -1
- agenta/client/backend/types/annotation_query.py +3 -1
- agenta/client/backend/types/annotation_query_request.py +3 -1
- agenta/client/backend/types/annotation_reference.py +3 -1
- agenta/client/backend/types/annotation_references.py +3 -1
- agenta/client/backend/types/annotation_response.py +3 -1
- agenta/client/backend/types/annotations_response.py +3 -1
- agenta/client/backend/types/app.py +3 -1
- agenta/client/backend/types/app_variant_response.py +3 -1
- agenta/client/backend/types/app_variant_revision.py +3 -1
- agenta/client/backend/types/artifact.py +6 -4
- agenta/client/backend/types/base_output.py +3 -1
- agenta/client/backend/types/body_fetch_workflow_revision.py +3 -1
- agenta/client/backend/types/body_import_testset.py +3 -1
- agenta/client/backend/types/bucket_dto.py +3 -1
- agenta/client/backend/types/collect_status_response.py +3 -1
- agenta/client/backend/types/config_db.py +3 -1
- agenta/client/backend/types/config_dto.py +3 -1
- agenta/client/backend/types/config_response_model.py +3 -1
- agenta/client/backend/types/correct_answer.py +3 -1
- agenta/client/backend/types/create_app_output.py +3 -1
- agenta/client/backend/types/custom_model_settings_dto.py +3 -1
- agenta/client/backend/types/custom_provider_dto.py +3 -1
- agenta/client/backend/types/custom_provider_kind.py +1 -1
- agenta/client/backend/types/custom_provider_settings_dto.py +3 -1
- agenta/client/backend/types/delete_evaluation.py +3 -1
- agenta/client/backend/types/environment_output.py +3 -1
- agenta/client/backend/types/environment_output_extended.py +3 -1
- agenta/client/backend/types/environment_revision.py +3 -1
- agenta/client/backend/types/error.py +3 -1
- agenta/client/backend/types/evaluation.py +3 -1
- agenta/client/backend/types/evaluation_scenario.py +3 -1
- agenta/client/backend/types/evaluation_scenario_input.py +3 -1
- agenta/client/backend/types/evaluation_scenario_output.py +3 -1
- agenta/client/backend/types/evaluation_scenario_result.py +3 -1
- agenta/client/backend/types/evaluator.py +6 -4
- agenta/client/backend/types/evaluator_config.py +6 -4
- agenta/client/backend/types/evaluator_flags.py +3 -1
- agenta/client/backend/types/evaluator_mapping_output_interface.py +3 -1
- agenta/client/backend/types/evaluator_output_interface.py +3 -1
- agenta/client/backend/types/evaluator_query.py +3 -1
- agenta/client/backend/types/evaluator_query_request.py +3 -1
- agenta/client/backend/types/evaluator_request.py +3 -1
- agenta/client/backend/types/evaluator_response.py +3 -1
- agenta/client/backend/types/evaluators_response.py +3 -1
- agenta/client/backend/types/exception_dto.py +3 -1
- agenta/client/backend/types/extended_o_tel_tracing_response.py +3 -1
- agenta/client/backend/types/get_config_response.py +3 -1
- agenta/client/backend/types/header.py +3 -1
- agenta/client/backend/types/http_validation_error.py +3 -1
- agenta/client/backend/types/human_evaluation.py +3 -1
- agenta/client/backend/types/human_evaluation_scenario.py +3 -1
- agenta/client/backend/types/human_evaluation_scenario_input.py +3 -1
- agenta/client/backend/types/human_evaluation_scenario_output.py +3 -1
- agenta/client/backend/types/invite_request.py +3 -1
- agenta/client/backend/types/legacy_analytics_response.py +3 -1
- agenta/client/backend/types/legacy_data_point.py +3 -1
- agenta/client/backend/types/legacy_evaluator.py +3 -1
- agenta/client/backend/types/legacy_scope_request.py +3 -1
- agenta/client/backend/types/legacy_scopes_response.py +3 -1
- agenta/client/backend/types/legacy_subscription_request.py +3 -1
- agenta/client/backend/types/legacy_user_request.py +3 -1
- agenta/client/backend/types/legacy_user_response.py +3 -1
- agenta/client/backend/types/lifecycle_dto.py +3 -1
- agenta/client/backend/types/link_dto.py +3 -1
- agenta/client/backend/types/list_api_keys_response.py +3 -1
- agenta/client/backend/types/llm_run_rate_limit.py +3 -1
- agenta/client/backend/types/meta_request.py +3 -1
- agenta/client/backend/types/metrics_dto.py +3 -1
- agenta/client/backend/types/new_testset.py +3 -1
- agenta/client/backend/types/node_dto.py +3 -1
- agenta/client/backend/types/o_tel_context_dto.py +3 -1
- agenta/client/backend/types/o_tel_event.py +6 -4
- agenta/client/backend/types/o_tel_event_dto.py +3 -1
- agenta/client/backend/types/o_tel_extra_dto.py +3 -1
- agenta/client/backend/types/o_tel_flat_span.py +6 -4
- agenta/client/backend/types/o_tel_link.py +6 -4
- agenta/client/backend/types/o_tel_link_dto.py +3 -1
- agenta/client/backend/types/o_tel_links_response.py +3 -1
- agenta/client/backend/types/o_tel_span.py +1 -1
- agenta/client/backend/types/o_tel_span_dto.py +3 -1
- agenta/client/backend/types/o_tel_spans_tree.py +3 -1
- agenta/client/backend/types/o_tel_tracing_data_response.py +3 -1
- agenta/client/backend/types/o_tel_tracing_request.py +3 -1
- agenta/client/backend/types/o_tel_tracing_response.py +3 -1
- agenta/client/backend/types/organization.py +3 -1
- agenta/client/backend/types/organization_details.py +3 -1
- agenta/client/backend/types/organization_membership_request.py +3 -1
- agenta/client/backend/types/organization_output.py +3 -1
- agenta/client/backend/types/organization_request.py +3 -1
- agenta/client/backend/types/parent_dto.py +3 -1
- agenta/client/backend/types/project_membership_request.py +3 -1
- agenta/client/backend/types/project_request.py +3 -1
- agenta/client/backend/types/project_scope.py +3 -1
- agenta/client/backend/types/projects_response.py +3 -1
- agenta/client/backend/types/reference.py +6 -4
- agenta/client/backend/types/reference_dto.py +3 -1
- agenta/client/backend/types/reference_request_model.py +3 -1
- agenta/client/backend/types/result.py +3 -1
- agenta/client/backend/types/root_dto.py +3 -1
- agenta/client/backend/types/scopes_response_model.py +3 -1
- agenta/client/backend/types/secret_dto.py +3 -1
- agenta/client/backend/types/secret_response_dto.py +3 -1
- agenta/client/backend/types/simple_evaluation_output.py +3 -1
- agenta/client/backend/types/span_dto.py +6 -4
- agenta/client/backend/types/standard_provider_dto.py +3 -1
- agenta/client/backend/types/standard_provider_settings_dto.py +3 -1
- agenta/client/backend/types/status_dto.py +3 -1
- agenta/client/backend/types/tags_request.py +3 -1
- agenta/client/backend/types/testcase_response.py +6 -4
- agenta/client/backend/types/testset.py +6 -4
- agenta/client/backend/types/{test_set_output_response.py → testset_output_response.py} +4 -2
- agenta/client/backend/types/testset_request.py +3 -1
- agenta/client/backend/types/testset_response.py +3 -1
- agenta/client/backend/types/{test_set_simple_response.py → testset_simple_response.py} +4 -2
- agenta/client/backend/types/testsets_response.py +3 -1
- agenta/client/backend/types/time_dto.py +3 -1
- agenta/client/backend/types/tree_dto.py +3 -1
- agenta/client/backend/types/update_app_output.py +3 -1
- agenta/client/backend/types/user_request.py +3 -1
- agenta/client/backend/types/validation_error.py +3 -1
- agenta/client/backend/types/workflow_artifact.py +6 -4
- agenta/client/backend/types/workflow_data.py +3 -1
- agenta/client/backend/types/workflow_flags.py +3 -1
- agenta/client/backend/types/workflow_request.py +3 -1
- agenta/client/backend/types/workflow_response.py +3 -1
- agenta/client/backend/types/workflow_revision.py +6 -4
- agenta/client/backend/types/workflow_revision_request.py +3 -1
- agenta/client/backend/types/workflow_revision_response.py +3 -1
- agenta/client/backend/types/workflow_revisions_response.py +3 -1
- agenta/client/backend/types/workflow_variant.py +6 -4
- agenta/client/backend/types/workflow_variant_request.py +3 -1
- agenta/client/backend/types/workflow_variant_response.py +3 -1
- agenta/client/backend/types/workflow_variants_response.py +3 -1
- agenta/client/backend/types/workflows_response.py +3 -1
- agenta/client/backend/types/workspace.py +3 -1
- agenta/client/backend/types/workspace_member_response.py +3 -1
- agenta/client/backend/types/workspace_membership_request.py +3 -1
- agenta/client/backend/types/workspace_permission.py +3 -1
- agenta/client/backend/types/workspace_request.py +3 -1
- agenta/client/backend/types/workspace_response.py +3 -1
- agenta/client/backend/workspace/client.py +2 -2
- agenta/client/client.py +102 -88
- agenta/sdk/__init__.py +52 -3
- agenta/sdk/agenta_init.py +43 -16
- agenta/sdk/assets.py +22 -15
- agenta/sdk/context/serving.py +20 -8
- agenta/sdk/context/tracing.py +40 -22
- agenta/sdk/contexts/__init__.py +0 -0
- agenta/sdk/contexts/routing.py +38 -0
- agenta/sdk/contexts/running.py +57 -0
- agenta/sdk/contexts/tracing.py +86 -0
- agenta/sdk/decorators/__init__.py +1 -0
- agenta/sdk/decorators/routing.py +284 -0
- agenta/sdk/decorators/running.py +692 -98
- agenta/sdk/decorators/serving.py +20 -21
- agenta/sdk/decorators/tracing.py +176 -131
- agenta/sdk/engines/__init__.py +0 -0
- agenta/sdk/engines/running/__init__.py +0 -0
- agenta/sdk/engines/running/utils.py +17 -0
- agenta/sdk/engines/tracing/__init__.py +1 -0
- agenta/sdk/engines/tracing/attributes.py +185 -0
- agenta/sdk/engines/tracing/conventions.py +49 -0
- agenta/sdk/engines/tracing/exporters.py +130 -0
- agenta/sdk/engines/tracing/inline.py +1154 -0
- agenta/sdk/engines/tracing/processors.py +190 -0
- agenta/sdk/engines/tracing/propagation.py +102 -0
- agenta/sdk/engines/tracing/spans.py +136 -0
- agenta/sdk/engines/tracing/tracing.py +324 -0
- agenta/sdk/evaluations/__init__.py +2 -0
- agenta/sdk/evaluations/metrics.py +37 -0
- agenta/sdk/evaluations/preview/__init__.py +0 -0
- agenta/sdk/evaluations/preview/evaluate.py +765 -0
- agenta/sdk/evaluations/preview/utils.py +861 -0
- agenta/sdk/evaluations/results.py +66 -0
- agenta/sdk/evaluations/runs.py +153 -0
- agenta/sdk/evaluations/scenarios.py +48 -0
- agenta/sdk/litellm/litellm.py +12 -0
- agenta/sdk/litellm/mockllm.py +6 -8
- agenta/sdk/litellm/mocks/__init__.py +5 -5
- agenta/sdk/managers/applications.py +304 -0
- agenta/sdk/managers/config.py +2 -2
- agenta/sdk/managers/evaluations.py +0 -0
- agenta/sdk/managers/evaluators.py +303 -0
- agenta/sdk/managers/secrets.py +161 -24
- agenta/sdk/managers/shared.py +3 -1
- agenta/sdk/managers/testsets.py +441 -0
- agenta/sdk/managers/vault.py +3 -3
- agenta/sdk/middleware/auth.py +0 -176
- agenta/sdk/middleware/vault.py +203 -8
- agenta/sdk/middlewares/__init__.py +0 -0
- agenta/sdk/middlewares/routing/__init__.py +0 -0
- agenta/sdk/middlewares/routing/auth.py +263 -0
- agenta/sdk/middlewares/routing/cors.py +30 -0
- agenta/sdk/middlewares/routing/otel.py +29 -0
- agenta/sdk/middlewares/running/__init__.py +0 -0
- agenta/sdk/middlewares/running/normalizer.py +321 -0
- agenta/sdk/middlewares/running/resolver.py +161 -0
- agenta/sdk/middlewares/running/vault.py +140 -0
- agenta/sdk/models/__init__.py +0 -0
- agenta/sdk/models/blobs.py +33 -0
- agenta/sdk/models/evaluations.py +119 -0
- agenta/sdk/models/git.py +126 -0
- agenta/sdk/models/shared.py +167 -0
- agenta/sdk/models/testsets.py +163 -0
- agenta/sdk/models/tracing.py +202 -0
- agenta/sdk/models/workflows.py +753 -0
- agenta/sdk/tracing/exporters.py +67 -17
- agenta/sdk/tracing/processors.py +97 -0
- agenta/sdk/tracing/propagation.py +3 -1
- agenta/sdk/tracing/spans.py +4 -0
- agenta/sdk/tracing/tracing.py +13 -13
- agenta/sdk/types.py +211 -17
- agenta/sdk/utils/cache.py +1 -1
- agenta/sdk/utils/client.py +38 -0
- agenta/sdk/utils/helpers.py +13 -12
- agenta/sdk/utils/logging.py +18 -78
- agenta/sdk/utils/references.py +23 -0
- agenta/sdk/workflows/builtin.py +600 -0
- agenta/sdk/workflows/configurations.py +22 -0
- agenta/sdk/workflows/errors.py +292 -0
- agenta/sdk/workflows/handlers.py +1791 -0
- agenta/sdk/workflows/interfaces.py +948 -0
- agenta/sdk/workflows/sandbox.py +118 -0
- agenta/sdk/workflows/utils.py +303 -6
- {agenta-0.57.0.dist-info → agenta-0.63.2.dist-info}/METADATA +33 -30
- agenta-0.63.2.dist-info/RECORD +421 -0
- agenta/sdk/middleware/adapt.py +0 -253
- agenta/sdk/middleware/base.py +0 -40
- agenta/sdk/middleware/flags.py +0 -40
- agenta/sdk/workflows/types.py +0 -472
- agenta-0.57.0.dist-info/RECORD +0 -371
- /agenta/sdk/{workflows → engines/running}/registry.py +0 -0
- {agenta-0.57.0.dist-info → agenta-0.63.2.dist-info}/WHEEL +0 -0
agenta/sdk/middleware/adapt.py
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
from typing import Callable
|
|
2
|
-
from inspect import signature
|
|
3
|
-
from uuid import uuid4
|
|
4
|
-
|
|
5
|
-
from agenta.sdk.utils.logging import get_module_logger
|
|
6
|
-
|
|
7
|
-
from agenta.sdk.middleware.base import (
|
|
8
|
-
WorkflowMiddleware,
|
|
9
|
-
middleware_as_decorator,
|
|
10
|
-
)
|
|
11
|
-
from agenta.sdk.workflows.types import (
|
|
12
|
-
WorkflowServiceRequest,
|
|
13
|
-
WorkflowServiceResponse,
|
|
14
|
-
WorkflowServiceData,
|
|
15
|
-
WorkflowRevision,
|
|
16
|
-
Status,
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
log = get_module_logger(__name__)
|
|
20
|
-
|
|
21
|
-
DEFAULT_INPUTS_MAPPINGS = {
|
|
22
|
-
"request": "request",
|
|
23
|
-
"revision": "revision",
|
|
24
|
-
"parameters": "revision.data.parameters",
|
|
25
|
-
"inputs": "request.data.inputs",
|
|
26
|
-
"outputs": "request.data.traces.0.attributes.ag.data.outputs",
|
|
27
|
-
"trace": "request.data.traces.0",
|
|
28
|
-
"trace_outputs": "request.data.traces.0.attributes.ag.data.outputs",
|
|
29
|
-
"traces": "request.data.traces",
|
|
30
|
-
"traces_outputs": "request.data.traces.{}.attributes.ag.data.outputs",
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
ALLOWED_INPUTS_KEYS = set(DEFAULT_INPUTS_MAPPINGS.keys())
|
|
34
|
-
|
|
35
|
-
ALLOWED_OUTPUTS_KEYS = {
|
|
36
|
-
"outputs",
|
|
37
|
-
"trace",
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
DEFAULT_MAPPINGS = {}
|
|
41
|
-
|
|
42
|
-
CURRENT_VERSION = "2025.07.14"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
@middleware_as_decorator
|
|
46
|
-
class AdaptMiddleware(WorkflowMiddleware):
|
|
47
|
-
def __init__(self):
|
|
48
|
-
pass
|
|
49
|
-
|
|
50
|
-
async def __call__(
|
|
51
|
-
self,
|
|
52
|
-
request: WorkflowServiceRequest,
|
|
53
|
-
revision: WorkflowRevision,
|
|
54
|
-
handler: Callable,
|
|
55
|
-
) -> WorkflowServiceResponse:
|
|
56
|
-
request_data_dict = request.data.model_dump(
|
|
57
|
-
mode="json",
|
|
58
|
-
exclude_none=True,
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
revision_data_dict = revision.data.model_dump(
|
|
62
|
-
mode="json",
|
|
63
|
-
exclude_none=True,
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
provided_request_keys = sorted(
|
|
67
|
-
{"request", "revision", "parameters"} | set(request_data_dict.keys())
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
handler_signature = signature(handler)
|
|
71
|
-
|
|
72
|
-
requested_inputs_keys = sorted(set(handler_signature.parameters.keys()))
|
|
73
|
-
|
|
74
|
-
kwargs = dict()
|
|
75
|
-
|
|
76
|
-
try:
|
|
77
|
-
for requested_input_key in requested_inputs_keys:
|
|
78
|
-
if requested_input_key not in ALLOWED_INPUTS_KEYS:
|
|
79
|
-
kwargs[requested_input_key] = None
|
|
80
|
-
continue
|
|
81
|
-
|
|
82
|
-
if requested_input_key in provided_request_keys:
|
|
83
|
-
if requested_input_key == "parameters":
|
|
84
|
-
kwargs[requested_input_key] = (
|
|
85
|
-
revision.data.parameters
|
|
86
|
-
if revision.data.parameters
|
|
87
|
-
else None
|
|
88
|
-
)
|
|
89
|
-
elif requested_input_key == "request":
|
|
90
|
-
kwargs[requested_input_key] = request
|
|
91
|
-
elif requested_input_key == "revision":
|
|
92
|
-
kwargs[requested_input_key] = revision
|
|
93
|
-
else:
|
|
94
|
-
kwargs[requested_input_key] = request_data_dict[
|
|
95
|
-
requested_input_key
|
|
96
|
-
]
|
|
97
|
-
|
|
98
|
-
else:
|
|
99
|
-
kwargs[requested_input_key] = self._apply_request_mapping(
|
|
100
|
-
request=request_data_dict,
|
|
101
|
-
revision=revision_data_dict,
|
|
102
|
-
key=requested_input_key,
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
except: # pylint: disable=bare-except
|
|
106
|
-
# handle the error
|
|
107
|
-
pass
|
|
108
|
-
|
|
109
|
-
try:
|
|
110
|
-
# inputs = kwargs.get("inputs", None)
|
|
111
|
-
|
|
112
|
-
# inputs_schema =
|
|
113
|
-
|
|
114
|
-
# self._check_request_schema(
|
|
115
|
-
# inputs,
|
|
116
|
-
# inputs_schema,
|
|
117
|
-
# )
|
|
118
|
-
|
|
119
|
-
# parameters = kwargs.get("parameters", None)
|
|
120
|
-
|
|
121
|
-
# parameters_schema =
|
|
122
|
-
|
|
123
|
-
# self._check_request_schema(
|
|
124
|
-
# parameters,
|
|
125
|
-
# parameters_schema,
|
|
126
|
-
# )
|
|
127
|
-
|
|
128
|
-
pass
|
|
129
|
-
|
|
130
|
-
except: # pylint: disable=bare-except
|
|
131
|
-
# handle the error
|
|
132
|
-
pass
|
|
133
|
-
|
|
134
|
-
try:
|
|
135
|
-
handler_signature.bind(**kwargs)
|
|
136
|
-
|
|
137
|
-
except: # pylint: disable=bare-except
|
|
138
|
-
# handle the error
|
|
139
|
-
pass
|
|
140
|
-
|
|
141
|
-
try:
|
|
142
|
-
outputs = await handler(**kwargs)
|
|
143
|
-
|
|
144
|
-
trace = None # get trace
|
|
145
|
-
|
|
146
|
-
except: # pylint: disable=bare-except
|
|
147
|
-
# handle the error
|
|
148
|
-
log.debug()
|
|
149
|
-
raise
|
|
150
|
-
|
|
151
|
-
try:
|
|
152
|
-
# outputs_schema =
|
|
153
|
-
|
|
154
|
-
# self._check_request_schema(
|
|
155
|
-
# outputs,
|
|
156
|
-
# outputs_schema,
|
|
157
|
-
# )
|
|
158
|
-
|
|
159
|
-
pass
|
|
160
|
-
|
|
161
|
-
except: # pylint: disable=bare-except
|
|
162
|
-
# handle the error
|
|
163
|
-
pass
|
|
164
|
-
|
|
165
|
-
return WorkflowServiceResponse(
|
|
166
|
-
id=uuid4(),
|
|
167
|
-
version=CURRENT_VERSION,
|
|
168
|
-
# status=Status(code=200, message="Success"),
|
|
169
|
-
data=WorkflowServiceData(
|
|
170
|
-
outputs=outputs,
|
|
171
|
-
trace=trace,
|
|
172
|
-
),
|
|
173
|
-
)
|
|
174
|
-
|
|
175
|
-
def _apply_request_mapping(
|
|
176
|
-
self,
|
|
177
|
-
request: dict,
|
|
178
|
-
revision: dict,
|
|
179
|
-
key: str,
|
|
180
|
-
):
|
|
181
|
-
mapping = DEFAULT_INPUTS_MAPPINGS[key]
|
|
182
|
-
|
|
183
|
-
parts = mapping.split(".")
|
|
184
|
-
|
|
185
|
-
base_part = parts.pop(0)
|
|
186
|
-
data_part = parts.pop(0)
|
|
187
|
-
|
|
188
|
-
base = (
|
|
189
|
-
request
|
|
190
|
-
if base_part == "request" and data_part == "data"
|
|
191
|
-
else (revision if base_part == "revision" and data_part == "data" else {})
|
|
192
|
-
)
|
|
193
|
-
|
|
194
|
-
scalar = True
|
|
195
|
-
is_list = False
|
|
196
|
-
is_dict = False
|
|
197
|
-
|
|
198
|
-
for part in parts:
|
|
199
|
-
_is_index = part.isdigit()
|
|
200
|
-
_is_list = part == "[]"
|
|
201
|
-
_is_dict = part == "{}"
|
|
202
|
-
|
|
203
|
-
_scalar = not (_is_list or _is_dict)
|
|
204
|
-
|
|
205
|
-
if not scalar and not _scalar:
|
|
206
|
-
# handle error once we start using mappings
|
|
207
|
-
pass
|
|
208
|
-
|
|
209
|
-
if _is_index:
|
|
210
|
-
if isinstance(base, list):
|
|
211
|
-
base = base[int(part)]
|
|
212
|
-
elif isinstance(base, dict):
|
|
213
|
-
base = base[list(base.keys())[int(part)]]
|
|
214
|
-
else:
|
|
215
|
-
# handle error once we start using mappings
|
|
216
|
-
pass
|
|
217
|
-
|
|
218
|
-
elif _is_list:
|
|
219
|
-
if not isinstance(base, list):
|
|
220
|
-
# handle error once we start using mappings
|
|
221
|
-
pass
|
|
222
|
-
elif _is_dict:
|
|
223
|
-
if not isinstance(base, dict):
|
|
224
|
-
# handle error once we start using mappings
|
|
225
|
-
pass
|
|
226
|
-
|
|
227
|
-
else:
|
|
228
|
-
if isinstance(base, dict):
|
|
229
|
-
if is_list:
|
|
230
|
-
base = [
|
|
231
|
-
(item.get(part, None) if isinstance(item, dict) else None)
|
|
232
|
-
for item in base
|
|
233
|
-
]
|
|
234
|
-
elif is_dict:
|
|
235
|
-
base = {
|
|
236
|
-
key: (
|
|
237
|
-
value.get(part, None)
|
|
238
|
-
if isinstance(value, dict)
|
|
239
|
-
else None
|
|
240
|
-
)
|
|
241
|
-
for key, value in base.items()
|
|
242
|
-
}
|
|
243
|
-
else:
|
|
244
|
-
base = base.get(part, None)
|
|
245
|
-
else:
|
|
246
|
-
# handle error once we start using mappings
|
|
247
|
-
pass
|
|
248
|
-
|
|
249
|
-
scalar = _scalar
|
|
250
|
-
is_list = _is_list
|
|
251
|
-
is_dict = _is_dict
|
|
252
|
-
|
|
253
|
-
return base
|
agenta/sdk/middleware/base.py
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
from typing import Protocol, Callable, Any, Union
|
|
2
|
-
|
|
3
|
-
from agenta.sdk.workflows.types import (
|
|
4
|
-
WorkflowServiceRequest,
|
|
5
|
-
WorkflowServiceResponse,
|
|
6
|
-
WorkflowRevision,
|
|
7
|
-
WorkflowServiceHandler,
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class WorkflowMiddleware(Protocol):
|
|
12
|
-
async def __call__(
|
|
13
|
-
self,
|
|
14
|
-
request: WorkflowServiceRequest,
|
|
15
|
-
revision: WorkflowRevision,
|
|
16
|
-
handler: Callable,
|
|
17
|
-
) -> Any:
|
|
18
|
-
...
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
WorkflowMiddlewareDecorator = Callable[[WorkflowServiceHandler], WorkflowServiceHandler]
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def middleware_as_decorator(
|
|
25
|
-
middleware: Union[WorkflowMiddleware, type[WorkflowMiddleware]],
|
|
26
|
-
) -> WorkflowMiddlewareDecorator:
|
|
27
|
-
middleware = middleware() if isinstance(middleware, type) else middleware
|
|
28
|
-
|
|
29
|
-
def decorator(
|
|
30
|
-
handler: WorkflowServiceHandler,
|
|
31
|
-
) -> WorkflowServiceHandler:
|
|
32
|
-
async def wrapped(
|
|
33
|
-
request: WorkflowServiceRequest,
|
|
34
|
-
revision: WorkflowRevision,
|
|
35
|
-
) -> WorkflowServiceResponse:
|
|
36
|
-
return await middleware(request, revision, handler)
|
|
37
|
-
|
|
38
|
-
return wrapped
|
|
39
|
-
|
|
40
|
-
return decorator
|
agenta/sdk/middleware/flags.py
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
from agenta.sdk.utils.logging import get_module_logger
|
|
2
|
-
|
|
3
|
-
from agenta.sdk.middleware.base import (
|
|
4
|
-
WorkflowMiddleware,
|
|
5
|
-
middleware_as_decorator,
|
|
6
|
-
)
|
|
7
|
-
from agenta.sdk.workflows.types import (
|
|
8
|
-
WorkflowServiceRequest,
|
|
9
|
-
WorkflowServiceResponse,
|
|
10
|
-
WorkflowRevision,
|
|
11
|
-
WorkflowServiceHandler,
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
from agenta.sdk.context.tracing import (
|
|
15
|
-
tracing_context_manager,
|
|
16
|
-
tracing_context,
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
log = get_module_logger(__name__)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
@middleware_as_decorator
|
|
24
|
-
class FlagsMiddleware(WorkflowMiddleware):
|
|
25
|
-
def __init__(self):
|
|
26
|
-
pass
|
|
27
|
-
|
|
28
|
-
async def __call__(
|
|
29
|
-
self,
|
|
30
|
-
request: WorkflowServiceRequest,
|
|
31
|
-
revision: WorkflowRevision,
|
|
32
|
-
handler: WorkflowServiceHandler,
|
|
33
|
-
) -> WorkflowServiceResponse:
|
|
34
|
-
ctx = tracing_context.get()
|
|
35
|
-
|
|
36
|
-
if isinstance(request.flags, dict) and request.flags.get("is_annotation"):
|
|
37
|
-
ctx.type = "annotation"
|
|
38
|
-
|
|
39
|
-
with tracing_context_manager(context=ctx):
|
|
40
|
-
return await handler(request, revision)
|