agenta 0.36.5__py3-none-any.whl → 0.37.0__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 +1 -2
- agenta/client/__init__.py +6 -10
- agenta/client/{admin → backend/admin}/client.py +2 -0
- agenta/client/backend/api_keys/client.py +531 -0
- agenta/client/{apps → backend/apps}/client.py +0 -222
- agenta/client/{containers → backend/containers}/client.py +10 -70
- agenta/client/{core → backend/core}/http_client.py +6 -6
- agenta/client/{core → backend/core}/pydantic_utilities.py +2 -2
- agenta/client/{environments → backend/environments}/client.py +0 -2
- agenta/client/{human_evaluations → backend/human_evaluations}/client.py +0 -2
- agenta/client/{observability → backend/observability}/client.py +98 -0
- agenta/client/backend/organization/client.py +839 -0
- agenta/client/backend/testsets/__init__.py +1 -0
- agenta/client/{types → backend/types}/__init__.py +22 -6
- agenta/client/{types → backend/types}/agenta_nodes_response.py +0 -5
- agenta/client/{types → backend/types}/agenta_root_dto.py +0 -5
- agenta/client/{types → backend/types}/agenta_roots_response.py +0 -5
- agenta/client/{types → backend/types}/agenta_tree_dto.py +0 -5
- agenta/client/{types → backend/types}/agenta_trees_response.py +0 -5
- agenta/client/backend/types/custom_model_settings_dto.py +22 -0
- agenta/client/backend/types/custom_provider_dto.py +29 -0
- agenta/client/backend/types/custom_provider_kind.py +26 -0
- agenta/client/backend/types/custom_provider_settings_dto.py +24 -0
- agenta/client/backend/types/data.py +7 -0
- agenta/client/{types → backend/types}/organization.py +1 -4
- agenta/client/backend/types/organization_details.py +29 -0
- agenta/client/{types → backend/types}/organization_membership_request.py +3 -2
- agenta/client/{types → backend/types}/permission.py +1 -0
- agenta/client/backend/types/provider_key_dto.py +21 -0
- agenta/client/backend/types/provider_kind.py +21 -0
- agenta/client/backend/types/score.py +3 -0
- agenta/client/{types → backend/types}/secret_dto.py +3 -3
- agenta/client/backend/types/secret_kind.py +5 -0
- agenta/client/backend/types/standard_provider_dto.py +24 -0
- agenta/client/backend/types/standard_provider_kind.py +21 -0
- agenta/client/backend/types/standard_provider_settings_dto.py +21 -0
- agenta/client/backend/types/workspace.py +24 -0
- agenta/client/{variants → backend/variants}/client.py +18 -24
- agenta/client/backend/vault/__init__.py +1 -0
- agenta/client/{vault → backend/vault}/client.py +26 -8
- agenta/client/backend/workspace/__init__.py +1 -0
- agenta/client/backend/workspace/client.py +405 -0
- agenta/client/client.py +46 -46
- agenta/client/types/provider_key_dto.py~feat_model-registry +21 -0
- agenta/client/types/provider_kind.py~feat_model-registry +21 -0
- agenta/sdk/__init__.py +1 -1
- agenta/sdk/managers/secrets.py +175 -11
- agenta/sdk/managers/shared.py +3 -3
- agenta/sdk/middleware/vault.py +29 -37
- agenta/sdk/types.py +4 -7
- {agenta-0.36.5.dist-info → agenta-0.37.0.dist-info}/METADATA +2 -6
- agenta-0.37.0.dist-info/RECORD +255 -0
- agenta/client/types/score.py +0 -5
- agenta/client/types/secret_kind.py +0 -5
- agenta/sdk/client.py +0 -56
- agenta-0.36.5.dist-info/RECORD +0 -236
- /agenta/client/{access_control → backend/access_control}/__init__.py +0 -0
- /agenta/client/{access_control → backend/access_control}/client.py +0 -0
- /agenta/client/{admin → backend/admin}/__init__.py +0 -0
- /agenta/client/{apps → backend/api_keys}/__init__.py +0 -0
- /agenta/client/{bases → backend/apps}/__init__.py +0 -0
- /agenta/client/{configs → backend/bases}/__init__.py +0 -0
- /agenta/client/{bases → backend/bases}/client.py +0 -0
- /agenta/client/{environments → backend/configs}/__init__.py +0 -0
- /agenta/client/{configs → backend/configs}/client.py +0 -0
- /agenta/client/{containers → backend/containers}/__init__.py +0 -0
- /agenta/client/{containers → backend/containers}/types/__init__.py +0 -0
- /agenta/client/{containers → backend/containers}/types/container_templates_response.py +0 -0
- /agenta/client/{core → backend/core}/__init__.py +0 -0
- /agenta/client/{core → backend/core}/api_error.py +0 -0
- /agenta/client/{core → backend/core}/client_wrapper.py +0 -0
- /agenta/client/{core → backend/core}/datetime_utils.py +0 -0
- /agenta/client/{core → backend/core}/file.py +0 -0
- /agenta/client/{core → backend/core}/jsonable_encoder.py +0 -0
- /agenta/client/{core → backend/core}/query_encoder.py +0 -0
- /agenta/client/{core → backend/core}/remove_none_from_dict.py +0 -0
- /agenta/client/{core → backend/core}/request_options.py +0 -0
- /agenta/client/{core → backend/core}/serialization.py +0 -0
- /agenta/client/{evaluations → backend/environments}/__init__.py +0 -0
- /agenta/client/{errors → backend/errors}/__init__.py +0 -0
- /agenta/client/{errors → backend/errors}/unprocessable_entity_error.py +0 -0
- /agenta/client/{evaluators → backend/evaluations}/__init__.py +0 -0
- /agenta/client/{evaluations → backend/evaluations}/client.py +0 -0
- /agenta/client/{human_evaluations → backend/evaluators}/__init__.py +0 -0
- /agenta/client/{evaluators → backend/evaluators}/client.py +0 -0
- /agenta/client/{scopes → backend/human_evaluations}/__init__.py +0 -0
- /agenta/client/{observability → backend/observability}/__init__.py +0 -0
- /agenta/client/{observability → backend/observability}/types/__init__.py +0 -0
- /agenta/client/{observability → backend/observability}/types/format.py +0 -0
- /agenta/client/{observability → backend/observability}/types/query_analytics_response.py +0 -0
- /agenta/client/{observability → backend/observability}/types/query_traces_response.py +0 -0
- /agenta/client/{testsets → backend/organization}/__init__.py +0 -0
- /agenta/client/{vault → backend/scopes}/__init__.py +0 -0
- /agenta/client/{scopes → backend/scopes}/client.py +0 -0
- /agenta/client/{testsets → backend/testsets}/client.py +0 -0
- /agenta/client/{types → backend/types}/account_response.py +0 -0
- /agenta/client/{types → backend/types}/agenta_node_dto.py +0 -0
- /agenta/client/{types → backend/types}/agenta_node_dto_nodes_value.py +0 -0
- /agenta/client/{types → backend/types}/aggregated_result.py +0 -0
- /agenta/client/{types → backend/types}/aggregated_result_evaluator_config.py +0 -0
- /agenta/client/{types → backend/types}/analytics_response.py +0 -0
- /agenta/client/{types → backend/types}/app.py +0 -0
- /agenta/client/{types → backend/types}/app_variant_response.py +0 -0
- /agenta/client/{types → backend/types}/app_variant_revision.py +0 -0
- /agenta/client/{types → backend/types}/base_output.py +0 -0
- /agenta/client/{types → backend/types}/body_import_testset.py +0 -0
- /agenta/client/{types → backend/types}/bucket_dto.py +0 -0
- /agenta/client/{types → backend/types}/collect_status_response.py +0 -0
- /agenta/client/{types → backend/types}/config_db.py +0 -0
- /agenta/client/{types → backend/types}/config_dto.py +0 -0
- /agenta/client/{types → backend/types}/config_response_model.py +0 -0
- /agenta/client/{types → backend/types}/correct_answer.py +0 -0
- /agenta/client/{types → backend/types}/create_app_output.py +0 -0
- /agenta/client/{types → backend/types}/delete_evaluation.py +0 -0
- /agenta/client/{types → backend/types}/docker_env_vars.py +0 -0
- /agenta/client/{types → backend/types}/environment_output.py +0 -0
- /agenta/client/{types → backend/types}/environment_output_extended.py +0 -0
- /agenta/client/{types → backend/types}/environment_revision.py +0 -0
- /agenta/client/{types → backend/types}/error.py +0 -0
- /agenta/client/{types → backend/types}/evaluation.py +0 -0
- /agenta/client/{types → backend/types}/evaluation_scenario.py +0 -0
- /agenta/client/{types → backend/types}/evaluation_scenario_input.py +0 -0
- /agenta/client/{types → backend/types}/evaluation_scenario_output.py +0 -0
- /agenta/client/{types → backend/types}/evaluation_scenario_result.py +0 -0
- /agenta/client/{types → backend/types}/evaluation_status_enum.py +0 -0
- /agenta/client/{types → backend/types}/evaluation_type.py +0 -0
- /agenta/client/{types → backend/types}/evaluator.py +0 -0
- /agenta/client/{types → backend/types}/evaluator_config.py +0 -0
- /agenta/client/{types → backend/types}/evaluator_mapping_output_interface.py +0 -0
- /agenta/client/{types → backend/types}/evaluator_output_interface.py +0 -0
- /agenta/client/{types → backend/types}/exception_dto.py +0 -0
- /agenta/client/{types → backend/types}/get_config_response.py +0 -0
- /agenta/client/{types → backend/types}/header_dto.py +0 -0
- /agenta/client/{types → backend/types}/http_validation_error.py +0 -0
- /agenta/client/{types → backend/types}/human_evaluation.py +0 -0
- /agenta/client/{types → backend/types}/human_evaluation_scenario.py +0 -0
- /agenta/client/{types → backend/types}/human_evaluation_scenario_input.py +0 -0
- /agenta/client/{types → backend/types}/human_evaluation_scenario_output.py +0 -0
- /agenta/client/{types → backend/types}/image.py +0 -0
- /agenta/client/{types → backend/types}/invite_request.py +0 -0
- /agenta/client/{types → backend/types}/legacy_analytics_response.py +0 -0
- /agenta/client/{types → backend/types}/legacy_data_point.py +0 -0
- /agenta/client/{types → backend/types}/legacy_scope_request.py +0 -0
- /agenta/client/{types → backend/types}/legacy_scopes_response.py +0 -0
- /agenta/client/{types → backend/types}/legacy_user_request.py +0 -0
- /agenta/client/{types → backend/types}/legacy_user_response.py +0 -0
- /agenta/client/{types → backend/types}/lifecycle_dto.py +0 -0
- /agenta/client/{types → backend/types}/link_dto.py +0 -0
- /agenta/client/{types → backend/types}/list_api_keys_response.py +0 -0
- /agenta/client/{types → backend/types}/llm_run_rate_limit.py +0 -0
- /agenta/client/{types → backend/types}/metrics_dto.py +0 -0
- /agenta/client/{types → backend/types}/new_testset.py +0 -0
- /agenta/client/{types → backend/types}/node_dto.py +0 -0
- /agenta/client/{types → backend/types}/node_type.py +0 -0
- /agenta/client/{types → backend/types}/o_tel_context_dto.py +0 -0
- /agenta/client/{types → backend/types}/o_tel_event_dto.py +0 -0
- /agenta/client/{types → backend/types}/o_tel_extra_dto.py +0 -0
- /agenta/client/{types → backend/types}/o_tel_link_dto.py +0 -0
- /agenta/client/{types → backend/types}/o_tel_span_dto.py +0 -0
- /agenta/client/{types → backend/types}/o_tel_span_kind.py +0 -0
- /agenta/client/{types → backend/types}/o_tel_spans_response.py +0 -0
- /agenta/client/{types → backend/types}/o_tel_status_code.py +0 -0
- /agenta/client/{types → backend/types}/organization_output.py +0 -0
- /agenta/client/{types → backend/types}/organization_request.py +0 -0
- /agenta/client/{types → backend/types}/parent_dto.py +0 -0
- /agenta/client/{types → backend/types}/project_membership_request.py +0 -0
- /agenta/client/{types → backend/types}/project_request.py +0 -0
- /agenta/client/{types → backend/types}/project_scope.py +0 -0
- /agenta/client/{types → backend/types}/projects_response.py +0 -0
- /agenta/client/{types → backend/types}/reference.py +0 -0
- /agenta/client/{types → backend/types}/reference_dto.py +0 -0
- /agenta/client/{types → backend/types}/reference_request_model.py +0 -0
- /agenta/client/{types → backend/types}/result.py +0 -0
- /agenta/client/{types → backend/types}/role.py +0 -0
- /agenta/client/{types → backend/types}/root_dto.py +0 -0
- /agenta/client/{types → backend/types}/scopes_response_model.py +0 -0
- /agenta/client/{types → backend/types}/secret_response_dto.py +0 -0
- /agenta/client/{types → backend/types}/simple_evaluation_output.py +0 -0
- /agenta/client/{types → backend/types}/span_dto.py +0 -0
- /agenta/client/{types → backend/types}/span_dto_nodes_value.py +0 -0
- /agenta/client/{types → backend/types}/status_code.py +0 -0
- /agenta/client/{types → backend/types}/status_dto.py +0 -0
- /agenta/client/{types → backend/types}/template.py +0 -0
- /agenta/client/{types → backend/types}/template_image_info.py +0 -0
- /agenta/client/{types → backend/types}/test_set_output_response.py +0 -0
- /agenta/client/{types → backend/types}/test_set_simple_response.py +0 -0
- /agenta/client/{types → backend/types}/time_dto.py +0 -0
- /agenta/client/{types → backend/types}/tree_dto.py +0 -0
- /agenta/client/{types → backend/types}/tree_type.py +0 -0
- /agenta/client/{types → backend/types}/update_app_output.py +0 -0
- /agenta/client/{types → backend/types}/uri.py +0 -0
- /agenta/client/{types → backend/types}/user_request.py +0 -0
- /agenta/client/{types → backend/types}/validation_error.py +0 -0
- /agenta/client/{types → backend/types}/validation_error_loc_item.py +0 -0
- /agenta/client/{types → backend/types}/variant_action.py +0 -0
- /agenta/client/{types → backend/types}/variant_action_enum.py +0 -0
- /agenta/client/{types → backend/types}/workspace_member_response.py +0 -0
- /agenta/client/{types → backend/types}/workspace_membership_request.py +0 -0
- /agenta/client/{types → backend/types}/workspace_permission.py +0 -0
- /agenta/client/{types → backend/types}/workspace_request.py +0 -0
- /agenta/client/{types → backend/types}/workspace_response.py +0 -0
- /agenta/client/{types → backend/types}/workspace_role.py +0 -0
- /agenta/client/{types → backend/types}/workspace_role_response.py +0 -0
- /agenta/client/{variants → backend/variants}/__init__.py +0 -0
- /agenta/client/{variants → backend/variants}/types/__init__.py +0 -0
- /agenta/client/{variants → backend/variants}/types/add_variant_from_base_and_config_response.py +0 -0
- /agenta/client/types/{provider_key_dto.py → provider_key_dto.py~HEAD} +0 -0
- /agenta/client/types/{provider_kind.py → provider_kind.py~HEAD} +0 -0
- {agenta-0.36.5.dist-info → agenta-0.37.0.dist-info}/WHEEL +0 -0
agenta/sdk/managers/secrets.py
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import re
|
|
2
|
+
from typing import Optional, Dict, Any, List
|
|
2
3
|
|
|
3
4
|
from agenta.sdk.context.routing import routing_context
|
|
4
|
-
|
|
5
|
-
from agenta.sdk.assets import model_to_provider_mapping
|
|
5
|
+
from agenta.sdk.assets import model_to_provider_mapping as _standard_providers
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class SecretsManager:
|
|
9
9
|
@staticmethod
|
|
10
|
-
def get_from_route() -> Optional[Dict[str, Any]]:
|
|
10
|
+
def get_from_route() -> Optional[List[Dict[str, Any]]]:
|
|
11
11
|
context = routing_context.get()
|
|
12
12
|
|
|
13
13
|
secrets = context.secrets
|
|
@@ -18,21 +18,185 @@ class SecretsManager:
|
|
|
18
18
|
return secrets
|
|
19
19
|
|
|
20
20
|
@staticmethod
|
|
21
|
-
def
|
|
22
|
-
|
|
21
|
+
def _parse_standard_secrets(
|
|
22
|
+
secret: Dict[str, Any], standard_secrets: List[Dict[str, Any]]
|
|
23
|
+
):
|
|
24
|
+
standard_secrets.append(
|
|
25
|
+
{
|
|
26
|
+
"kind": secret.get("kind", ""),
|
|
27
|
+
"data": secret.get("data", {}),
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
@staticmethod
|
|
32
|
+
def _parse_custom_secrets(
|
|
33
|
+
secret: Dict[str, Any],
|
|
34
|
+
custom_secrets: List[Dict[str, Any]],
|
|
35
|
+
):
|
|
36
|
+
data = secret.get("data", {})
|
|
37
|
+
custom_secrets.append(
|
|
38
|
+
{
|
|
39
|
+
"kind": secret.get("kind", ""),
|
|
40
|
+
"data": {
|
|
41
|
+
"provider_slug": data.get("provider_slug"),
|
|
42
|
+
"provider": {
|
|
43
|
+
"kind": data.get("kind", ""),
|
|
44
|
+
"extras": (
|
|
45
|
+
{
|
|
46
|
+
**data["provider"]["extras"],
|
|
47
|
+
"api_base": data["provider"]["url"],
|
|
48
|
+
"api_version": data["provider"].get("version"),
|
|
49
|
+
}
|
|
50
|
+
if all(
|
|
51
|
+
k in data.get("provider", {}) for k in ["extras", "url"]
|
|
52
|
+
)
|
|
53
|
+
else data.get("provider", {}).get("extras", {})
|
|
54
|
+
),
|
|
55
|
+
},
|
|
56
|
+
"models": data.get("model_keys", []),
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
@staticmethod
|
|
62
|
+
def _parse_secrets(secrets: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
|
|
63
|
+
standard_secrets: List[dict] = []
|
|
64
|
+
custom_secrets: List[dict] = []
|
|
65
|
+
|
|
66
|
+
for secret in secrets:
|
|
67
|
+
if secret.get("kind") == "provider_key":
|
|
68
|
+
SecretsManager._parse_standard_secrets(
|
|
69
|
+
secret=secret,
|
|
70
|
+
standard_secrets=standard_secrets,
|
|
71
|
+
) # append secret to standard_secrets
|
|
72
|
+
elif secret.get("kind") == "custom_provider":
|
|
73
|
+
SecretsManager._parse_custom_secrets(
|
|
74
|
+
secret=secret,
|
|
75
|
+
custom_secrets=custom_secrets,
|
|
76
|
+
) # append secret to custom_secrets
|
|
77
|
+
|
|
78
|
+
secrets = standard_secrets + custom_secrets
|
|
79
|
+
|
|
80
|
+
return secrets
|
|
81
|
+
|
|
82
|
+
@staticmethod
|
|
83
|
+
def _custom_provider_get_value(
|
|
84
|
+
*, model: str, secrets: list[dict], key: str, from_provider: bool = True
|
|
85
|
+
):
|
|
86
|
+
for secret in secrets:
|
|
87
|
+
models = secret.get("data", {}).get("models", [])
|
|
88
|
+
if model in models:
|
|
89
|
+
if from_provider:
|
|
90
|
+
return secret.get("data", {}).get("provider", {}).get(key)
|
|
91
|
+
return secret.get("data", {}).get(key)
|
|
92
|
+
return None
|
|
93
|
+
|
|
94
|
+
@staticmethod
|
|
95
|
+
def _custom_providers_get(*, model: str, secrets: list[dict]):
|
|
96
|
+
return SecretsManager._custom_provider_get_value(
|
|
97
|
+
model=model, secrets=secrets, key="kind", from_provider=True
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
@staticmethod
|
|
101
|
+
def _custom_provider_slug_get(*, model: str, secrets: list[dict]):
|
|
102
|
+
return SecretsManager._custom_provider_get_value(
|
|
103
|
+
model=model, secrets=secrets, key="provider_slug", from_provider=False
|
|
104
|
+
)
|
|
23
105
|
|
|
106
|
+
@staticmethod
|
|
107
|
+
def _get_compatible_model(*, model: str, provider_slug: str):
|
|
108
|
+
"""Return the model string used by litellm.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
model (str): The complete model string (e.g. `mybedrock/bedrock/model_name`).
|
|
112
|
+
In the format provider_slug/kind/model_name (See SecretResponseDTO)
|
|
113
|
+
provider_slug (str): The provider slug (e.g. `mybedrock`)
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
str: The model string used by litellm
|
|
117
|
+
"""
|
|
118
|
+
# First replace provider_slug/custom with openai.
|
|
119
|
+
# The reason is that custom providers are in fact openai compatible providers
|
|
120
|
+
# They need to be passed in litellm as openai/modelname
|
|
121
|
+
|
|
122
|
+
if "custom" in model:
|
|
123
|
+
modified_model = model.replace(f"{provider_slug}/custom/", "openai/")
|
|
124
|
+
return modified_model.replace(f"{provider_slug}/", "")
|
|
125
|
+
|
|
126
|
+
return model.replace(f"{provider_slug}/", "")
|
|
127
|
+
|
|
128
|
+
@staticmethod
|
|
129
|
+
def get_provider_settings(model: str) -> Optional[Dict]:
|
|
130
|
+
"""
|
|
131
|
+
Builds the LLM request with appropriate kwargs based on the custom provider/model
|
|
132
|
+
|
|
133
|
+
Args:
|
|
134
|
+
model (str): The name of the model
|
|
135
|
+
|
|
136
|
+
Returns:
|
|
137
|
+
Dict: A dictionary containing all parameters needed for litellm.completion
|
|
138
|
+
"""
|
|
139
|
+
|
|
140
|
+
# STEP 1: get vault secrets from route context and transform it
|
|
141
|
+
secrets = SecretsManager.get_from_route()
|
|
24
142
|
if not secrets:
|
|
25
143
|
return None
|
|
26
144
|
|
|
27
|
-
|
|
145
|
+
# STEP 1b: Parse secrets into usable format
|
|
146
|
+
secrets = SecretsManager._parse_secrets(secrets=secrets)
|
|
147
|
+
|
|
148
|
+
# STEP 2: check model exists in supported standard models
|
|
149
|
+
provider = _standard_providers.get(model)
|
|
150
|
+
if not provider:
|
|
151
|
+
# check and get provider kind if model exists in custom provider models
|
|
152
|
+
provider = SecretsManager._custom_providers_get(
|
|
153
|
+
model=model,
|
|
154
|
+
secrets=secrets,
|
|
155
|
+
)
|
|
28
156
|
|
|
157
|
+
# STEP 2b: return None in the case provider is None
|
|
29
158
|
if not provider:
|
|
30
159
|
return None
|
|
31
160
|
|
|
32
|
-
|
|
161
|
+
# STEP 2c: get litellm compatible model
|
|
162
|
+
provider_slug = SecretsManager._custom_provider_slug_get(
|
|
163
|
+
model=model, secrets=secrets
|
|
164
|
+
)
|
|
165
|
+
model = SecretsManager._get_compatible_model(
|
|
166
|
+
model=model, provider_slug=provider_slug
|
|
167
|
+
)
|
|
33
168
|
|
|
169
|
+
# STEP 3: initialize provider settings and simplify provider name
|
|
170
|
+
provider_settings = {"model": model}
|
|
171
|
+
provider_name = re.sub(
|
|
172
|
+
r"[\s-]+", "", provider.lower()
|
|
173
|
+
) # normalizing other special characters too (azure-openai)
|
|
174
|
+
|
|
175
|
+
# STEP 4: get credentials for model
|
|
34
176
|
for secret in secrets:
|
|
35
|
-
|
|
36
|
-
|
|
177
|
+
secret_data = secret.get("data", {})
|
|
178
|
+
provider_info = secret_data.get("provider", {})
|
|
37
179
|
|
|
38
|
-
|
|
180
|
+
# i). Extract API key if present
|
|
181
|
+
# (for standard models -- openai/anthropic/gemini, etc)
|
|
182
|
+
if secret.get("kind") == "provider_key":
|
|
183
|
+
provider_kind = secret_data.get("kind", "")
|
|
184
|
+
|
|
185
|
+
if provider_kind == provider_name:
|
|
186
|
+
if "key" in provider_info:
|
|
187
|
+
provider_settings["api_key"] = provider_info["key"]
|
|
188
|
+
continue
|
|
189
|
+
|
|
190
|
+
# ii). Extract Credentials if present
|
|
191
|
+
# (for custom providers -- aws bedrock/sagemaker, vertexai, etc)
|
|
192
|
+
elif secret.get("kind") == "custom_provider":
|
|
193
|
+
provider_kind = provider_info.get("kind", "").lower().replace(" ", "")
|
|
194
|
+
provider_slug = secret_data.get("provider_slug", "")
|
|
195
|
+
provider_extras = provider_info.get("extras", {})
|
|
196
|
+
|
|
197
|
+
if provider_kind == provider_name or provider_slug == provider_name:
|
|
198
|
+
if provider_extras:
|
|
199
|
+
provider_settings.update(provider_extras)
|
|
200
|
+
continue
|
|
201
|
+
|
|
202
|
+
return provider_settings
|
agenta/sdk/managers/shared.py
CHANGED
|
@@ -7,9 +7,9 @@ from agenta.sdk.types import (
|
|
|
7
7
|
ConfigurationResponse,
|
|
8
8
|
DeploymentResponse,
|
|
9
9
|
)
|
|
10
|
-
from agenta.client.types.config_dto import ConfigDto as ConfigRequest
|
|
11
|
-
from agenta.client.types.config_response_model import ConfigResponseModel
|
|
12
|
-
from agenta.client.types.reference_request_model import ReferenceRequestModel
|
|
10
|
+
from agenta.client.backend.types.config_dto import ConfigDto as ConfigRequest
|
|
11
|
+
from agenta.client.backend.types.config_response_model import ConfigResponseModel
|
|
12
|
+
from agenta.client.backend.types.reference_request_model import ReferenceRequestModel
|
|
13
13
|
|
|
14
14
|
import agenta as ag
|
|
15
15
|
|
agenta/sdk/middleware/vault.py
CHANGED
|
@@ -7,22 +7,23 @@ from fastapi import FastAPI, Request
|
|
|
7
7
|
from starlette.middleware.base import BaseHTTPMiddleware
|
|
8
8
|
|
|
9
9
|
from agenta.sdk.utils.constants import TRUTHY
|
|
10
|
-
from agenta.
|
|
10
|
+
from agenta.sdk.utils.cache import TTLLRUCache
|
|
11
11
|
from agenta.sdk.utils.exceptions import suppress, display_exception
|
|
12
|
-
from agenta.client.types
|
|
13
|
-
from agenta.client.types
|
|
14
|
-
|
|
12
|
+
from agenta.client.backend.types import SecretDto as SecretDTO
|
|
13
|
+
from agenta.client.backend.types import (
|
|
14
|
+
StandardProviderKind,
|
|
15
|
+
StandardProviderDto as StandardProviderDTO,
|
|
16
|
+
StandardProviderSettingsDto as StandardProviderSettingsDTO,
|
|
15
17
|
)
|
|
16
|
-
from agenta.sdk.utils.cache import TTLLRUCache
|
|
17
18
|
|
|
18
19
|
import agenta as ag
|
|
19
20
|
|
|
20
21
|
|
|
21
22
|
_PROVIDER_KINDS = []
|
|
22
23
|
|
|
23
|
-
for
|
|
24
|
-
if hasattr(
|
|
25
|
-
_PROVIDER_KINDS.extend(
|
|
24
|
+
for provider_kind in StandardProviderKind.__args__[0].__args__: # type: ignore
|
|
25
|
+
if hasattr(provider_kind, "__args__"):
|
|
26
|
+
_PROVIDER_KINDS.extend(provider_kind.__args__)
|
|
26
27
|
|
|
27
28
|
_CACHE_ENABLED = getenv("AGENTA_MIDDLEWARE_CACHE_ENABLED", "false").lower() in TRUTHY
|
|
28
29
|
|
|
@@ -35,18 +36,6 @@ class VaultMiddleware(BaseHTTPMiddleware):
|
|
|
35
36
|
|
|
36
37
|
self.host = ag.DEFAULT_AGENTA_SINGLETON_INSTANCE.host
|
|
37
38
|
|
|
38
|
-
def _transform_secrets_response_to_secret_dto(
|
|
39
|
-
self, secrets_list: List[Dict[str, Any]]
|
|
40
|
-
) -> List[Dict[str, Any]]:
|
|
41
|
-
secrets_dto_dict = [
|
|
42
|
-
{
|
|
43
|
-
"kind": secret.get("secret", {}).get("kind"),
|
|
44
|
-
"data": secret.get("secret", {}).get("data", {}),
|
|
45
|
-
}
|
|
46
|
-
for secret in secrets_list
|
|
47
|
-
]
|
|
48
|
-
return secrets_dto_dict
|
|
49
|
-
|
|
50
39
|
async def dispatch(
|
|
51
40
|
self,
|
|
52
41
|
request: Request,
|
|
@@ -83,7 +72,7 @@ class VaultMiddleware(BaseHTTPMiddleware):
|
|
|
83
72
|
|
|
84
73
|
return secrets
|
|
85
74
|
|
|
86
|
-
local_secrets: List[
|
|
75
|
+
local_secrets: List[Dict[str, Any]] = []
|
|
87
76
|
|
|
88
77
|
try:
|
|
89
78
|
for provider_kind in _PROVIDER_KINDS:
|
|
@@ -95,18 +84,18 @@ class VaultMiddleware(BaseHTTPMiddleware):
|
|
|
95
84
|
continue
|
|
96
85
|
|
|
97
86
|
secret = SecretDTO(
|
|
98
|
-
|
|
99
|
-
data=
|
|
100
|
-
|
|
101
|
-
key=key,
|
|
87
|
+
kind="provider_kind", # type: ignore
|
|
88
|
+
data=StandardProviderDTO(
|
|
89
|
+
kind=provider,
|
|
90
|
+
provider=StandardProviderSettingsDTO(key=key),
|
|
102
91
|
),
|
|
103
92
|
)
|
|
104
93
|
|
|
105
|
-
local_secrets.append(secret.model_dump())
|
|
94
|
+
local_secrets.append(secret.model_dump())
|
|
106
95
|
except: # pylint: disable=bare-except
|
|
107
96
|
display_exception("Vault: Local Secrets Exception")
|
|
108
97
|
|
|
109
|
-
vault_secrets: List[
|
|
98
|
+
vault_secrets: List[Dict[str, Any]] = []
|
|
110
99
|
|
|
111
100
|
try:
|
|
112
101
|
async with httpx.AsyncClient() as client:
|
|
@@ -119,26 +108,29 @@ class VaultMiddleware(BaseHTTPMiddleware):
|
|
|
119
108
|
vault_secrets = []
|
|
120
109
|
|
|
121
110
|
else:
|
|
122
|
-
|
|
123
|
-
vault_secrets = self._transform_secrets_response_to_secret_dto(
|
|
124
|
-
secrets_list=secrets # type: ignore
|
|
125
|
-
)
|
|
111
|
+
vault_secrets = response.json()
|
|
126
112
|
except: # pylint: disable=bare-except
|
|
127
113
|
display_exception("Vault: Vault Secrets Exception")
|
|
128
114
|
|
|
129
|
-
|
|
115
|
+
secrets = local_secrets + vault_secrets
|
|
116
|
+
|
|
117
|
+
standard_secrets = {}
|
|
118
|
+
custom_secrets = []
|
|
130
119
|
|
|
131
120
|
if local_secrets:
|
|
132
121
|
for secret in local_secrets:
|
|
133
|
-
|
|
134
|
-
merged_secrets[provider] = secret
|
|
122
|
+
standard_secrets[secret["data"]["kind"]] = secret # type: ignore
|
|
135
123
|
|
|
136
124
|
if vault_secrets:
|
|
137
125
|
for secret in vault_secrets:
|
|
138
|
-
|
|
139
|
-
|
|
126
|
+
if secret["kind"] == "provider_key": # type: ignore
|
|
127
|
+
standard_secrets[secret["data"]["kind"]] = secret # type: ignore
|
|
128
|
+
elif secret["kind"] == "custom_provider": # type: ignore
|
|
129
|
+
custom_secrets.append(secret)
|
|
130
|
+
|
|
131
|
+
standard_secrets = list(standard_secrets.values())
|
|
140
132
|
|
|
141
|
-
secrets =
|
|
133
|
+
secrets = standard_secrets + custom_secrets
|
|
142
134
|
|
|
143
135
|
_cache.put(_hash, {"secrets": secrets})
|
|
144
136
|
|
agenta/sdk/types.py
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import json
|
|
2
2
|
from dataclasses import dataclass
|
|
3
|
-
from typing import
|
|
3
|
+
from typing import List, Union, Optional, Dict, Literal, Any
|
|
4
4
|
|
|
5
5
|
from pydantic import ConfigDict, BaseModel, HttpUrl
|
|
6
|
-
|
|
7
|
-
from agenta.client.types.agenta_node_dto import AgentaNodeDto
|
|
8
|
-
from agenta.client.types.agenta_nodes_response import AgentaNodesResponse
|
|
9
|
-
from typing import Annotated, List, Union, Optional, Dict, Literal, Any
|
|
10
6
|
from pydantic import BaseModel, Field, model_validator
|
|
7
|
+
|
|
11
8
|
from agenta.sdk.assets import supported_llm_models
|
|
9
|
+
from agenta.client.backend.types import AgentaNodesResponse, AgentaNodeDto
|
|
12
10
|
|
|
13
11
|
|
|
14
12
|
@dataclass
|
|
@@ -543,8 +541,7 @@ class PromptTemplate(BaseModel):
|
|
|
543
541
|
def to_openai_kwargs(self) -> dict:
|
|
544
542
|
"""Convert the prompt template to kwargs compatible with litellm/openai"""
|
|
545
543
|
kwargs = {
|
|
546
|
-
"
|
|
547
|
-
"messages": [msg.dict(exclude_none=True) for msg in self.messages],
|
|
544
|
+
"messages": [msg.model_dump(exclude_none=True) for msg in self.messages],
|
|
548
545
|
}
|
|
549
546
|
|
|
550
547
|
# Add optional parameters only if they are set
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: agenta
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.37.0
|
|
4
4
|
Summary: The SDK for agenta is an open-source LLMOps platform.
|
|
5
5
|
Keywords: LLMOps,LLM,evaluation,prompt engineering
|
|
6
6
|
Author: Mahmoud Mabrouk
|
|
@@ -15,20 +15,16 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.13
|
|
17
17
|
Classifier: Topic :: Software Development :: Libraries
|
|
18
|
-
Requires-Dist: cachetools (>=5.3.3,<6.0.0)
|
|
19
|
-
Requires-Dist: docker (>=6.1.1,<8.0.0)
|
|
20
18
|
Requires-Dist: fastapi (>=0.100.0)
|
|
21
19
|
Requires-Dist: httpx (>=0.24,<0.28)
|
|
22
20
|
Requires-Dist: importlib-metadata (>=8.0.0,<9.0)
|
|
23
21
|
Requires-Dist: litellm (>=1.48.0,<2.0.0)
|
|
24
22
|
Requires-Dist: opentelemetry-api (==1.27.0)
|
|
25
|
-
Requires-Dist: opentelemetry-exporter-otlp (==1.27.0)
|
|
23
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-http (==1.27.0)
|
|
26
24
|
Requires-Dist: opentelemetry-sdk (==1.27.0)
|
|
27
|
-
Requires-Dist: posthog (>=3.1.0,<4.0.0)
|
|
28
25
|
Requires-Dist: pydantic (>=2)
|
|
29
26
|
Requires-Dist: python-dotenv (>=1.0.0,<2.0.0)
|
|
30
27
|
Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
|
|
31
|
-
Requires-Dist: questionary (>=1.10,<3.0)
|
|
32
28
|
Requires-Dist: toml (>=0.10.2,<0.11.0)
|
|
33
29
|
Project-URL: Documentation, https://docs.agenta.ai
|
|
34
30
|
Project-URL: Homepage, https://agenta.ai
|