agenta 0.36.3__py3-none-any.whl → 0.36.5__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 +5 -5
- agenta/client/Readme.md +3 -3
- agenta/client/__init__.py +294 -0
- agenta/client/client.py +3192 -466
- agenta/sdk/__init__.py +5 -5
- agenta/sdk/agenta_init.py +28 -54
- agenta/sdk/client.py +1 -1
- agenta/sdk/managers/shared.py +3 -3
- agenta/sdk/middleware/auth.py +18 -9
- agenta/sdk/middleware/config.py +0 -2
- agenta/sdk/middleware/vault.py +3 -3
- agenta/sdk/types.py +2 -2
- {agenta-0.36.3.dist-info → agenta-0.36.5.dist-info}/METADATA +1 -2
- agenta-0.36.5.dist-info/RECORD +236 -0
- agenta/cli/helper.py +0 -202
- agenta/cli/main.py +0 -229
- agenta/cli/telemetry.py +0 -50
- agenta/cli/variant_commands.py +0 -526
- agenta/cli/variant_configs.py +0 -49
- agenta/client/api.py +0 -74
- agenta/client/api_models.py +0 -34
- agenta/client/backend/__init__.py +0 -294
- agenta/client/backend/client.py +0 -3289
- agenta/client/exceptions.py +0 -2
- agenta/docker/docker-assets/Dockerfile.cloud.template +0 -9
- agenta/docker/docker-assets/Dockerfile.oss.template +0 -13
- agenta/docker/docker-assets/Dockerfile.template +0 -13
- agenta/docker/docker-assets/README.md +0 -1
- agenta/docker/docker-assets/entrypoint.sh +0 -7
- agenta/docker/docker-assets/lambda_function.py +0 -6
- agenta/docker/docker-assets/main.py +0 -13
- agenta/docker/docker_utils.py +0 -100
- agenta-0.36.3.dist-info/RECORD +0 -255
- agenta-0.36.3.dist-info/entry_points.txt +0 -3
- /agenta/client/{backend/access_control → access_control}/__init__.py +0 -0
- /agenta/client/{backend/access_control → access_control}/client.py +0 -0
- /agenta/client/{backend/admin → admin}/__init__.py +0 -0
- /agenta/client/{backend/admin → admin}/client.py +0 -0
- /agenta/client/{backend/apps → apps}/__init__.py +0 -0
- /agenta/client/{backend/apps → apps}/client.py +0 -0
- /agenta/client/{backend/bases → bases}/__init__.py +0 -0
- /agenta/client/{backend/bases → bases}/client.py +0 -0
- /agenta/client/{backend/configs → configs}/__init__.py +0 -0
- /agenta/client/{backend/configs → configs}/client.py +0 -0
- /agenta/client/{backend/containers → containers}/__init__.py +0 -0
- /agenta/client/{backend/containers → containers}/client.py +0 -0
- /agenta/client/{backend/containers → containers}/types/__init__.py +0 -0
- /agenta/client/{backend/containers → containers}/types/container_templates_response.py +0 -0
- /agenta/client/{backend/core → core}/__init__.py +0 -0
- /agenta/client/{backend/core → core}/api_error.py +0 -0
- /agenta/client/{backend/core → core}/client_wrapper.py +0 -0
- /agenta/client/{backend/core → core}/datetime_utils.py +0 -0
- /agenta/client/{backend/core → core}/file.py +0 -0
- /agenta/client/{backend/core → core}/http_client.py +0 -0
- /agenta/client/{backend/core → core}/jsonable_encoder.py +0 -0
- /agenta/client/{backend/core → core}/pydantic_utilities.py +0 -0
- /agenta/client/{backend/core → core}/query_encoder.py +0 -0
- /agenta/client/{backend/core → core}/remove_none_from_dict.py +0 -0
- /agenta/client/{backend/core → core}/request_options.py +0 -0
- /agenta/client/{backend/core → core}/serialization.py +0 -0
- /agenta/client/{backend/environments → environments}/__init__.py +0 -0
- /agenta/client/{backend/environments → environments}/client.py +0 -0
- /agenta/client/{backend/errors → errors}/__init__.py +0 -0
- /agenta/client/{backend/errors → errors}/unprocessable_entity_error.py +0 -0
- /agenta/client/{backend/evaluations → evaluations}/__init__.py +0 -0
- /agenta/client/{backend/evaluations → evaluations}/client.py +0 -0
- /agenta/client/{backend/evaluators → evaluators}/__init__.py +0 -0
- /agenta/client/{backend/evaluators → evaluators}/client.py +0 -0
- /agenta/client/{backend/human_evaluations → human_evaluations}/__init__.py +0 -0
- /agenta/client/{backend/human_evaluations → human_evaluations}/client.py +0 -0
- /agenta/client/{backend/observability → observability}/__init__.py +0 -0
- /agenta/client/{backend/observability → observability}/client.py +0 -0
- /agenta/client/{backend/observability → observability}/types/__init__.py +0 -0
- /agenta/client/{backend/observability → observability}/types/format.py +0 -0
- /agenta/client/{backend/observability → observability}/types/query_analytics_response.py +0 -0
- /agenta/client/{backend/observability → observability}/types/query_traces_response.py +0 -0
- /agenta/client/{backend/scopes → scopes}/__init__.py +0 -0
- /agenta/client/{backend/scopes → scopes}/client.py +0 -0
- /agenta/client/{backend/testsets → testsets}/__init__.py +0 -0
- /agenta/client/{backend/testsets → testsets}/client.py +0 -0
- /agenta/client/{backend/types → types}/__init__.py +0 -0
- /agenta/client/{backend/types → types}/account_response.py +0 -0
- /agenta/client/{backend/types → types}/agenta_node_dto.py +0 -0
- /agenta/client/{backend/types → types}/agenta_node_dto_nodes_value.py +0 -0
- /agenta/client/{backend/types → types}/agenta_nodes_response.py +0 -0
- /agenta/client/{backend/types → types}/agenta_root_dto.py +0 -0
- /agenta/client/{backend/types → types}/agenta_roots_response.py +0 -0
- /agenta/client/{backend/types → types}/agenta_tree_dto.py +0 -0
- /agenta/client/{backend/types → types}/agenta_trees_response.py +0 -0
- /agenta/client/{backend/types → types}/aggregated_result.py +0 -0
- /agenta/client/{backend/types → types}/aggregated_result_evaluator_config.py +0 -0
- /agenta/client/{backend/types → types}/analytics_response.py +0 -0
- /agenta/client/{backend/types → types}/app.py +0 -0
- /agenta/client/{backend/types → types}/app_variant_response.py +0 -0
- /agenta/client/{backend/types → types}/app_variant_revision.py +0 -0
- /agenta/client/{backend/types → types}/base_output.py +0 -0
- /agenta/client/{backend/types → types}/body_import_testset.py +0 -0
- /agenta/client/{backend/types → types}/bucket_dto.py +0 -0
- /agenta/client/{backend/types → types}/collect_status_response.py +0 -0
- /agenta/client/{backend/types → types}/config_db.py +0 -0
- /agenta/client/{backend/types → types}/config_dto.py +0 -0
- /agenta/client/{backend/types → types}/config_response_model.py +0 -0
- /agenta/client/{backend/types → types}/correct_answer.py +0 -0
- /agenta/client/{backend/types → types}/create_app_output.py +0 -0
- /agenta/client/{backend/types → types}/delete_evaluation.py +0 -0
- /agenta/client/{backend/types → types}/docker_env_vars.py +0 -0
- /agenta/client/{backend/types → types}/environment_output.py +0 -0
- /agenta/client/{backend/types → types}/environment_output_extended.py +0 -0
- /agenta/client/{backend/types → types}/environment_revision.py +0 -0
- /agenta/client/{backend/types → types}/error.py +0 -0
- /agenta/client/{backend/types → types}/evaluation.py +0 -0
- /agenta/client/{backend/types → types}/evaluation_scenario.py +0 -0
- /agenta/client/{backend/types → types}/evaluation_scenario_input.py +0 -0
- /agenta/client/{backend/types → types}/evaluation_scenario_output.py +0 -0
- /agenta/client/{backend/types → types}/evaluation_scenario_result.py +0 -0
- /agenta/client/{backend/types → types}/evaluation_status_enum.py +0 -0
- /agenta/client/{backend/types → types}/evaluation_type.py +0 -0
- /agenta/client/{backend/types → types}/evaluator.py +0 -0
- /agenta/client/{backend/types → types}/evaluator_config.py +0 -0
- /agenta/client/{backend/types → types}/evaluator_mapping_output_interface.py +0 -0
- /agenta/client/{backend/types → types}/evaluator_output_interface.py +0 -0
- /agenta/client/{backend/types → types}/exception_dto.py +0 -0
- /agenta/client/{backend/types → types}/get_config_response.py +0 -0
- /agenta/client/{backend/types → types}/header_dto.py +0 -0
- /agenta/client/{backend/types → types}/http_validation_error.py +0 -0
- /agenta/client/{backend/types → types}/human_evaluation.py +0 -0
- /agenta/client/{backend/types → types}/human_evaluation_scenario.py +0 -0
- /agenta/client/{backend/types → types}/human_evaluation_scenario_input.py +0 -0
- /agenta/client/{backend/types → types}/human_evaluation_scenario_output.py +0 -0
- /agenta/client/{backend/types → types}/image.py +0 -0
- /agenta/client/{backend/types → types}/invite_request.py +0 -0
- /agenta/client/{backend/types → types}/legacy_analytics_response.py +0 -0
- /agenta/client/{backend/types → types}/legacy_data_point.py +0 -0
- /agenta/client/{backend/types → types}/legacy_scope_request.py +0 -0
- /agenta/client/{backend/types → types}/legacy_scopes_response.py +0 -0
- /agenta/client/{backend/types → types}/legacy_user_request.py +0 -0
- /agenta/client/{backend/types → types}/legacy_user_response.py +0 -0
- /agenta/client/{backend/types → types}/lifecycle_dto.py +0 -0
- /agenta/client/{backend/types → types}/link_dto.py +0 -0
- /agenta/client/{backend/types → types}/list_api_keys_response.py +0 -0
- /agenta/client/{backend/types → types}/llm_run_rate_limit.py +0 -0
- /agenta/client/{backend/types → types}/metrics_dto.py +0 -0
- /agenta/client/{backend/types → types}/new_testset.py +0 -0
- /agenta/client/{backend/types → types}/node_dto.py +0 -0
- /agenta/client/{backend/types → types}/node_type.py +0 -0
- /agenta/client/{backend/types → types}/o_tel_context_dto.py +0 -0
- /agenta/client/{backend/types → types}/o_tel_event_dto.py +0 -0
- /agenta/client/{backend/types → types}/o_tel_extra_dto.py +0 -0
- /agenta/client/{backend/types → types}/o_tel_link_dto.py +0 -0
- /agenta/client/{backend/types → types}/o_tel_span_dto.py +0 -0
- /agenta/client/{backend/types → types}/o_tel_span_kind.py +0 -0
- /agenta/client/{backend/types → types}/o_tel_spans_response.py +0 -0
- /agenta/client/{backend/types → types}/o_tel_status_code.py +0 -0
- /agenta/client/{backend/types → types}/organization.py +0 -0
- /agenta/client/{backend/types → types}/organization_membership_request.py +0 -0
- /agenta/client/{backend/types → types}/organization_output.py +0 -0
- /agenta/client/{backend/types → types}/organization_request.py +0 -0
- /agenta/client/{backend/types → types}/parent_dto.py +0 -0
- /agenta/client/{backend/types → types}/permission.py +0 -0
- /agenta/client/{backend/types → types}/project_membership_request.py +0 -0
- /agenta/client/{backend/types → types}/project_request.py +0 -0
- /agenta/client/{backend/types → types}/project_scope.py +0 -0
- /agenta/client/{backend/types → types}/projects_response.py +0 -0
- /agenta/client/{backend/types → types}/provider_key_dto.py +0 -0
- /agenta/client/{backend/types → types}/provider_kind.py +0 -0
- /agenta/client/{backend/types → types}/reference.py +0 -0
- /agenta/client/{backend/types → types}/reference_dto.py +0 -0
- /agenta/client/{backend/types → types}/reference_request_model.py +0 -0
- /agenta/client/{backend/types → types}/result.py +0 -0
- /agenta/client/{backend/types → types}/role.py +0 -0
- /agenta/client/{backend/types → types}/root_dto.py +0 -0
- /agenta/client/{backend/types → types}/scopes_response_model.py +0 -0
- /agenta/client/{backend/types → types}/score.py +0 -0
- /agenta/client/{backend/types → types}/secret_dto.py +0 -0
- /agenta/client/{backend/types → types}/secret_kind.py +0 -0
- /agenta/client/{backend/types → types}/secret_response_dto.py +0 -0
- /agenta/client/{backend/types → types}/simple_evaluation_output.py +0 -0
- /agenta/client/{backend/types → types}/span_dto.py +0 -0
- /agenta/client/{backend/types → types}/span_dto_nodes_value.py +0 -0
- /agenta/client/{backend/types → types}/status_code.py +0 -0
- /agenta/client/{backend/types → types}/status_dto.py +0 -0
- /agenta/client/{backend/types → types}/template.py +0 -0
- /agenta/client/{backend/types → types}/template_image_info.py +0 -0
- /agenta/client/{backend/types → types}/test_set_output_response.py +0 -0
- /agenta/client/{backend/types → types}/test_set_simple_response.py +0 -0
- /agenta/client/{backend/types → types}/time_dto.py +0 -0
- /agenta/client/{backend/types → types}/tree_dto.py +0 -0
- /agenta/client/{backend/types → types}/tree_type.py +0 -0
- /agenta/client/{backend/types → types}/update_app_output.py +0 -0
- /agenta/client/{backend/types → types}/uri.py +0 -0
- /agenta/client/{backend/types → types}/user_request.py +0 -0
- /agenta/client/{backend/types → types}/validation_error.py +0 -0
- /agenta/client/{backend/types → types}/validation_error_loc_item.py +0 -0
- /agenta/client/{backend/types → types}/variant_action.py +0 -0
- /agenta/client/{backend/types → types}/variant_action_enum.py +0 -0
- /agenta/client/{backend/types → types}/workspace_member_response.py +0 -0
- /agenta/client/{backend/types → types}/workspace_membership_request.py +0 -0
- /agenta/client/{backend/types → types}/workspace_permission.py +0 -0
- /agenta/client/{backend/types → types}/workspace_request.py +0 -0
- /agenta/client/{backend/types → types}/workspace_response.py +0 -0
- /agenta/client/{backend/types → types}/workspace_role.py +0 -0
- /agenta/client/{backend/types → types}/workspace_role_response.py +0 -0
- /agenta/client/{backend/variants → variants}/__init__.py +0 -0
- /agenta/client/{backend/variants → variants}/client.py +0 -0
- /agenta/client/{backend/variants → variants}/types/__init__.py +0 -0
- /agenta/client/{backend/variants → variants}/types/add_variant_from_base_and_config_response.py +0 -0
- /agenta/client/{backend/vault → vault}/__init__.py +0 -0
- /agenta/client/{backend/vault → vault}/client.py +0 -0
- {agenta-0.36.3.dist-info → agenta-0.36.5.dist-info}/WHEEL +0 -0
agenta/cli/helper.py
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import sys
|
|
3
|
-
import toml
|
|
4
|
-
import click
|
|
5
|
-
import questionary
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
from typing import Any, List, MutableMapping
|
|
8
|
-
from agenta.client.api_models import AppVariant
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
from typing import Any, Optional
|
|
12
|
-
from pathlib import Path
|
|
13
|
-
import toml
|
|
14
|
-
|
|
15
|
-
from agenta.client.backend.client import AgentaApi
|
|
16
|
-
|
|
17
|
-
BACKEND_URL_SUFFIX = os.environ.get("BACKEND_URL_SUFFIX", "api")
|
|
18
|
-
POSTHOG_KEY = os.environ.get(
|
|
19
|
-
"POSTHOG_KEY", "phc_hmVSxIjTW1REBHXgj2aw4HW9X6CXb6FzerBgP9XenC7"
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def get_global_config(var_name: str) -> Optional[Any]:
|
|
24
|
-
"""
|
|
25
|
-
Get the value of a global configuration variable.
|
|
26
|
-
|
|
27
|
-
Args:
|
|
28
|
-
var_name: the name of the variable to get
|
|
29
|
-
|
|
30
|
-
Returns:
|
|
31
|
-
the value of the variable, or None if it doesn't exist
|
|
32
|
-
"""
|
|
33
|
-
agenta_dir = Path.home() / ".agenta"
|
|
34
|
-
if not agenta_dir.exists():
|
|
35
|
-
return None
|
|
36
|
-
agenta_config_file = agenta_dir / "config.toml"
|
|
37
|
-
if not agenta_config_file.exists():
|
|
38
|
-
return None
|
|
39
|
-
global_config = toml.load(agenta_config_file)
|
|
40
|
-
if var_name not in global_config:
|
|
41
|
-
return None
|
|
42
|
-
return global_config[var_name]
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def set_global_config(var_name: str, var_value: Any) -> None:
|
|
46
|
-
"""
|
|
47
|
-
Set the value of a global configuration variable.
|
|
48
|
-
|
|
49
|
-
Args:
|
|
50
|
-
var_name: the name of the variable to set
|
|
51
|
-
var_value: the value to set the variable to
|
|
52
|
-
"""
|
|
53
|
-
agenta_dir = Path.home() / ".agenta"
|
|
54
|
-
if not agenta_dir.exists():
|
|
55
|
-
agenta_dir.mkdir(exist_ok=True)
|
|
56
|
-
agenta_config_file = agenta_dir / "config.toml"
|
|
57
|
-
if not agenta_config_file.exists():
|
|
58
|
-
config = {}
|
|
59
|
-
with agenta_config_file.open("w") as config_file:
|
|
60
|
-
toml.dump(config, config_file)
|
|
61
|
-
global_config = toml.load(agenta_config_file)
|
|
62
|
-
global_config[var_name] = var_value
|
|
63
|
-
with open(agenta_config_file, "w") as config_file:
|
|
64
|
-
toml.dump(global_config, config_file)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
def get_api_key(backend_host: str) -> str:
|
|
68
|
-
"""
|
|
69
|
-
Retrieve or request the API key for accessing the Agenta platform.
|
|
70
|
-
|
|
71
|
-
This function first looks for an existing API key in the global config file.
|
|
72
|
-
If found, it prompts the user to confirm whether they'd like to use that key.
|
|
73
|
-
If not found, it asks the user to input a new key.
|
|
74
|
-
|
|
75
|
-
Args:
|
|
76
|
-
backend_host (str): The URL of the backend host.
|
|
77
|
-
|
|
78
|
-
Returns:
|
|
79
|
-
str: The API key to be used for accessing the Agenta platform.
|
|
80
|
-
|
|
81
|
-
Raises:
|
|
82
|
-
SystemExit: If the user cancels the input by pressing Ctrl+C.
|
|
83
|
-
"""
|
|
84
|
-
|
|
85
|
-
api_key = get_global_config("api_key")
|
|
86
|
-
if api_key:
|
|
87
|
-
# API key exists in the config file, ask for confirmation
|
|
88
|
-
confirm_api_key = questionary.confirm(
|
|
89
|
-
f"API Key found: {api_key}\nDo you want to use this API Key?"
|
|
90
|
-
).ask()
|
|
91
|
-
|
|
92
|
-
if confirm_api_key:
|
|
93
|
-
return api_key
|
|
94
|
-
elif confirm_api_key is None: # User pressed Ctrl+C
|
|
95
|
-
sys.exit(0)
|
|
96
|
-
|
|
97
|
-
api_key = questionary.text(
|
|
98
|
-
f"(You can get your API Key here: {backend_host}/settings?tab=apiKeys) "
|
|
99
|
-
"Please provide your API key:"
|
|
100
|
-
).ask()
|
|
101
|
-
|
|
102
|
-
if api_key:
|
|
103
|
-
set_global_config("api_key", api_key.strip())
|
|
104
|
-
|
|
105
|
-
return api_key
|
|
106
|
-
elif api_key is None: # User pressed Ctrl+C
|
|
107
|
-
sys.exit(0)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
def init_telemetry_config() -> None:
|
|
111
|
-
if (
|
|
112
|
-
get_global_config("telemetry_tracking_enabled") is None
|
|
113
|
-
or get_global_config("telemetry_api_key") is None
|
|
114
|
-
):
|
|
115
|
-
set_global_config("telemetry_tracking_enabled", True)
|
|
116
|
-
set_global_config(
|
|
117
|
-
"telemetry_api_key",
|
|
118
|
-
POSTHOG_KEY,
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
def update_variants_from_backend(
|
|
123
|
-
app_id: str,
|
|
124
|
-
config: MutableMapping[str, Any],
|
|
125
|
-
host: str,
|
|
126
|
-
api_key: str = None,
|
|
127
|
-
) -> MutableMapping[str, Any]:
|
|
128
|
-
"""Reads the list of variants from the backend and updates the config accordingly
|
|
129
|
-
|
|
130
|
-
Arguments:
|
|
131
|
-
app_id -- the app id
|
|
132
|
-
config -- the config loaded using toml.load
|
|
133
|
-
api_key -- the api key to use for authentication
|
|
134
|
-
|
|
135
|
-
Returns:
|
|
136
|
-
a new config object later to be saved using toml.dump(config, config_file.open('w'))
|
|
137
|
-
"""
|
|
138
|
-
client = AgentaApi(
|
|
139
|
-
base_url=f"{host}/{BACKEND_URL_SUFFIX}",
|
|
140
|
-
api_key=api_key,
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
try:
|
|
144
|
-
variants: List[AppVariant] = client.apps.list_app_variants(app_id=app_id)
|
|
145
|
-
except Exception as ex:
|
|
146
|
-
raise ex
|
|
147
|
-
|
|
148
|
-
config["variants"] = [variant.variant_name for variant in variants]
|
|
149
|
-
config["variant_ids"] = [variant.variant_id for variant in variants]
|
|
150
|
-
return config
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
def update_config_from_backend(config_file: Path, host: str):
|
|
154
|
-
"""Updates the config file with new information from the backend
|
|
155
|
-
|
|
156
|
-
Arguments:
|
|
157
|
-
config_file -- the path to the config file
|
|
158
|
-
"""
|
|
159
|
-
assert config_file.exists(), "Config file does not exist!"
|
|
160
|
-
config = toml.load(config_file)
|
|
161
|
-
app_id = config["app_id"]
|
|
162
|
-
api_key = config.get("api_key", "")
|
|
163
|
-
if "variants" not in config:
|
|
164
|
-
config["variants"] = []
|
|
165
|
-
if "variant_ids" not in config:
|
|
166
|
-
config["variant_ids"] = []
|
|
167
|
-
config = update_variants_from_backend(app_id, config, host, api_key)
|
|
168
|
-
toml.dump(config, config_file.open("w"))
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
def display_app_variant(variant: AppVariant):
|
|
172
|
-
"""Prints a variant nicely in the terminal"""
|
|
173
|
-
click.echo(
|
|
174
|
-
click.style("App Name: ", bold=True, fg="green")
|
|
175
|
-
+ click.style(variant.app_name, fg="green")
|
|
176
|
-
)
|
|
177
|
-
click.echo(
|
|
178
|
-
click.style("Variant Name: ", bold=True, fg="blue")
|
|
179
|
-
+ click.style(variant.variant_name, fg="blue")
|
|
180
|
-
)
|
|
181
|
-
click.echo(click.style("Parameters: ", bold=True, fg="cyan"))
|
|
182
|
-
if variant.parameters:
|
|
183
|
-
for param, value in variant.parameters.items():
|
|
184
|
-
click.echo(
|
|
185
|
-
click.style(f" {param}: ", fg="cyan")
|
|
186
|
-
+ click.style(str(value), fg="cyan")
|
|
187
|
-
)
|
|
188
|
-
else:
|
|
189
|
-
click.echo(click.style(" Defaults from code", fg="cyan"))
|
|
190
|
-
if variant.previous_variant_name:
|
|
191
|
-
click.echo(
|
|
192
|
-
click.style("Template Variant Name: ", bold=True, fg="magenta")
|
|
193
|
-
+ click.style(variant.previous_variant_name, fg="magenta")
|
|
194
|
-
)
|
|
195
|
-
else:
|
|
196
|
-
click.echo(
|
|
197
|
-
click.style("Template Variant Name: ", bold=True, fg="magenta")
|
|
198
|
-
+ click.style("None", fg="magenta")
|
|
199
|
-
)
|
|
200
|
-
click.echo(
|
|
201
|
-
click.style("-" * 50, bold=True, fg="white")
|
|
202
|
-
) # a line for separating each variant
|
agenta/cli/main.py
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import re
|
|
3
|
-
import shutil
|
|
4
|
-
import sys
|
|
5
|
-
from typing import Union
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
|
|
8
|
-
import click
|
|
9
|
-
import questionary
|
|
10
|
-
import toml
|
|
11
|
-
|
|
12
|
-
from agenta.cli import helper
|
|
13
|
-
from agenta.cli import variant_configs
|
|
14
|
-
from agenta.cli import variant_commands
|
|
15
|
-
from agenta.cli import evaluation_commands
|
|
16
|
-
|
|
17
|
-
from agenta.client.backend.client import AgentaApi
|
|
18
|
-
|
|
19
|
-
BACKEND_URL_SUFFIX = os.environ.get("BACKEND_URL_SUFFIX", "api")
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def print_version(ctx, param, value):
|
|
23
|
-
if not value or ctx.resilient_parsing:
|
|
24
|
-
return
|
|
25
|
-
try:
|
|
26
|
-
try:
|
|
27
|
-
from importlib.metadata import PackageNotFoundError, version
|
|
28
|
-
except ImportError:
|
|
29
|
-
from importlib_metadata import PackageNotFoundError, version
|
|
30
|
-
package_version = version("agenta")
|
|
31
|
-
except PackageNotFoundError:
|
|
32
|
-
package_version = "package is not installed"
|
|
33
|
-
click.echo(f"Agenta CLI version: {package_version}")
|
|
34
|
-
ctx.exit()
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def check_latest_version() -> Union[str, None]:
|
|
38
|
-
import requests
|
|
39
|
-
|
|
40
|
-
try:
|
|
41
|
-
response = requests.get("https://pypi.org/pypi/agenta/json", timeout=360)
|
|
42
|
-
response.raise_for_status()
|
|
43
|
-
latest_version = response.json()["info"]["version"]
|
|
44
|
-
return latest_version
|
|
45
|
-
except (requests.RequestException, KeyError):
|
|
46
|
-
return None
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def notify_update(available_version: str):
|
|
50
|
-
import importlib.metadata
|
|
51
|
-
|
|
52
|
-
installed_version = importlib.metadata.version("agenta")
|
|
53
|
-
if available_version > installed_version:
|
|
54
|
-
click.echo(
|
|
55
|
-
click.style(
|
|
56
|
-
f"A new release of agenta is available: {installed_version} → {available_version}",
|
|
57
|
-
fg="yellow",
|
|
58
|
-
)
|
|
59
|
-
)
|
|
60
|
-
click.echo(
|
|
61
|
-
click.style("To upgrade, run: pip install --upgrade agenta", fg="yellow")
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
@click.group()
|
|
66
|
-
@click.option(
|
|
67
|
-
"--version",
|
|
68
|
-
"-v",
|
|
69
|
-
is_flag=True,
|
|
70
|
-
callback=print_version,
|
|
71
|
-
expose_value=False,
|
|
72
|
-
is_eager=True,
|
|
73
|
-
)
|
|
74
|
-
def cli():
|
|
75
|
-
latest_version = check_latest_version()
|
|
76
|
-
if latest_version:
|
|
77
|
-
notify_update(latest_version)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
@click.command()
|
|
81
|
-
@click.option("--app-name", "--app_name", default=None)
|
|
82
|
-
@click.option("--backend-host", "backend_host", default=None)
|
|
83
|
-
def init(app_name: str, backend_host: str):
|
|
84
|
-
"""Initialize a new Agenta app with the template files."""
|
|
85
|
-
|
|
86
|
-
init_option = "Blank App" if backend_host != "" and app_name != "" else ""
|
|
87
|
-
|
|
88
|
-
api_key = os.getenv("AGENTA_API_KEY")
|
|
89
|
-
|
|
90
|
-
if not app_name:
|
|
91
|
-
while True:
|
|
92
|
-
app_name = questionary.text("Please enter the app name").ask()
|
|
93
|
-
if app_name and re.match("^[a-zA-Z0-9_-]+$", app_name):
|
|
94
|
-
break
|
|
95
|
-
else:
|
|
96
|
-
if app_name is None: # User pressed Ctrl+C
|
|
97
|
-
sys.exit(0)
|
|
98
|
-
else:
|
|
99
|
-
print(
|
|
100
|
-
"Invalid input. Please use only alphanumeric characters without spaces."
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
try:
|
|
104
|
-
backend_hosts = {
|
|
105
|
-
"https://cloud.agenta.ai": "On agenta cloud",
|
|
106
|
-
"http://localhost": "On my local machine",
|
|
107
|
-
}
|
|
108
|
-
where_question = backend_hosts.get(backend_host, "On a remote machine")
|
|
109
|
-
if not backend_host:
|
|
110
|
-
where_question = questionary.select(
|
|
111
|
-
"Where are you running agenta?",
|
|
112
|
-
choices=[
|
|
113
|
-
"On agenta cloud",
|
|
114
|
-
"On my local machine",
|
|
115
|
-
"On a remote machine",
|
|
116
|
-
],
|
|
117
|
-
).ask()
|
|
118
|
-
|
|
119
|
-
if where_question == "On my local machine":
|
|
120
|
-
backend_host = "http://localhost"
|
|
121
|
-
elif where_question == "On a remote machine":
|
|
122
|
-
backend_host = questionary.text(
|
|
123
|
-
"Please provide the IP or URL of your remote host"
|
|
124
|
-
).ask()
|
|
125
|
-
elif where_question == "On agenta cloud":
|
|
126
|
-
global_backend_host = helper.get_global_config("host")
|
|
127
|
-
if global_backend_host:
|
|
128
|
-
backend_host = global_backend_host
|
|
129
|
-
else:
|
|
130
|
-
backend_host = "https://cloud.agenta.ai"
|
|
131
|
-
|
|
132
|
-
if not api_key:
|
|
133
|
-
api_key = helper.get_api_key(backend_host)
|
|
134
|
-
|
|
135
|
-
elif where_question is None: # User pressed Ctrl+C
|
|
136
|
-
sys.exit(0)
|
|
137
|
-
backend_host = (
|
|
138
|
-
backend_host
|
|
139
|
-
if backend_host.startswith("http://") or backend_host.startswith("https://")
|
|
140
|
-
else "http://" + backend_host
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
# initialize the client with the backend url and api key
|
|
144
|
-
client = AgentaApi(
|
|
145
|
-
base_url=f"{backend_host}/{BACKEND_URL_SUFFIX}",
|
|
146
|
-
api_key=api_key if where_question == "On agenta cloud" else "",
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
# Get app_id after creating new app in the backend server
|
|
150
|
-
try:
|
|
151
|
-
app_id = client.apps.create_app(app_name=app_name).app_id
|
|
152
|
-
except Exception as ex:
|
|
153
|
-
click.echo(click.style(f"Error: {ex}", fg="red"))
|
|
154
|
-
sys.exit(1)
|
|
155
|
-
|
|
156
|
-
# Set app toml configuration
|
|
157
|
-
config = {
|
|
158
|
-
"app_name": app_name,
|
|
159
|
-
"app_id": app_id,
|
|
160
|
-
"backend_host": backend_host,
|
|
161
|
-
"api_key": api_key if where_question == "On agenta cloud" else None,
|
|
162
|
-
}
|
|
163
|
-
with open("config.toml", "w") as config_file:
|
|
164
|
-
toml.dump(config, config_file)
|
|
165
|
-
|
|
166
|
-
# Ask for init option
|
|
167
|
-
if not init_option:
|
|
168
|
-
init_option = questionary.select(
|
|
169
|
-
"How do you want to initialize your app?",
|
|
170
|
-
choices=["Blank App", "Start from template"],
|
|
171
|
-
).ask()
|
|
172
|
-
|
|
173
|
-
# If the user selected the second option, show a list of available templates
|
|
174
|
-
if init_option == "Start from template":
|
|
175
|
-
current_dir = Path.cwd()
|
|
176
|
-
template_dir = Path(__file__).parent.parent / "templates"
|
|
177
|
-
templates = [
|
|
178
|
-
folder.name for folder in template_dir.iterdir() if folder.is_dir()
|
|
179
|
-
]
|
|
180
|
-
template_desc = [
|
|
181
|
-
toml.load((template_dir / name / "template.toml"))["short_desc"]
|
|
182
|
-
for name in templates
|
|
183
|
-
]
|
|
184
|
-
|
|
185
|
-
# Show the templates to the user
|
|
186
|
-
template = questionary.select(
|
|
187
|
-
"Which template do you want to use?",
|
|
188
|
-
choices=[
|
|
189
|
-
questionary.Choice(
|
|
190
|
-
title=f"{template} - {template_desc}", value=template
|
|
191
|
-
)
|
|
192
|
-
for template, template_desc in zip(templates, template_desc)
|
|
193
|
-
],
|
|
194
|
-
).ask()
|
|
195
|
-
|
|
196
|
-
# Copy the template files to the current directory
|
|
197
|
-
chosen_template_dir = template_dir / template
|
|
198
|
-
for file in chosen_template_dir.glob("*"):
|
|
199
|
-
if file.name != "template.toml" and not file.is_dir():
|
|
200
|
-
shutil.copy(file, current_dir / file.name)
|
|
201
|
-
elif init_option is None: # User pressed Ctrl+C
|
|
202
|
-
sys.exit(0)
|
|
203
|
-
|
|
204
|
-
# Create a .gitignore file and add some default environment folder names to it
|
|
205
|
-
gitignore_content = (
|
|
206
|
-
"# Environments \nenv/\nvenv/\nENV/\nenv.bak/\nvenv.bak/\nmyenv/\n"
|
|
207
|
-
)
|
|
208
|
-
if not os.path.exists(".agentaignore"):
|
|
209
|
-
with open(".agentaignore", "w") as gitignore_file:
|
|
210
|
-
gitignore_file.write(gitignore_content)
|
|
211
|
-
|
|
212
|
-
click.echo("App initialized successfully")
|
|
213
|
-
if init_option == "Start from template":
|
|
214
|
-
click.echo(
|
|
215
|
-
"Please check the README.md for further instructions to setup the template."
|
|
216
|
-
)
|
|
217
|
-
except Exception as ex:
|
|
218
|
-
click.echo(click.style(f"Error: {ex}", fg="red"))
|
|
219
|
-
sys.exit(1)
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
# Add the commands to the CLI group
|
|
223
|
-
cli.add_command(init)
|
|
224
|
-
cli.add_command(variant_configs.config)
|
|
225
|
-
cli.add_command(variant_commands.variant)
|
|
226
|
-
cli.add_command(evaluation_commands.evaluation)
|
|
227
|
-
|
|
228
|
-
if __name__ == "__main__":
|
|
229
|
-
cli()
|
agenta/cli/telemetry.py
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# Stdlib Imports
|
|
2
|
-
from uuid import uuid4
|
|
3
|
-
|
|
4
|
-
# Own Imports
|
|
5
|
-
from agenta.cli import helper
|
|
6
|
-
|
|
7
|
-
# Third party Imports
|
|
8
|
-
from posthog import Posthog
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
# Load telemetry configuration
|
|
12
|
-
helper.init_telemetry_config()
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class EventTracking(Posthog):
|
|
16
|
-
_instance = None
|
|
17
|
-
|
|
18
|
-
def __new__(cls, *args, **kwargs):
|
|
19
|
-
if cls._instance is None:
|
|
20
|
-
cls._instance = super().__new__(cls)
|
|
21
|
-
return cls._instance
|
|
22
|
-
|
|
23
|
-
def __init__(self, api_key: str, host: str) -> None:
|
|
24
|
-
super(Posthog, self).__init__(api_key, host)
|
|
25
|
-
|
|
26
|
-
def capture_event(
|
|
27
|
-
self,
|
|
28
|
-
event_name: str,
|
|
29
|
-
body: dict,
|
|
30
|
-
) -> None:
|
|
31
|
-
"""
|
|
32
|
-
Captures an event.
|
|
33
|
-
|
|
34
|
-
Args:
|
|
35
|
-
event_name (str): The name of the event being captured.
|
|
36
|
-
body (dict): Contains the data associated with the event being captured.
|
|
37
|
-
"""
|
|
38
|
-
|
|
39
|
-
# A unique identifier for the user or entity associated with the event
|
|
40
|
-
distinct_id = helper.get_global_config("telemetry_distinct_id")
|
|
41
|
-
if not distinct_id:
|
|
42
|
-
distinct_id = uuid4()
|
|
43
|
-
helper.set_global_config("telemetry_distinct_id", str(distinct_id))
|
|
44
|
-
self.capture(distinct_id, event_name, body)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
# Initialize event tracking
|
|
48
|
-
event_track = EventTracking(
|
|
49
|
-
helper.get_global_config("telemetry_api_key"), "https://app.posthog.com"
|
|
50
|
-
)
|