agenta 0.12.3__py3-none-any.whl → 0.32.0a1__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.
Potentially problematic release.
This version of agenta might be problematic. Click here for more details.
- agenta/__init__.py +64 -7
- agenta/cli/helper.py +7 -3
- agenta/cli/main.py +15 -50
- agenta/cli/variant_commands.py +50 -29
- agenta/client/Readme.md +72 -64
- agenta/client/api.py +2 -2
- agenta/client/backend/__init__.py +193 -22
- agenta/client/backend/access_control/__init__.py +1 -0
- agenta/client/backend/access_control/client.py +167 -0
- agenta/client/backend/apps/__init__.py +1 -0
- agenta/client/backend/apps/client.py +1691 -0
- agenta/client/backend/bases/__init__.py +1 -0
- agenta/client/backend/bases/client.py +190 -0
- agenta/client/backend/client.py +2508 -5712
- agenta/client/backend/configs/__init__.py +1 -0
- agenta/client/backend/configs/client.py +604 -0
- agenta/client/backend/containers/__init__.py +5 -0
- agenta/client/backend/containers/client.py +648 -0
- agenta/client/backend/containers/types/__init__.py +5 -0
- agenta/client/backend/{types → containers/types}/container_templates_response.py +1 -2
- agenta/client/backend/core/__init__.py +30 -0
- agenta/client/backend/core/client_wrapper.py +42 -9
- agenta/client/backend/core/file.py +70 -0
- agenta/client/backend/core/http_client.py +575 -0
- agenta/client/backend/core/jsonable_encoder.py +33 -39
- agenta/client/backend/core/pydantic_utilities.py +325 -0
- agenta/client/backend/core/query_encoder.py +60 -0
- agenta/client/backend/core/remove_none_from_dict.py +2 -2
- agenta/client/backend/core/request_options.py +35 -0
- agenta/client/backend/core/serialization.py +276 -0
- agenta/client/backend/environments/__init__.py +1 -0
- agenta/client/backend/environments/client.py +196 -0
- agenta/client/backend/evaluations/__init__.py +1 -0
- agenta/client/backend/evaluations/client.py +1469 -0
- agenta/client/backend/evaluators/__init__.py +1 -0
- agenta/client/backend/evaluators/client.py +1283 -0
- agenta/client/backend/observability/__init__.py +1 -0
- agenta/client/backend/observability/client.py +1286 -0
- agenta/client/backend/observability_v_1/__init__.py +5 -0
- agenta/client/backend/observability_v_1/client.py +763 -0
- agenta/client/backend/observability_v_1/types/__init__.py +7 -0
- agenta/client/backend/observability_v_1/types/format.py +5 -0
- agenta/client/backend/observability_v_1/types/query_analytics_response.py +7 -0
- agenta/client/backend/observability_v_1/types/query_traces_response.py +11 -0
- agenta/client/backend/scopes/__init__.py +1 -0
- agenta/client/backend/scopes/client.py +114 -0
- agenta/client/backend/testsets/__init__.py +1 -0
- agenta/client/backend/testsets/client.py +1284 -0
- agenta/client/backend/types/__init__.py +154 -26
- agenta/client/backend/types/agenta_node_dto.py +48 -0
- agenta/client/backend/types/agenta_node_dto_nodes_value.py +6 -0
- agenta/client/backend/types/agenta_nodes_response.py +30 -0
- agenta/client/backend/types/agenta_root_dto.py +30 -0
- agenta/client/backend/types/agenta_roots_response.py +30 -0
- agenta/client/backend/types/agenta_tree_dto.py +30 -0
- agenta/client/backend/types/agenta_trees_response.py +30 -0
- agenta/client/backend/types/aggregated_result.py +16 -31
- agenta/client/backend/types/aggregated_result_evaluator_config.py +8 -0
- agenta/client/backend/types/analytics_response.py +24 -0
- agenta/client/backend/types/app.py +17 -30
- agenta/client/backend/types/app_variant_response.py +36 -0
- agenta/client/backend/types/app_variant_revision.py +17 -32
- agenta/client/backend/types/base_output.py +13 -28
- agenta/client/backend/types/body_import_testset.py +15 -31
- agenta/client/backend/types/bucket_dto.py +26 -0
- agenta/client/backend/types/collect_status_response.py +22 -0
- agenta/client/backend/types/config_db.py +16 -31
- agenta/client/backend/types/config_dto.py +32 -0
- agenta/client/backend/types/config_response_model.py +32 -0
- agenta/client/backend/types/correct_answer.py +22 -0
- agenta/client/backend/types/create_app_output.py +13 -28
- agenta/client/backend/types/create_span.py +45 -0
- agenta/client/backend/types/create_trace_response.py +22 -0
- agenta/client/backend/types/docker_env_vars.py +13 -28
- agenta/client/backend/types/environment_output.py +22 -34
- agenta/client/backend/types/environment_output_extended.py +31 -0
- agenta/client/backend/types/environment_revision.py +26 -0
- agenta/client/backend/types/error.py +22 -0
- agenta/client/backend/types/evaluation.py +22 -33
- agenta/client/backend/types/evaluation_scenario.py +18 -33
- agenta/client/backend/types/evaluation_scenario_input.py +16 -31
- agenta/client/backend/types/evaluation_scenario_output.py +17 -30
- agenta/client/backend/types/evaluation_scenario_result.py +14 -29
- agenta/client/backend/types/evaluation_scenario_score_update.py +21 -0
- agenta/client/backend/types/evaluation_status_enum.py +11 -29
- agenta/client/backend/types/evaluation_type.py +3 -21
- agenta/client/backend/types/evaluator.py +20 -31
- agenta/client/backend/types/evaluator_config.py +21 -33
- agenta/client/backend/types/evaluator_mapping_output_interface.py +21 -0
- agenta/client/backend/types/evaluator_output_interface.py +21 -0
- agenta/client/backend/types/exception_dto.py +26 -0
- agenta/client/backend/types/get_config_response.py +23 -0
- agenta/client/backend/types/header_dto.py +22 -0
- agenta/client/backend/types/http_validation_error.py +14 -29
- agenta/client/backend/types/human_evaluation.py +18 -34
- agenta/client/backend/types/human_evaluation_scenario.py +22 -38
- agenta/client/backend/types/human_evaluation_scenario_input.py +13 -28
- agenta/client/backend/types/human_evaluation_scenario_output.py +13 -28
- agenta/client/backend/types/human_evaluation_scenario_update.py +30 -0
- agenta/client/backend/types/human_evaluation_update.py +22 -0
- agenta/client/backend/types/image.py +18 -32
- agenta/client/backend/types/invite_request.py +16 -30
- agenta/client/backend/types/legacy_analytics_response.py +29 -0
- agenta/client/backend/types/legacy_data_point.py +27 -0
- agenta/client/backend/types/lifecycle_dto.py +24 -0
- agenta/client/backend/types/link_dto.py +24 -0
- agenta/client/backend/types/list_api_keys_response.py +24 -0
- agenta/client/backend/types/llm_run_rate_limit.py +13 -28
- agenta/client/backend/types/llm_tokens.py +23 -0
- agenta/client/backend/types/metrics_dto.py +24 -0
- agenta/client/backend/types/new_human_evaluation.py +27 -0
- agenta/client/backend/types/new_testset.py +16 -31
- agenta/client/backend/types/node_dto.py +24 -0
- agenta/client/backend/types/node_type.py +19 -0
- agenta/client/backend/types/o_tel_context_dto.py +22 -0
- agenta/client/backend/types/o_tel_event_dto.py +23 -0
- agenta/client/backend/types/o_tel_extra_dto.py +26 -0
- agenta/client/backend/types/o_tel_link_dto.py +23 -0
- agenta/client/backend/types/o_tel_span_dto.py +37 -0
- agenta/client/backend/types/o_tel_span_kind.py +15 -0
- agenta/client/backend/types/o_tel_spans_response.py +24 -0
- agenta/client/backend/types/o_tel_status_code.py +8 -0
- agenta/client/backend/types/organization.py +22 -35
- agenta/client/backend/types/organization_output.py +13 -28
- agenta/client/backend/types/outputs.py +5 -0
- agenta/client/backend/types/parent_dto.py +21 -0
- agenta/client/backend/types/permission.py +41 -0
- agenta/client/backend/types/projects_response.py +28 -0
- agenta/client/backend/types/provider_key_dto.py +23 -0
- agenta/client/backend/types/provider_kind.py +21 -0
- agenta/client/backend/types/reference_dto.py +23 -0
- agenta/client/backend/types/reference_request_model.py +23 -0
- agenta/client/backend/types/result.py +18 -31
- agenta/client/backend/types/root_dto.py +21 -0
- agenta/client/backend/types/{human_evaluation_scenario_score.py → score.py} +1 -1
- agenta/client/backend/types/secret_dto.py +24 -0
- agenta/client/backend/types/{human_evaluation_scenario_update_score.py → secret_kind.py} +1 -1
- agenta/client/backend/types/secret_response_dto.py +27 -0
- agenta/client/backend/types/simple_evaluation_output.py +13 -28
- agenta/client/backend/types/span.py +39 -49
- agenta/client/backend/types/span_detail.py +44 -0
- agenta/client/backend/types/span_dto.py +54 -0
- agenta/client/backend/types/span_dto_nodes_value.py +9 -0
- agenta/client/backend/types/span_status_code.py +5 -0
- agenta/client/backend/types/span_variant.py +23 -0
- agenta/client/backend/types/status_code.py +5 -0
- agenta/client/backend/types/status_dto.py +23 -0
- agenta/client/backend/types/template.py +14 -29
- agenta/client/backend/types/template_image_info.py +21 -35
- agenta/client/backend/types/test_set_output_response.py +20 -33
- agenta/client/backend/types/test_set_simple_response.py +13 -28
- agenta/client/backend/types/time_dto.py +23 -0
- agenta/client/backend/types/trace_detail.py +44 -0
- agenta/client/backend/types/tree_dto.py +23 -0
- agenta/client/backend/types/tree_type.py +5 -0
- agenta/client/backend/types/update_app_output.py +22 -0
- agenta/client/backend/types/uri.py +13 -28
- agenta/client/backend/types/validation_error.py +13 -28
- agenta/client/backend/types/variant_action.py +14 -29
- agenta/client/backend/types/variant_action_enum.py +1 -19
- agenta/client/backend/types/with_pagination.py +26 -0
- agenta/client/backend/types/workspace_member_response.py +23 -0
- agenta/client/backend/types/workspace_permission.py +25 -0
- agenta/client/backend/types/workspace_response.py +29 -0
- agenta/client/backend/types/workspace_role.py +15 -0
- agenta/client/backend/types/workspace_role_response.py +23 -0
- agenta/client/backend/variants/__init__.py +5 -0
- agenta/client/backend/variants/client.py +2814 -0
- agenta/client/backend/variants/types/__init__.py +7 -0
- agenta/client/backend/variants/types/add_variant_from_base_and_config_response.py +8 -0
- agenta/client/backend/vault/__init__.py +1 -0
- agenta/client/backend/vault/client.py +685 -0
- agenta/client/client.py +1 -1
- agenta/config.py +0 -2
- agenta/config.toml +0 -1
- agenta/docker/docker-assets/Dockerfile.cloud.template +2 -1
- agenta/docker/docker-assets/Dockerfile.template +2 -1
- agenta/docker/docker_utils.py +11 -12
- agenta/sdk/__init__.py +58 -7
- agenta/sdk/agenta_init.py +182 -164
- agenta/sdk/assets.py +95 -0
- agenta/sdk/client.py +56 -0
- agenta/sdk/context/__init__.py +0 -0
- agenta/sdk/context/exporting.py +25 -0
- agenta/sdk/context/routing.py +27 -0
- agenta/sdk/context/tracing.py +28 -0
- agenta/sdk/decorators/__init__.py +0 -0
- agenta/sdk/decorators/routing.py +576 -0
- agenta/sdk/decorators/tracing.py +296 -0
- agenta/sdk/litellm/__init__.py +1 -0
- agenta/sdk/litellm/litellm.py +314 -0
- agenta/sdk/litellm/mockllm.py +27 -0
- agenta/sdk/litellm/mocks/__init__.py +26 -0
- agenta/sdk/managers/__init__.py +6 -0
- agenta/sdk/managers/config.py +208 -0
- agenta/sdk/managers/deployment.py +45 -0
- agenta/sdk/managers/secrets.py +38 -0
- agenta/sdk/managers/shared.py +639 -0
- agenta/sdk/managers/variant.py +182 -0
- agenta/sdk/managers/vault.py +16 -0
- agenta/sdk/middleware/__init__.py +0 -0
- agenta/sdk/middleware/auth.py +180 -0
- agenta/sdk/middleware/cache.py +47 -0
- agenta/sdk/middleware/config.py +255 -0
- agenta/sdk/middleware/cors.py +29 -0
- agenta/sdk/middleware/inline.py +38 -0
- agenta/sdk/middleware/mock.py +33 -0
- agenta/sdk/middleware/otel.py +40 -0
- agenta/sdk/middleware/vault.py +145 -0
- agenta/sdk/router.py +0 -7
- agenta/sdk/tracing/__init__.py +1 -0
- agenta/sdk/tracing/attributes.py +141 -0
- agenta/sdk/tracing/conventions.py +49 -0
- agenta/sdk/tracing/exporters.py +103 -0
- agenta/sdk/tracing/inline.py +1146 -0
- agenta/sdk/tracing/processors.py +121 -0
- agenta/sdk/tracing/spans.py +136 -0
- agenta/sdk/tracing/tracing.py +237 -0
- agenta/sdk/types.py +478 -74
- agenta/sdk/utils/__init__.py +0 -0
- agenta/sdk/utils/constants.py +1 -0
- agenta/sdk/utils/{helper/openai_cost.py → costs.py} +3 -0
- agenta/sdk/utils/exceptions.py +59 -0
- agenta/sdk/utils/globals.py +6 -10
- agenta/sdk/utils/helpers.py +8 -0
- agenta/sdk/utils/logging.py +21 -0
- agenta/sdk/utils/singleton.py +13 -0
- agenta/sdk/utils/timing.py +58 -0
- {agenta-0.12.3.dist-info → agenta-0.32.0a1.dist-info}/METADATA +98 -151
- agenta-0.32.0a1.dist-info/RECORD +263 -0
- {agenta-0.12.3.dist-info → agenta-0.32.0a1.dist-info}/WHEEL +1 -1
- agenta/client/backend/types/add_variant_from_base_and_config_response.py +0 -7
- agenta/client/backend/types/app_variant_output.py +0 -47
- agenta/client/backend/types/app_variant_output_extended.py +0 -50
- agenta/client/backend/types/delete_evaluation.py +0 -36
- agenta/client/backend/types/evaluation_webhook.py +0 -36
- agenta/client/backend/types/feedback.py +0 -40
- agenta/client/backend/types/get_config_reponse.py +0 -39
- agenta/client/backend/types/list_api_keys_output.py +0 -39
- agenta/client/backend/types/trace.py +0 -48
- agenta/sdk/agenta_decorator.py +0 -443
- agenta/sdk/context.py +0 -41
- agenta-0.12.3.dist-info/RECORD +0 -114
- {agenta-0.12.3.dist-info → agenta-0.32.0a1.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import logging
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Optional, Type, TypeVar, Dict, Any, Union
|
|
5
|
+
|
|
6
|
+
import yaml
|
|
7
|
+
from pydantic import BaseModel
|
|
8
|
+
|
|
9
|
+
from agenta.sdk.managers.shared import SharedManager
|
|
10
|
+
from agenta.sdk.context.routing import routing_context
|
|
11
|
+
|
|
12
|
+
T = TypeVar("T", bound=BaseModel)
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
AVAILABLE_ENVIRONMENTS = ["development", "production", "staging"]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ConfigManager:
|
|
20
|
+
@staticmethod
|
|
21
|
+
def get_from_route(
|
|
22
|
+
schema: Optional[Type[T]] = None,
|
|
23
|
+
) -> Optional[Union[Dict[str, Any], T]]:
|
|
24
|
+
"""
|
|
25
|
+
Retrieves the configuration from the route context and returns a config object.
|
|
26
|
+
|
|
27
|
+
This method checks the route context for configuration information and returns
|
|
28
|
+
an instance of the specified schema based on the available context data.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
schema (Type[T]): A Pydantic model class that defines the structure of the configuration.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
T: An instance of the specified schema populated with the configuration data.
|
|
35
|
+
|
|
36
|
+
Raises:
|
|
37
|
+
ValueError: If conflicting configuration sources are provided or if no valid
|
|
38
|
+
configuration source is found in the context.
|
|
39
|
+
|
|
40
|
+
Note:
|
|
41
|
+
The method prioritizes the inputs in the following way:
|
|
42
|
+
1. 'config' (i.e. when called explicitly from the playground)
|
|
43
|
+
2. 'environment'
|
|
44
|
+
3. 'variant'
|
|
45
|
+
Only one of these should be provided.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
context = routing_context.get()
|
|
49
|
+
|
|
50
|
+
parameters = context.parameters
|
|
51
|
+
|
|
52
|
+
if not parameters:
|
|
53
|
+
return None
|
|
54
|
+
|
|
55
|
+
if not schema:
|
|
56
|
+
return parameters
|
|
57
|
+
|
|
58
|
+
return schema(**parameters)
|
|
59
|
+
|
|
60
|
+
@staticmethod
|
|
61
|
+
def get_from_registry(
|
|
62
|
+
schema: Optional[Type[T]] = None,
|
|
63
|
+
#
|
|
64
|
+
app_id: Optional[str] = None,
|
|
65
|
+
app_slug: Optional[str] = None,
|
|
66
|
+
variant_id: Optional[str] = None,
|
|
67
|
+
variant_slug: Optional[str] = None,
|
|
68
|
+
variant_version: Optional[int] = None,
|
|
69
|
+
environment_id: Optional[str] = None,
|
|
70
|
+
environment_slug: Optional[str] = None,
|
|
71
|
+
environment_version: Optional[int] = None,
|
|
72
|
+
) -> Union[Dict[str, Any], T]:
|
|
73
|
+
"""
|
|
74
|
+
Pulls the parameters for the app variant from the server and returns a config object.
|
|
75
|
+
|
|
76
|
+
This method retrieves the configuration from the backend server based on the provided
|
|
77
|
+
environment or variant. It then validates and returns the configuration as an instance
|
|
78
|
+
of the specified schema.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
app_slug (str): The unique identifier for the application whose configuration is to be fetched.
|
|
82
|
+
variant_slug (Optional[str]): The variant name to fetch the configuration for. Defaults to None.
|
|
83
|
+
variant_version (Optional[int]): The version number of the variant to fetch. Defaults to None.
|
|
84
|
+
environment_slug (Optional[str]): The environment name to fetch the configuration for.
|
|
85
|
+
Must be one of "development", "production", or "staging". Defaults to None.
|
|
86
|
+
|
|
87
|
+
Raises:
|
|
88
|
+
Exception: For any other errors during the process (e.g., API communication issues).
|
|
89
|
+
"""
|
|
90
|
+
config = SharedManager.fetch(
|
|
91
|
+
app_id=app_id,
|
|
92
|
+
app_slug=app_slug,
|
|
93
|
+
variant_id=variant_id,
|
|
94
|
+
variant_slug=variant_slug,
|
|
95
|
+
variant_version=variant_version,
|
|
96
|
+
environment_id=environment_id,
|
|
97
|
+
environment_slug=environment_slug,
|
|
98
|
+
environment_version=environment_version,
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
if schema:
|
|
102
|
+
return schema(**config.params)
|
|
103
|
+
|
|
104
|
+
return config.params
|
|
105
|
+
|
|
106
|
+
@staticmethod
|
|
107
|
+
async def aget_from_registry(
|
|
108
|
+
schema: Optional[Type[T]] = None,
|
|
109
|
+
#
|
|
110
|
+
app_id: Optional[str] = None,
|
|
111
|
+
app_slug: Optional[str] = None,
|
|
112
|
+
variant_id: Optional[str] = None,
|
|
113
|
+
variant_slug: Optional[str] = None,
|
|
114
|
+
variant_version: Optional[int] = None,
|
|
115
|
+
environment_id: Optional[str] = None,
|
|
116
|
+
environment_slug: Optional[str] = None,
|
|
117
|
+
environment_version: Optional[int] = None,
|
|
118
|
+
) -> Union[Dict[str, Any], T]:
|
|
119
|
+
"""
|
|
120
|
+
Pulls the parameters for the app variant from the server and returns a config object.
|
|
121
|
+
|
|
122
|
+
This method retrieves the configuration from the backend server based on the provided
|
|
123
|
+
environment or variant. It then validates and returns the configuration as an instance
|
|
124
|
+
of the specified schema.
|
|
125
|
+
|
|
126
|
+
Args:
|
|
127
|
+
app_slug (str): The unique identifier for the application whose configuration is to be fetched.
|
|
128
|
+
variant_slug (Optional[str]): The variant name to fetch the configuration for. Defaults to None.
|
|
129
|
+
variant_version (Optional[int]): The version number of the variant to fetch. Defaults to None.
|
|
130
|
+
environment_slug (Optional[str]): The environment name to fetch the configuration for.
|
|
131
|
+
Must be one of "development", "production", or "staging". Defaults to None.
|
|
132
|
+
|
|
133
|
+
Raises:
|
|
134
|
+
Exception: For any other errors during the process (e.g., API communication issues).
|
|
135
|
+
"""
|
|
136
|
+
config = await SharedManager.afetch(
|
|
137
|
+
app_id=app_id,
|
|
138
|
+
app_slug=app_slug,
|
|
139
|
+
variant_id=variant_id,
|
|
140
|
+
variant_slug=variant_slug,
|
|
141
|
+
variant_version=variant_version,
|
|
142
|
+
environment_id=environment_id,
|
|
143
|
+
environment_slug=environment_slug,
|
|
144
|
+
environment_version=environment_version,
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
if schema:
|
|
148
|
+
return schema(**config.params)
|
|
149
|
+
|
|
150
|
+
return config.params
|
|
151
|
+
|
|
152
|
+
@staticmethod
|
|
153
|
+
def get_from_yaml(
|
|
154
|
+
filename: str,
|
|
155
|
+
schema: Optional[Type[T]] = None,
|
|
156
|
+
) -> T:
|
|
157
|
+
"""
|
|
158
|
+
Loads configuration from a YAML file and returns a config object.
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
filename (str): The name of the YAML file to load.
|
|
162
|
+
schema (Type[T]): A Pydantic model class that defines the structure of the configuration.
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
T: An instance of the specified schema populated with the configuration data.
|
|
166
|
+
|
|
167
|
+
Raises:
|
|
168
|
+
FileNotFoundError: If the specified file doesn't exist.
|
|
169
|
+
ValidationError: If the loaded configuration data doesn't match the schema.
|
|
170
|
+
"""
|
|
171
|
+
file_path = Path(filename)
|
|
172
|
+
|
|
173
|
+
with open(file_path, "r", encoding="utf-8") as file:
|
|
174
|
+
parameters = yaml.safe_load(file)
|
|
175
|
+
|
|
176
|
+
if schema:
|
|
177
|
+
return schema(**parameters)
|
|
178
|
+
|
|
179
|
+
return parameters
|
|
180
|
+
|
|
181
|
+
@staticmethod
|
|
182
|
+
def get_from_json(
|
|
183
|
+
filename: str,
|
|
184
|
+
schema: Optional[Type[T]] = None,
|
|
185
|
+
) -> T:
|
|
186
|
+
"""
|
|
187
|
+
Loads configuration from a JSON file and returns a config object.
|
|
188
|
+
|
|
189
|
+
Args:
|
|
190
|
+
filename (str): The name of the JSON file to load.
|
|
191
|
+
schema (Type[T]): A Pydantic model class that defines the structure of the configuration.
|
|
192
|
+
|
|
193
|
+
Returns:
|
|
194
|
+
T: An instance of the specified schema populated with the configuration data.
|
|
195
|
+
|
|
196
|
+
Raises:
|
|
197
|
+
FileNotFoundError: If the specified file doesn't exist.
|
|
198
|
+
ValidationError: If the loaded configuration data doesn't match the schema.
|
|
199
|
+
"""
|
|
200
|
+
file_path = Path(filename)
|
|
201
|
+
|
|
202
|
+
with open(file_path, "r", encoding="utf-8") as file:
|
|
203
|
+
parameters = json.load(file)
|
|
204
|
+
|
|
205
|
+
if schema:
|
|
206
|
+
return schema(**parameters)
|
|
207
|
+
|
|
208
|
+
return parameters
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from agenta.sdk.managers.shared import SharedManager
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class DeploymentManager:
|
|
7
|
+
@classmethod
|
|
8
|
+
def deploy(
|
|
9
|
+
cls,
|
|
10
|
+
*,
|
|
11
|
+
variant_slug: str,
|
|
12
|
+
environment_slug: str,
|
|
13
|
+
#
|
|
14
|
+
app_id: Optional[str] = None,
|
|
15
|
+
app_slug: Optional[str] = None,
|
|
16
|
+
variant_version: Optional[int] = None,
|
|
17
|
+
):
|
|
18
|
+
deployment = SharedManager.deploy(
|
|
19
|
+
app_id=app_id,
|
|
20
|
+
app_slug=app_slug,
|
|
21
|
+
variant_slug=variant_slug,
|
|
22
|
+
variant_version=variant_version,
|
|
23
|
+
environment_slug=environment_slug,
|
|
24
|
+
)
|
|
25
|
+
return deployment
|
|
26
|
+
|
|
27
|
+
@classmethod
|
|
28
|
+
async def adeploy(
|
|
29
|
+
cls,
|
|
30
|
+
*,
|
|
31
|
+
variant_slug: str,
|
|
32
|
+
environment_slug: str,
|
|
33
|
+
#
|
|
34
|
+
app_id: Optional[str] = None,
|
|
35
|
+
app_slug: Optional[str] = None,
|
|
36
|
+
variant_version: Optional[int] = None,
|
|
37
|
+
):
|
|
38
|
+
deployment = await SharedManager.adeploy(
|
|
39
|
+
app_id=app_id,
|
|
40
|
+
app_slug=app_slug,
|
|
41
|
+
variant_slug=variant_slug,
|
|
42
|
+
variant_version=variant_version,
|
|
43
|
+
environment_slug=environment_slug,
|
|
44
|
+
)
|
|
45
|
+
return deployment
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from typing import Optional, Dict, Any
|
|
2
|
+
|
|
3
|
+
from agenta.sdk.context.routing import routing_context
|
|
4
|
+
|
|
5
|
+
from agenta.sdk.assets import model_to_provider_mapping
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SecretsManager:
|
|
9
|
+
@staticmethod
|
|
10
|
+
def get_from_route() -> Optional[Dict[str, Any]]:
|
|
11
|
+
context = routing_context.get()
|
|
12
|
+
|
|
13
|
+
secrets = context.secrets
|
|
14
|
+
|
|
15
|
+
if not secrets:
|
|
16
|
+
return None
|
|
17
|
+
|
|
18
|
+
return secrets
|
|
19
|
+
|
|
20
|
+
@staticmethod
|
|
21
|
+
def get_api_key_for_model(model: str) -> str:
|
|
22
|
+
secrets = SecretsManager.get_from_route()
|
|
23
|
+
|
|
24
|
+
if not secrets:
|
|
25
|
+
return None
|
|
26
|
+
|
|
27
|
+
provider = model_to_provider_mapping.get(model)
|
|
28
|
+
|
|
29
|
+
if not provider:
|
|
30
|
+
return None
|
|
31
|
+
|
|
32
|
+
provider = provider.lower().replace(" ", "")
|
|
33
|
+
|
|
34
|
+
for secret in secrets:
|
|
35
|
+
if secret["data"]["provider"] == provider:
|
|
36
|
+
return secret["data"]["key"]
|
|
37
|
+
|
|
38
|
+
return None
|