agenta 0.15.0a2__tar.gz → 0.15.0a4__tar.gz
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-0.15.0a2 → agenta-0.15.0a4}/PKG-INFO +1 -1
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/docker/docker_utils.py +1 -1
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/sdk/agenta_init.py +78 -72
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/sdk/decorators/llm_entrypoint.py +12 -19
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/sdk/decorators/tracing.py +10 -2
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/sdk/tracing/llm_tracing.py +7 -9
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/sdk/tracing/logger.py +1 -1
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/sdk/types.py +3 -2
- {agenta-0.15.0a2 → agenta-0.15.0a4}/pyproject.toml +1 -1
- {agenta-0.15.0a2 → agenta-0.15.0a4}/README.md +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/cli/evaluation_commands.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/cli/helper.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/cli/main.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/cli/telemetry.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/cli/variant_commands.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/cli/variant_configs.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/Readme.md +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/api.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/api_models.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/client.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/core/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/core/api_error.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/core/client_wrapper.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/core/datetime_utils.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/core/jsonable_encoder.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/core/remove_none_from_dict.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/errors/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/errors/unprocessable_entity_error.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/apps/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/apps/client.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/bases/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/bases/client.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/configs/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/configs/client.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/containers/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/containers/client.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/containers/types/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/containers/types/container_templates_response.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/environments/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/environments/client.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/evaluations/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/evaluations/client.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/evaluators/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/evaluators/client.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/observability/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/observability/client.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/testsets/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/testsets/client.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/variants/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/variants/client.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/variants/types/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/variants/types/add_variant_from_base_and_config_response.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/aggregated_result.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/aggregated_result_evaluator_config.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/app.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/app_variant_response.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/app_variant_revision.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/base_output.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/body_import_testset.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/config_db.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/create_app_output.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/create_span.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/create_trace_response.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/docker_env_vars.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/environment_output.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/environment_output_extended.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/environment_revision.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/error.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/evaluation.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/evaluation_scenario.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/evaluation_scenario_input.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/evaluation_scenario_output.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/evaluation_scenario_result.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/evaluation_scenario_score_update.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/evaluation_status_enum.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/evaluation_type.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/evaluation_webhook.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/evaluator.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/evaluator_config.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/feedback.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/get_config_response.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/http_validation_error.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/human_evaluation.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/human_evaluation_scenario.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/human_evaluation_scenario_input.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/human_evaluation_scenario_output.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/human_evaluation_scenario_update.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/human_evaluation_update.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/image.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/invite_request.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/list_api_keys_response.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/llm_run_rate_limit.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/llm_tokens.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/new_human_evaluation.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/new_testset.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/organization.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/organization_output.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/permission.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/result.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/score.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/simple_evaluation_output.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/span.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/span_detail.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/span_kind.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/span_status_code.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/span_variant.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/template.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/template_image_info.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/test_set_output_response.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/test_set_simple_response.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/trace_detail.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/uri.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/validation_error.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/validation_error_loc_item.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/variant_action.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/variant_action_enum.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/with_pagination.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/workspace_member_response.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/workspace_permission.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/workspace_response.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/workspace_role.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/workspace_role_response.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/client.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/exceptions.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/config.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/config.toml +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/docker/docker-assets/Dockerfile.cloud.template +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/docker/docker-assets/Dockerfile.template +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/docker/docker-assets/README.md +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/docker/docker-assets/entrypoint.sh +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/docker/docker-assets/lambda_function.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/docker/docker-assets/main.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/sdk/__init__.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/sdk/client.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/sdk/context.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/sdk/decorators/base.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/sdk/router.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/sdk/tracing/context_manager.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/sdk/tracing/tasks_manager.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/sdk/utils/globals.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/sdk/utils/helper/openai_cost.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/sdk/utils/preinit.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/templates/compose_email/README.md +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/templates/compose_email/app.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/templates/compose_email/env.example +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/templates/compose_email/requirements.txt +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/templates/compose_email/template.toml +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/templates/extract_data_to_json/README.md +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/templates/extract_data_to_json/app.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/templates/extract_data_to_json/env.example +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/templates/extract_data_to_json/requirements.txt +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/templates/extract_data_to_json/template.toml +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/templates/simple_prompt/README.md +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/templates/simple_prompt/app.py +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/templates/simple_prompt/env.example +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/templates/simple_prompt/requirements.txt +0 -0
- {agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/templates/simple_prompt/template.toml +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import logging
|
|
3
|
+
import toml
|
|
3
4
|
from typing import Optional
|
|
4
5
|
|
|
5
6
|
from agenta.sdk.utils.globals import set_global
|
|
@@ -40,85 +41,69 @@ class AgentaSingleton:
|
|
|
40
41
|
app_id: Optional[str] = None,
|
|
41
42
|
host: Optional[str] = None,
|
|
42
43
|
api_key: Optional[str] = None,
|
|
44
|
+
config_fname: Optional[str] = None,
|
|
43
45
|
) -> None:
|
|
44
46
|
"""Main function to initialize the singleton.
|
|
45
47
|
|
|
46
|
-
Initializes the singleton with the given `
|
|
47
|
-
|
|
48
|
+
Initializes the singleton with the given `app_id`, `host`, and `api_key`. The order of precedence for these variables is:
|
|
49
|
+
1. Explicit argument provided in the function call.
|
|
50
|
+
2. Value from the configuration file specified by `config_fname`.
|
|
51
|
+
3. Environment variables.
|
|
52
|
+
|
|
53
|
+
Examples:
|
|
54
|
+
ag.init(app_id="xxxx", api_key="xxx")
|
|
55
|
+
ag.init(config_fname="config.toml")
|
|
56
|
+
ag.init() #assuming env vars are set
|
|
48
57
|
|
|
49
58
|
Args:
|
|
50
|
-
app_id (Optional[str]): ID of the Agenta application. Defaults to None. If not provided, will look for "
|
|
51
|
-
host (Optional[str]): Host name of the backend server. Defaults to None. If not provided, will look for "AGENTA_HOST" in environment variables.
|
|
52
|
-
api_key (Optional[str]): API Key to use with the host of the backend server.
|
|
53
|
-
|
|
59
|
+
app_id (Optional[str]): ID of the Agenta application. Defaults to None. If not provided, will look for "app_id" in the config file, then "AGENTA_APP_ID" in environment variables.
|
|
60
|
+
host (Optional[str]): Host name of the backend server. Defaults to None. If not provided, will look for "backend_host" in the config file, then "AGENTA_HOST" in environment variables.
|
|
61
|
+
api_key (Optional[str]): API Key to use with the host of the backend server. Defaults to None. If not provided, will look for "api_key" in the config file, then "AGENTA_API_KEY" in environment variables.
|
|
62
|
+
config_fname (Optional[str]): Path to the configuration file (relative or absolute). Defaults to None.
|
|
54
63
|
|
|
55
64
|
Raises:
|
|
56
|
-
ValueError: If `
|
|
65
|
+
ValueError: If `app_id` is not specified either as an argument, in the config file, or in the environment variables.
|
|
57
66
|
"""
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
app_id = app_id or os.environ.get("AGENTA_APP_ID")
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
config = {}
|
|
68
|
+
if config_fname:
|
|
69
|
+
config = toml.load(config_fname)
|
|
70
|
+
|
|
71
|
+
self.app_id = app_id or config.get("app_id") or os.environ.get("AGENTA_APP_ID")
|
|
72
|
+
self.host = (
|
|
73
|
+
host
|
|
74
|
+
or config.get("backend_host")
|
|
75
|
+
or os.environ.get("AGENTA_HOST", "https://cloud.agenta.ai")
|
|
76
|
+
)
|
|
77
|
+
self.api_key = (
|
|
78
|
+
api_key or config.get("api_key") or os.environ.get("AGENTA_API_KEY")
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
if not self.app_id:
|
|
82
|
+
raise ValueError(
|
|
83
|
+
"App ID must be specified. You can provide it in one of the following ways:\n"
|
|
84
|
+
"1. As an argument when calling ag.init(app_id='your_app_id').\n"
|
|
85
|
+
"2. In the configuration file specified by config_fname.\n"
|
|
86
|
+
"3. As an environment variable 'AGENTA_APP_ID'."
|
|
87
|
+
)
|
|
88
|
+
self.base_id = os.environ.get("AGENTA_BASE_ID")
|
|
89
|
+
if self.base_id is None:
|
|
69
90
|
print(
|
|
70
|
-
|
|
91
|
+
"Warning: Your configuration will not be saved permanently since base_id is not provided."
|
|
71
92
|
)
|
|
72
|
-
else:
|
|
73
|
-
try:
|
|
74
|
-
base_id = self.get_app_base(app_id, base_name) # type: ignore
|
|
75
|
-
except Exception as ex:
|
|
76
|
-
raise APIRequestError(
|
|
77
|
-
f"Failed to get base id and/or app_id from the server with error: {ex}"
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
self.app_id = app_id
|
|
81
|
-
self.base_id = base_id
|
|
82
|
-
self.variant_id = os.environ.get("AGENTA_VARIANT_ID")
|
|
83
|
-
self.variant_name = os.environ.get("AGENTA_VARIANT_NAME")
|
|
84
|
-
self.config = Config(base_id=self.base_id, host=self.host, api_key=self.api_key) # type: ignore
|
|
85
|
-
|
|
86
|
-
def get_app_base(self, app_id: str, base_name: str) -> str:
|
|
87
|
-
bases = self.client.bases.list_bases(app_id=app_id, base_name=base_name)
|
|
88
|
-
if len(bases) == 0:
|
|
89
|
-
raise APIRequestError(f"No base was found for the app {app_id}")
|
|
90
|
-
return bases[0].base_id
|
|
91
|
-
|
|
92
|
-
def get_current_config(self):
|
|
93
|
-
"""
|
|
94
|
-
Retrieves the current active configuration
|
|
95
|
-
"""
|
|
96
93
|
|
|
97
|
-
|
|
98
|
-
raise RuntimeError("AgentaSingleton has not been initialized")
|
|
99
|
-
return self._config_data
|
|
94
|
+
self.config = Config(base_id=self.base_id, host=self.host) # type: ignore
|
|
100
95
|
|
|
101
96
|
|
|
102
97
|
class Config:
|
|
103
|
-
def __init__(self, base_id: str, host: str, api_key: str):
|
|
98
|
+
def __init__(self, base_id: str, host: str, api_key: str = ""):
|
|
104
99
|
self.base_id = base_id
|
|
105
100
|
self.host = host
|
|
106
|
-
self.api_key = api_key
|
|
107
101
|
|
|
108
102
|
if base_id is None or host is None:
|
|
109
103
|
self.persist = False
|
|
110
104
|
else:
|
|
111
105
|
self.persist = True
|
|
112
|
-
|
|
113
|
-
@property
|
|
114
|
-
def client(self):
|
|
115
|
-
"""API Backend client.
|
|
116
|
-
|
|
117
|
-
Returns:
|
|
118
|
-
AgentaAPI: instance of agenta api backend
|
|
119
|
-
"""
|
|
120
|
-
|
|
121
|
-
return AgentaApi(base_url=self.host + "/api", api_key=self.api_key)
|
|
106
|
+
self.client = AgentaApi(base_url=self.host + "/api", api_key=api_key)
|
|
122
107
|
|
|
123
108
|
def register_default(self, overwrite=False, **kwargs):
|
|
124
109
|
"""alias for default"""
|
|
@@ -137,7 +122,7 @@ class Config:
|
|
|
137
122
|
self.push(config_name="default", overwrite=overwrite, **kwargs)
|
|
138
123
|
except Exception as ex:
|
|
139
124
|
logger.warning(
|
|
140
|
-
"Unable to push the default configuration to the server."
|
|
125
|
+
"Unable to push the default configuration to the server. %s", str(ex)
|
|
141
126
|
)
|
|
142
127
|
|
|
143
128
|
def push(self, config_name: str, overwrite=True, **kwargs):
|
|
@@ -158,7 +143,7 @@ class Config:
|
|
|
158
143
|
)
|
|
159
144
|
except Exception as ex:
|
|
160
145
|
logger.warning(
|
|
161
|
-
"Failed to push the configuration to the server with error: "
|
|
146
|
+
"Failed to push the configuration to the server with error: %s", ex
|
|
162
147
|
)
|
|
163
148
|
|
|
164
149
|
def pull(
|
|
@@ -168,7 +153,7 @@ class Config:
|
|
|
168
153
|
if not self.persist and (
|
|
169
154
|
config_name != "default" or environment_name is not None
|
|
170
155
|
):
|
|
171
|
-
raise
|
|
156
|
+
raise ValueError(
|
|
172
157
|
"Cannot pull the configuration from the server since the app_name and base_name are not provided."
|
|
173
158
|
)
|
|
174
159
|
if self.persist:
|
|
@@ -185,13 +170,13 @@ class Config:
|
|
|
185
170
|
)
|
|
186
171
|
except Exception as ex:
|
|
187
172
|
logger.warning(
|
|
188
|
-
"Failed to pull the configuration from the server with error: "
|
|
189
|
-
|
|
173
|
+
"Failed to pull the configuration from the server with error: %s",
|
|
174
|
+
str(ex),
|
|
190
175
|
)
|
|
191
176
|
try:
|
|
192
177
|
self.set(**{"current_version": config.current_version, **config.parameters})
|
|
193
178
|
except Exception as ex:
|
|
194
|
-
logger.warning("Failed to set the configuration with error: "
|
|
179
|
+
logger.warning("Failed to set the configuration with error: %s", str(ex))
|
|
195
180
|
|
|
196
181
|
def all(self):
|
|
197
182
|
"""Returns all the parameters for the app variant"""
|
|
@@ -199,7 +184,15 @@ class Config:
|
|
|
199
184
|
k: v
|
|
200
185
|
for k, v in self.__dict__.items()
|
|
201
186
|
if k
|
|
202
|
-
not in [
|
|
187
|
+
not in [
|
|
188
|
+
"app_name",
|
|
189
|
+
"base_name",
|
|
190
|
+
"host",
|
|
191
|
+
"base_id",
|
|
192
|
+
"api_key",
|
|
193
|
+
"persist",
|
|
194
|
+
"client",
|
|
195
|
+
]
|
|
203
196
|
}
|
|
204
197
|
|
|
205
198
|
# function to set the parameters for the app variant
|
|
@@ -226,24 +219,37 @@ def init(
|
|
|
226
219
|
app_id: Optional[str] = None,
|
|
227
220
|
host: Optional[str] = None,
|
|
228
221
|
api_key: Optional[str] = None,
|
|
222
|
+
config_fname: Optional[str] = None,
|
|
229
223
|
max_workers: Optional[int] = None,
|
|
230
224
|
):
|
|
231
|
-
"""Main function to
|
|
225
|
+
"""Main function to initialize the agenta sdk.
|
|
226
|
+
|
|
227
|
+
Initializes agenta with the given `app_id`, `host`, and `api_key`. The order of precedence for these variables is:
|
|
228
|
+
1. Explicit argument provided in the function call.
|
|
229
|
+
2. Value from the configuration file specified by `config_fname`.
|
|
230
|
+
3. Environment variables.
|
|
231
|
+
|
|
232
|
+
- `app_id` is a required parameter (to be specified in one of the above ways)
|
|
233
|
+
- `host` is optional and defaults to "https://cloud.agenta.ai"
|
|
234
|
+
- `api_key` is optional and defaults to "". It is required only when using cloud or enterprise version of agenta.
|
|
235
|
+
|
|
232
236
|
|
|
233
237
|
Args:
|
|
234
|
-
app_id (str):
|
|
235
|
-
host (str):
|
|
236
|
-
api_key (str):
|
|
238
|
+
app_id (Optional[str]): ID of the Agenta application. Defaults to None. If not provided, will look for "app_id" in the config file, then "AGENTA_APP_ID" in environment variables.
|
|
239
|
+
host (Optional[str]): Host name of the backend server. Defaults to None. If not provided, will look for "backend_host" in the config file, then "AGENTA_HOST" in environment variables.
|
|
240
|
+
api_key (Optional[str]): API Key to use with the host of the backend server. Defaults to None. If not provided, will look for "api_key" in the config file, then "AGENTA_API_KEY" in environment variables.
|
|
241
|
+
config_fname (Optional[str]): Path to the configuration file. Defaults to None.
|
|
242
|
+
|
|
243
|
+
Raises:
|
|
244
|
+
ValueError: If `app_id` is not specified either as an argument, in the config file, or in the environment variables.
|
|
237
245
|
"""
|
|
238
246
|
|
|
239
247
|
singleton = AgentaSingleton()
|
|
240
248
|
|
|
241
|
-
singleton.init(app_id=app_id, host=host, api_key=api_key)
|
|
249
|
+
singleton.init(app_id=app_id, host=host, api_key=api_key, config_fname=config_fname)
|
|
242
250
|
tracing = Tracing(
|
|
243
251
|
host=singleton.host, # type: ignore
|
|
244
252
|
app_id=singleton.app_id, # type: ignore
|
|
245
|
-
variant_id=singleton.variant_id, # type: ignore
|
|
246
|
-
variant_name=singleton.variant_name,
|
|
247
253
|
api_key=singleton.api_key,
|
|
248
254
|
max_workers=max_workers,
|
|
249
255
|
)
|
|
@@ -55,20 +55,18 @@ app.include_router(router, prefix="")
|
|
|
55
55
|
class entrypoint(BaseDecorator):
|
|
56
56
|
"""Decorator class to wrap a function for HTTP POST, terminal exposure and enable tracing.
|
|
57
57
|
|
|
58
|
-
Args:
|
|
59
|
-
BaseDecorator (object): base decorator class
|
|
60
58
|
|
|
61
59
|
Example:
|
|
62
60
|
```python
|
|
63
61
|
import agenta as ag
|
|
64
62
|
|
|
65
|
-
@ag.entrypoint
|
|
63
|
+
@ag.entrypoint
|
|
66
64
|
async def chain_of_prompts_llm(prompt: str):
|
|
67
65
|
return ...
|
|
68
66
|
```
|
|
69
67
|
"""
|
|
70
68
|
|
|
71
|
-
def
|
|
69
|
+
def __init__(self, func: Callable[..., Any]):
|
|
72
70
|
endpoint_name = "generate"
|
|
73
71
|
func_signature = inspect.signature(func)
|
|
74
72
|
config_params = agenta.config.all()
|
|
@@ -134,13 +132,12 @@ class entrypoint(BaseDecorator):
|
|
|
134
132
|
)
|
|
135
133
|
|
|
136
134
|
if self.is_main_script(func):
|
|
137
|
-
|
|
135
|
+
self.handle_terminal_run(
|
|
138
136
|
func,
|
|
139
137
|
func_signature.parameters, # type: ignore
|
|
140
138
|
config_params,
|
|
141
139
|
ingestible_files,
|
|
142
140
|
)
|
|
143
|
-
return result
|
|
144
141
|
|
|
145
142
|
def extract_ingestible_files(
|
|
146
143
|
self,
|
|
@@ -205,9 +202,16 @@ class entrypoint(BaseDecorator):
|
|
|
205
202
|
return FuncResponse(**result, latency=round(latency, 4))
|
|
206
203
|
if isinstance(result, str):
|
|
207
204
|
return FuncResponse(message=result, latency=round(latency, 4)) # type: ignore
|
|
205
|
+
if isinstance(result, int) or isinstance(result, float):
|
|
206
|
+
return FuncResponse(message=str(result), latency=round(latency, 4))
|
|
207
|
+
if result is None:
|
|
208
|
+
return FuncResponse(
|
|
209
|
+
message="Function executed successfully, but did return None. \n Are you sure you did not forget to return a value?",
|
|
210
|
+
latency=round(latency, 4),
|
|
211
|
+
)
|
|
208
212
|
except Exception as e:
|
|
209
213
|
self.handle_exception(e)
|
|
210
|
-
return FuncResponse(message="Unexpected error occurred", latency=0) # type: ignore
|
|
214
|
+
return FuncResponse(message="Unexpected error occurred when calling the @entrypoing decorated function", latency=0) # type: ignore
|
|
211
215
|
|
|
212
216
|
def handle_exception(self, e: Exception):
|
|
213
217
|
"""Handle exceptions."""
|
|
@@ -322,17 +326,7 @@ class entrypoint(BaseDecorator):
|
|
|
322
326
|
if is_main_script(my_function):
|
|
323
327
|
print("This is the main script.")
|
|
324
328
|
"""
|
|
325
|
-
|
|
326
|
-
# this ensures that when we call main.py, it starts the fastapi server
|
|
327
|
-
if os.path.splitext(os.path.basename(sys.argv[0]))[0] == "main":
|
|
328
|
-
return False
|
|
329
|
-
|
|
330
|
-
# the function that gets passed to entrypoint will always be called from sdk/decorators/tracing.py
|
|
331
|
-
if os.path.splitext(os.path.basename(inspect.getfile(func)))[0] == "tracing":
|
|
332
|
-
return True
|
|
333
|
-
|
|
334
|
-
# same behaviour as the first single-line comment above
|
|
335
|
-
return False
|
|
329
|
+
return func.__module__ == "__main__"
|
|
336
330
|
|
|
337
331
|
def handle_terminal_run(
|
|
338
332
|
self,
|
|
@@ -404,7 +398,6 @@ class entrypoint(BaseDecorator):
|
|
|
404
398
|
print(
|
|
405
399
|
f"\n========== Result ==========\n\nMessage: {result.message}\nCost: {result.cost}\nToken Usage: {result.usage}"
|
|
406
400
|
)
|
|
407
|
-
return result
|
|
408
401
|
|
|
409
402
|
def override_schema(
|
|
410
403
|
self, openapi_schema: dict, func_name: str, endpoint: str, params: dict
|
|
@@ -43,9 +43,13 @@ class instrument(BaseDecorator):
|
|
|
43
43
|
@wraps(func)
|
|
44
44
|
async def async_wrapper(*args, **kwargs):
|
|
45
45
|
result = None
|
|
46
|
+
func_args = inspect.getfullargspec(func).args
|
|
47
|
+
input_dict = {name: value for name, value in zip(func_args, args)}
|
|
48
|
+
input_dict.update(kwargs)
|
|
49
|
+
|
|
46
50
|
span = self.tracing.start_span(
|
|
47
51
|
name=func.__name__,
|
|
48
|
-
input=
|
|
52
|
+
input=input_dict,
|
|
49
53
|
spankind=self.spankind,
|
|
50
54
|
config=self.config,
|
|
51
55
|
)
|
|
@@ -67,9 +71,13 @@ class instrument(BaseDecorator):
|
|
|
67
71
|
@wraps(func)
|
|
68
72
|
def sync_wrapper(*args, **kwargs):
|
|
69
73
|
result = None
|
|
74
|
+
func_args = inspect.getfullargspec(func).args
|
|
75
|
+
input_dict = {name: value for name, value in zip(func_args, args)}
|
|
76
|
+
input_dict.update(kwargs)
|
|
77
|
+
|
|
70
78
|
span = self.tracing.start_span(
|
|
71
79
|
name=func.__name__,
|
|
72
|
-
input=
|
|
80
|
+
input=input_dict,
|
|
73
81
|
spankind=self.spankind,
|
|
74
82
|
config=self.config,
|
|
75
83
|
)
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
# Stdlib Imports
|
|
2
1
|
import os
|
|
3
2
|
from threading import Lock
|
|
4
3
|
from datetime import datetime, timezone
|
|
5
4
|
from typing import Optional, Dict, Any, List, Union
|
|
6
5
|
|
|
7
|
-
# Own Imports
|
|
8
6
|
from agenta.sdk.tracing.logger import llm_logger
|
|
9
7
|
from agenta.sdk.tracing.tasks_manager import TaskQueue
|
|
10
8
|
from agenta.client.backend.client import AsyncAgentaApi
|
|
11
9
|
from agenta.client.backend.client import AsyncObservabilityClient
|
|
12
10
|
from agenta.client.backend.types.create_span import CreateSpan, SpanKind, SpanStatusCode
|
|
13
11
|
|
|
14
|
-
# Third Party Imports
|
|
15
12
|
from bson.objectid import ObjectId
|
|
16
13
|
|
|
14
|
+
VARIANT_TRACKING_FEATURE_FLAG = False
|
|
15
|
+
|
|
17
16
|
|
|
18
17
|
class SingletonMeta(type):
|
|
19
18
|
"""
|
|
@@ -58,8 +57,6 @@ class Tracing(metaclass=SingletonMeta):
|
|
|
58
57
|
self,
|
|
59
58
|
host: str,
|
|
60
59
|
app_id: str,
|
|
61
|
-
variant_id: Optional[str] = None,
|
|
62
|
-
variant_name: Optional[str] = None,
|
|
63
60
|
api_key: Optional[str] = None,
|
|
64
61
|
max_workers: Optional[int] = None,
|
|
65
62
|
):
|
|
@@ -67,8 +64,6 @@ class Tracing(metaclass=SingletonMeta):
|
|
|
67
64
|
self.api_key = api_key if api_key is not None else ""
|
|
68
65
|
self.llm_logger = llm_logger
|
|
69
66
|
self.app_id = app_id
|
|
70
|
-
self.variant_id = variant_id
|
|
71
|
-
self.variant_name = variant_name
|
|
72
67
|
self.tasks_manager = TaskQueue(
|
|
73
68
|
max_workers if max_workers else 4, logger=llm_logger
|
|
74
69
|
)
|
|
@@ -126,8 +121,6 @@ class Tracing(metaclass=SingletonMeta):
|
|
|
126
121
|
inputs=input,
|
|
127
122
|
name=name,
|
|
128
123
|
app_id=self.app_id,
|
|
129
|
-
variant_id=self.variant_id,
|
|
130
|
-
variant_name=self.variant_name,
|
|
131
124
|
config=config,
|
|
132
125
|
spankind=spankind.upper(),
|
|
133
126
|
attributes={},
|
|
@@ -155,6 +148,11 @@ class Tracing(metaclass=SingletonMeta):
|
|
|
155
148
|
if not config and self.trace_config_cache is not None
|
|
156
149
|
else None
|
|
157
150
|
)
|
|
151
|
+
if VARIANT_TRACKING_FEATURE_FLAG:
|
|
152
|
+
# TODO: we should get the variant_id and variant_name (and environment) from the config object
|
|
153
|
+
span.variant_id = config.variant_id
|
|
154
|
+
span.variant_name = (config.variant_name,)
|
|
155
|
+
|
|
158
156
|
else:
|
|
159
157
|
span.parent_span_id = self.active_span.id
|
|
160
158
|
self.span_dict[span.id] = span
|
|
@@ -131,8 +131,9 @@ class GroupedMultipleChoiceParam(str):
|
|
|
131
131
|
def __new__(cls, default: str = None, choices: Dict[str, List[str]] = None):
|
|
132
132
|
if choices is None:
|
|
133
133
|
choices = {}
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
if default and not any(
|
|
135
|
+
default in choice_list for choice_list in choices.values()
|
|
136
|
+
):
|
|
136
137
|
if not choices:
|
|
137
138
|
print(
|
|
138
139
|
f"Warning: Default value {default} provided but choices are empty."
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/errors/unprocessable_entity_error.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/containers/types/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/environments/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/observability/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/resources/variants/types/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/environment_output_extended.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/evaluation_scenario_input.py
RENAMED
|
File without changes
|
{agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/evaluation_scenario_output.py
RENAMED
|
File without changes
|
{agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/evaluation_scenario_result.py
RENAMED
|
File without changes
|
{agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/evaluation_scenario_score_update.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/human_evaluation_scenario.py
RENAMED
|
File without changes
|
{agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/human_evaluation_scenario_input.py
RENAMED
|
File without changes
|
{agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/human_evaluation_scenario_output.py
RENAMED
|
File without changes
|
{agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/human_evaluation_scenario_update.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/validation_error_loc_item.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{agenta-0.15.0a2 → agenta-0.15.0a4}/agenta/client/backend/types/workspace_member_response.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|