agenta 0.27.0a9__py3-none-any.whl → 0.27.0a12__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 +21 -3
- agenta/client/backend/__init__.py +14 -0
- agenta/client/backend/apps/client.py +28 -20
- agenta/client/backend/client.py +25 -2
- agenta/client/backend/containers/client.py +5 -1
- agenta/client/backend/core/__init__.py +2 -1
- agenta/client/backend/core/client_wrapper.py +6 -6
- agenta/client/backend/core/file.py +33 -11
- agenta/client/backend/core/http_client.py +24 -18
- agenta/client/backend/core/pydantic_utilities.py +144 -29
- agenta/client/backend/core/request_options.py +3 -0
- agenta/client/backend/core/serialization.py +139 -42
- agenta/client/backend/evaluations/client.py +7 -2
- agenta/client/backend/evaluators/client.py +349 -1
- agenta/client/backend/observability/client.py +11 -2
- agenta/client/backend/testsets/client.py +10 -10
- agenta/client/backend/types/__init__.py +14 -0
- agenta/client/backend/types/app.py +1 -0
- agenta/client/backend/types/app_variant_response.py +3 -1
- agenta/client/backend/types/config_dto.py +32 -0
- agenta/client/backend/types/config_response_model.py +32 -0
- agenta/client/backend/types/create_span.py +3 -2
- agenta/client/backend/types/environment_output.py +1 -0
- agenta/client/backend/types/environment_output_extended.py +1 -0
- agenta/client/backend/types/evaluation.py +1 -2
- agenta/client/backend/types/evaluator.py +2 -0
- agenta/client/backend/types/evaluator_config.py +1 -0
- 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/human_evaluation.py +1 -2
- agenta/client/backend/types/lifecycle_dto.py +24 -0
- agenta/client/backend/types/llm_tokens.py +2 -2
- agenta/client/backend/types/reference_dto.py +23 -0
- agenta/client/backend/types/reference_request_model.py +23 -0
- agenta/client/backend/types/span.py +1 -0
- agenta/client/backend/types/span_detail.py +7 -1
- agenta/client/backend/types/test_set_output_response.py +5 -2
- agenta/client/backend/types/trace_detail.py +7 -1
- agenta/client/backend/types/with_pagination.py +4 -2
- agenta/client/backend/variants/client.py +1565 -272
- agenta/sdk/__init__.py +19 -5
- agenta/sdk/agenta_init.py +21 -7
- agenta/sdk/context/routing.py +6 -5
- agenta/sdk/decorators/routing.py +16 -5
- agenta/sdk/decorators/tracing.py +16 -9
- agenta/sdk/litellm/litellm.py +47 -36
- agenta/sdk/managers/__init__.py +6 -0
- agenta/sdk/managers/config.py +318 -0
- agenta/sdk/managers/deployment.py +45 -0
- agenta/sdk/managers/shared.py +639 -0
- agenta/sdk/managers/variant.py +182 -0
- agenta/sdk/tracing/exporters.py +0 -1
- agenta/sdk/tracing/inline.py +45 -0
- agenta/sdk/tracing/processors.py +0 -1
- agenta/sdk/types.py +47 -2
- agenta/sdk/utils/exceptions.py +31 -1
- {agenta-0.27.0a9.dist-info → agenta-0.27.0a12.dist-info}/METADATA +1 -1
- {agenta-0.27.0a9.dist-info → agenta-0.27.0a12.dist-info}/RECORD +60 -49
- agenta/sdk/config_manager.py +0 -205
- {agenta-0.27.0a9.dist-info → agenta-0.27.0a12.dist-info}/WHEEL +0 -0
- {agenta-0.27.0a9.dist-info → agenta-0.27.0a12.dist-info}/entry_points.txt +0 -0
agenta/sdk/config_manager.py
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import logging
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
from typing import Optional, Type, TypeVar
|
|
5
|
-
|
|
6
|
-
import yaml
|
|
7
|
-
from pydantic import BaseModel, ValidationError
|
|
8
|
-
|
|
9
|
-
from agenta.client.backend.client import AgentaApi
|
|
10
|
-
from agenta.sdk.context.routing import routing_context
|
|
11
|
-
|
|
12
|
-
from . import AgentaSingleton
|
|
13
|
-
|
|
14
|
-
T = TypeVar("T", bound=BaseModel)
|
|
15
|
-
|
|
16
|
-
logger = logging.getLogger(__name__)
|
|
17
|
-
singleton = AgentaSingleton()
|
|
18
|
-
|
|
19
|
-
AVAILABLE_ENVIRONMENTS = ["development", "production", "staging"]
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class ConfigManager:
|
|
23
|
-
client = None
|
|
24
|
-
|
|
25
|
-
@staticmethod
|
|
26
|
-
def get_from_route(schema: Type[T]) -> T:
|
|
27
|
-
"""
|
|
28
|
-
Retrieves the configuration from the route context and returns a config object.
|
|
29
|
-
|
|
30
|
-
This method checks the route context for configuration information and returns
|
|
31
|
-
an instance of the specified schema based on the available context data.
|
|
32
|
-
|
|
33
|
-
Args:
|
|
34
|
-
schema (Type[T]): A Pydantic model class that defines the structure of the configuration.
|
|
35
|
-
|
|
36
|
-
Returns:
|
|
37
|
-
T: An instance of the specified schema populated with the configuration data.
|
|
38
|
-
|
|
39
|
-
Raises:
|
|
40
|
-
ValueError: If conflicting configuration sources are provided or if no valid
|
|
41
|
-
configuration source is found in the context.
|
|
42
|
-
|
|
43
|
-
Note:
|
|
44
|
-
The method prioritizes the inputs in the following way:
|
|
45
|
-
1. 'config' (i.e. when called explicitly from the playground)
|
|
46
|
-
2. 'environment'
|
|
47
|
-
3. 'variant'
|
|
48
|
-
Only one of these should be provided.
|
|
49
|
-
"""
|
|
50
|
-
context = routing_context.get()
|
|
51
|
-
if ("config" in context and context["config"]) and (
|
|
52
|
-
("environment" in context and context["environment"])
|
|
53
|
-
or ("variant" in context and context["variant"])
|
|
54
|
-
):
|
|
55
|
-
raise ValueError(
|
|
56
|
-
"Either config, environment or variant must be provided. Not both."
|
|
57
|
-
)
|
|
58
|
-
if "config" in context and context["config"]:
|
|
59
|
-
return schema(**context["config"])
|
|
60
|
-
elif "environment" in context and context["environment"]:
|
|
61
|
-
return ConfigManager.get_from_registry(
|
|
62
|
-
schema, environment=context["environment"]
|
|
63
|
-
)
|
|
64
|
-
elif "variant" in context and context["variant"]:
|
|
65
|
-
return ConfigManager.get_from_registry(schema, variant=context["variant"])
|
|
66
|
-
else:
|
|
67
|
-
raise ValueError("Either config, environment or variant must be provided")
|
|
68
|
-
|
|
69
|
-
@staticmethod
|
|
70
|
-
def get_from_registry(
|
|
71
|
-
schema: Type[T],
|
|
72
|
-
environment: Optional[str] = None,
|
|
73
|
-
version: Optional[str] = None,
|
|
74
|
-
variant: Optional[str] = None,
|
|
75
|
-
) -> T:
|
|
76
|
-
"""
|
|
77
|
-
Pulls the parameters for the app variant from the server and returns a config object.
|
|
78
|
-
|
|
79
|
-
This method retrieves the configuration from the backend server based on the provided
|
|
80
|
-
environment or variant. It then validates and returns the configuration as an instance
|
|
81
|
-
of the specified schema.
|
|
82
|
-
|
|
83
|
-
Args:
|
|
84
|
-
schema (Type[T]): A Pydantic model class that defines the structure of the configuration.
|
|
85
|
-
environment (Optional[str]): The environment name to fetch the configuration for.
|
|
86
|
-
Must be one of "development", "production", or "staging".
|
|
87
|
-
version (Optional[str]): Currently not implemented. Will raise NotImplementedError if provided.
|
|
88
|
-
variant (Optional[str]): The variant name to fetch the configuration for.
|
|
89
|
-
|
|
90
|
-
Returns:
|
|
91
|
-
T: An instance of the specified schema populated with the configuration data.
|
|
92
|
-
|
|
93
|
-
Raises:
|
|
94
|
-
ValueError: If neither environment nor variant is provided.
|
|
95
|
-
NotImplementedError: If a specific version is requested (not yet implemented).
|
|
96
|
-
ValidationError: If the retrieved configuration data doesn't match the schema.
|
|
97
|
-
Exception: For any other errors during the process (e.g., API communication issues).
|
|
98
|
-
|
|
99
|
-
Note:
|
|
100
|
-
Either environment or variant must be provided, but not both.
|
|
101
|
-
"""
|
|
102
|
-
if not ConfigManager.client:
|
|
103
|
-
try:
|
|
104
|
-
ConfigManager.client = AgentaApi(
|
|
105
|
-
base_url=singleton.host + "/api",
|
|
106
|
-
api_key=singleton.api_key if singleton.api_key else "",
|
|
107
|
-
)
|
|
108
|
-
except Exception as ex:
|
|
109
|
-
logger.error(
|
|
110
|
-
"Failed to initialize Agenta client with error: %s", str(ex)
|
|
111
|
-
)
|
|
112
|
-
raise
|
|
113
|
-
if not environment and not variant:
|
|
114
|
-
raise ValueError("Either environment or variant must be provided")
|
|
115
|
-
try:
|
|
116
|
-
if environment:
|
|
117
|
-
if version:
|
|
118
|
-
raise NotImplementedError(
|
|
119
|
-
"Getting config for a specific version is not implemented yet."
|
|
120
|
-
)
|
|
121
|
-
else:
|
|
122
|
-
assert (
|
|
123
|
-
environment in AVAILABLE_ENVIRONMENTS
|
|
124
|
-
), f"Environment must be in {AVAILABLE_ENVIRONMENTS}"
|
|
125
|
-
config = ConfigManager.client.configs.get_config(
|
|
126
|
-
base_id=singleton.base_id, environment_name=environment
|
|
127
|
-
)
|
|
128
|
-
elif variant:
|
|
129
|
-
config = ConfigManager.client.configs.get_config(
|
|
130
|
-
base_id=singleton.base_id, config_name=variant
|
|
131
|
-
)
|
|
132
|
-
except Exception as ex:
|
|
133
|
-
logger.error(
|
|
134
|
-
"Failed to pull the configuration from the server with error: %s",
|
|
135
|
-
str(ex),
|
|
136
|
-
)
|
|
137
|
-
|
|
138
|
-
try:
|
|
139
|
-
result = schema(**config.parameters)
|
|
140
|
-
except ValidationError as ex:
|
|
141
|
-
logger.error("Failed to validate the configuration with error: %s", str(ex))
|
|
142
|
-
raise
|
|
143
|
-
return result
|
|
144
|
-
|
|
145
|
-
@staticmethod
|
|
146
|
-
def get_from_yaml(filename: str, schema: Type[T]) -> T:
|
|
147
|
-
"""
|
|
148
|
-
Loads configuration from a YAML file and returns a config object.
|
|
149
|
-
|
|
150
|
-
Args:
|
|
151
|
-
filename (str): The name of the YAML file to load.
|
|
152
|
-
schema (Type[T]): A Pydantic model class that defines the structure of the configuration.
|
|
153
|
-
|
|
154
|
-
Returns:
|
|
155
|
-
T: An instance of the specified schema populated with the configuration data.
|
|
156
|
-
|
|
157
|
-
Raises:
|
|
158
|
-
FileNotFoundError: If the specified file doesn't exist.
|
|
159
|
-
ValidationError: If the loaded configuration data doesn't match the schema.
|
|
160
|
-
"""
|
|
161
|
-
file_path = Path(filename)
|
|
162
|
-
if not file_path.exists():
|
|
163
|
-
raise FileNotFoundError(f"Config file not found: {filename}")
|
|
164
|
-
|
|
165
|
-
with open(file_path, "r") as file:
|
|
166
|
-
config_data = yaml.safe_load(file)
|
|
167
|
-
|
|
168
|
-
try:
|
|
169
|
-
return schema(**config_data)
|
|
170
|
-
except ValidationError as ex:
|
|
171
|
-
logger.error(
|
|
172
|
-
f"Failed to validate the configuration from {filename} with error: {str(ex)}"
|
|
173
|
-
)
|
|
174
|
-
raise
|
|
175
|
-
|
|
176
|
-
@staticmethod
|
|
177
|
-
def get_from_json(filename: str, schema: Type[T]) -> T:
|
|
178
|
-
"""
|
|
179
|
-
Loads configuration from a JSON file and returns a config object.
|
|
180
|
-
|
|
181
|
-
Args:
|
|
182
|
-
filename (str): The name of the JSON file to load.
|
|
183
|
-
schema (Type[T]): A Pydantic model class that defines the structure of the configuration.
|
|
184
|
-
|
|
185
|
-
Returns:
|
|
186
|
-
T: An instance of the specified schema populated with the configuration data.
|
|
187
|
-
|
|
188
|
-
Raises:
|
|
189
|
-
FileNotFoundError: If the specified file doesn't exist.
|
|
190
|
-
ValidationError: If the loaded configuration data doesn't match the schema.
|
|
191
|
-
"""
|
|
192
|
-
file_path = Path(filename)
|
|
193
|
-
if not file_path.exists():
|
|
194
|
-
raise FileNotFoundError(f"Config file not found: {filename}")
|
|
195
|
-
|
|
196
|
-
with open(file_path, "r") as file:
|
|
197
|
-
config_data = json.load(file)
|
|
198
|
-
|
|
199
|
-
try:
|
|
200
|
-
return schema(**config_data)
|
|
201
|
-
except ValidationError as ex:
|
|
202
|
-
logger.error(
|
|
203
|
-
f"Failed to validate the configuration from {filename} with error: {str(ex)}"
|
|
204
|
-
)
|
|
205
|
-
raise
|
|
File without changes
|
|
File without changes
|