agenta 0.12.2__py3-none-any.whl → 0.32.0a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of agenta might be problematic. Click here for more details.
- agenta/__init__.py +64 -7
- agenta/cli/helper.py +7 -3
- agenta/cli/main.py +15 -50
- agenta/cli/variant_commands.py +50 -29
- agenta/client/Readme.md +72 -64
- agenta/client/api.py +2 -2
- agenta/client/backend/__init__.py +193 -22
- agenta/client/backend/access_control/__init__.py +1 -0
- agenta/client/backend/access_control/client.py +167 -0
- agenta/client/backend/apps/__init__.py +1 -0
- agenta/client/backend/apps/client.py +1691 -0
- agenta/client/backend/bases/__init__.py +1 -0
- agenta/client/backend/bases/client.py +190 -0
- agenta/client/backend/client.py +2508 -5712
- agenta/client/backend/configs/__init__.py +1 -0
- agenta/client/backend/configs/client.py +604 -0
- agenta/client/backend/containers/__init__.py +5 -0
- agenta/client/backend/containers/client.py +648 -0
- agenta/client/backend/containers/types/__init__.py +5 -0
- agenta/client/backend/{types → containers/types}/container_templates_response.py +1 -2
- agenta/client/backend/core/__init__.py +30 -0
- agenta/client/backend/core/client_wrapper.py +42 -9
- agenta/client/backend/core/file.py +70 -0
- agenta/client/backend/core/http_client.py +575 -0
- agenta/client/backend/core/jsonable_encoder.py +33 -39
- agenta/client/backend/core/pydantic_utilities.py +325 -0
- agenta/client/backend/core/query_encoder.py +60 -0
- agenta/client/backend/core/remove_none_from_dict.py +2 -2
- agenta/client/backend/core/request_options.py +35 -0
- agenta/client/backend/core/serialization.py +276 -0
- agenta/client/backend/environments/__init__.py +1 -0
- agenta/client/backend/environments/client.py +196 -0
- agenta/client/backend/evaluations/__init__.py +1 -0
- agenta/client/backend/evaluations/client.py +1469 -0
- agenta/client/backend/evaluators/__init__.py +1 -0
- agenta/client/backend/evaluators/client.py +1283 -0
- agenta/client/backend/observability/__init__.py +1 -0
- agenta/client/backend/observability/client.py +1286 -0
- agenta/client/backend/observability_v_1/__init__.py +5 -0
- agenta/client/backend/observability_v_1/client.py +763 -0
- agenta/client/backend/observability_v_1/types/__init__.py +7 -0
- agenta/client/backend/observability_v_1/types/format.py +5 -0
- agenta/client/backend/observability_v_1/types/query_analytics_response.py +7 -0
- agenta/client/backend/observability_v_1/types/query_traces_response.py +11 -0
- agenta/client/backend/scopes/__init__.py +1 -0
- agenta/client/backend/scopes/client.py +114 -0
- agenta/client/backend/testsets/__init__.py +1 -0
- agenta/client/backend/testsets/client.py +1284 -0
- agenta/client/backend/types/__init__.py +154 -26
- agenta/client/backend/types/agenta_node_dto.py +48 -0
- agenta/client/backend/types/agenta_node_dto_nodes_value.py +6 -0
- agenta/client/backend/types/agenta_nodes_response.py +30 -0
- agenta/client/backend/types/agenta_root_dto.py +30 -0
- agenta/client/backend/types/agenta_roots_response.py +30 -0
- agenta/client/backend/types/agenta_tree_dto.py +30 -0
- agenta/client/backend/types/agenta_trees_response.py +30 -0
- agenta/client/backend/types/aggregated_result.py +16 -31
- agenta/client/backend/types/aggregated_result_evaluator_config.py +8 -0
- agenta/client/backend/types/analytics_response.py +24 -0
- agenta/client/backend/types/app.py +17 -30
- agenta/client/backend/types/app_variant_response.py +36 -0
- agenta/client/backend/types/app_variant_revision.py +17 -32
- agenta/client/backend/types/base_output.py +13 -28
- agenta/client/backend/types/body_import_testset.py +15 -31
- agenta/client/backend/types/bucket_dto.py +26 -0
- agenta/client/backend/types/collect_status_response.py +22 -0
- agenta/client/backend/types/config_db.py +16 -31
- agenta/client/backend/types/config_dto.py +32 -0
- agenta/client/backend/types/config_response_model.py +32 -0
- agenta/client/backend/types/correct_answer.py +22 -0
- agenta/client/backend/types/create_app_output.py +13 -28
- agenta/client/backend/types/create_span.py +45 -0
- agenta/client/backend/types/create_trace_response.py +22 -0
- agenta/client/backend/types/docker_env_vars.py +13 -28
- agenta/client/backend/types/environment_output.py +22 -34
- agenta/client/backend/types/environment_output_extended.py +31 -0
- agenta/client/backend/types/environment_revision.py +26 -0
- agenta/client/backend/types/error.py +22 -0
- agenta/client/backend/types/evaluation.py +22 -33
- agenta/client/backend/types/evaluation_scenario.py +18 -33
- agenta/client/backend/types/evaluation_scenario_input.py +16 -31
- agenta/client/backend/types/evaluation_scenario_output.py +17 -30
- agenta/client/backend/types/evaluation_scenario_result.py +14 -29
- agenta/client/backend/types/evaluation_scenario_score_update.py +21 -0
- agenta/client/backend/types/evaluation_status_enum.py +11 -29
- agenta/client/backend/types/evaluation_type.py +3 -21
- agenta/client/backend/types/evaluator.py +20 -31
- agenta/client/backend/types/evaluator_config.py +21 -33
- agenta/client/backend/types/evaluator_mapping_output_interface.py +21 -0
- agenta/client/backend/types/evaluator_output_interface.py +21 -0
- agenta/client/backend/types/exception_dto.py +26 -0
- agenta/client/backend/types/get_config_response.py +23 -0
- agenta/client/backend/types/header_dto.py +22 -0
- agenta/client/backend/types/http_validation_error.py +14 -29
- agenta/client/backend/types/human_evaluation.py +18 -34
- agenta/client/backend/types/human_evaluation_scenario.py +22 -38
- agenta/client/backend/types/human_evaluation_scenario_input.py +13 -28
- agenta/client/backend/types/human_evaluation_scenario_output.py +13 -28
- agenta/client/backend/types/human_evaluation_scenario_update.py +30 -0
- agenta/client/backend/types/human_evaluation_update.py +22 -0
- agenta/client/backend/types/image.py +18 -32
- agenta/client/backend/types/invite_request.py +16 -30
- agenta/client/backend/types/legacy_analytics_response.py +29 -0
- agenta/client/backend/types/legacy_data_point.py +27 -0
- agenta/client/backend/types/lifecycle_dto.py +24 -0
- agenta/client/backend/types/link_dto.py +24 -0
- agenta/client/backend/types/list_api_keys_response.py +24 -0
- agenta/client/backend/types/llm_run_rate_limit.py +13 -28
- agenta/client/backend/types/llm_tokens.py +23 -0
- agenta/client/backend/types/metrics_dto.py +24 -0
- agenta/client/backend/types/new_human_evaluation.py +27 -0
- agenta/client/backend/types/new_testset.py +16 -31
- agenta/client/backend/types/node_dto.py +24 -0
- agenta/client/backend/types/node_type.py +19 -0
- agenta/client/backend/types/o_tel_context_dto.py +22 -0
- agenta/client/backend/types/o_tel_event_dto.py +23 -0
- agenta/client/backend/types/o_tel_extra_dto.py +26 -0
- agenta/client/backend/types/o_tel_link_dto.py +23 -0
- agenta/client/backend/types/o_tel_span_dto.py +37 -0
- agenta/client/backend/types/o_tel_span_kind.py +15 -0
- agenta/client/backend/types/o_tel_spans_response.py +24 -0
- agenta/client/backend/types/o_tel_status_code.py +8 -0
- agenta/client/backend/types/organization.py +22 -35
- agenta/client/backend/types/organization_output.py +13 -28
- agenta/client/backend/types/outputs.py +5 -0
- agenta/client/backend/types/parent_dto.py +21 -0
- agenta/client/backend/types/permission.py +41 -0
- agenta/client/backend/types/projects_response.py +28 -0
- agenta/client/backend/types/provider_key_dto.py +23 -0
- agenta/client/backend/types/provider_kind.py +21 -0
- agenta/client/backend/types/reference_dto.py +23 -0
- agenta/client/backend/types/reference_request_model.py +23 -0
- agenta/client/backend/types/result.py +18 -31
- agenta/client/backend/types/root_dto.py +21 -0
- agenta/client/backend/types/{human_evaluation_scenario_score.py → score.py} +1 -1
- agenta/client/backend/types/secret_dto.py +24 -0
- agenta/client/backend/types/{human_evaluation_scenario_update_score.py → secret_kind.py} +1 -1
- agenta/client/backend/types/secret_response_dto.py +27 -0
- agenta/client/backend/types/simple_evaluation_output.py +13 -28
- agenta/client/backend/types/span.py +39 -49
- agenta/client/backend/types/span_detail.py +44 -0
- agenta/client/backend/types/span_dto.py +54 -0
- agenta/client/backend/types/span_dto_nodes_value.py +9 -0
- agenta/client/backend/types/span_status_code.py +5 -0
- agenta/client/backend/types/span_variant.py +23 -0
- agenta/client/backend/types/status_code.py +5 -0
- agenta/client/backend/types/status_dto.py +23 -0
- agenta/client/backend/types/template.py +14 -29
- agenta/client/backend/types/template_image_info.py +21 -35
- agenta/client/backend/types/test_set_output_response.py +20 -33
- agenta/client/backend/types/test_set_simple_response.py +13 -28
- agenta/client/backend/types/time_dto.py +23 -0
- agenta/client/backend/types/trace_detail.py +44 -0
- agenta/client/backend/types/tree_dto.py +23 -0
- agenta/client/backend/types/tree_type.py +5 -0
- agenta/client/backend/types/update_app_output.py +22 -0
- agenta/client/backend/types/uri.py +13 -28
- agenta/client/backend/types/validation_error.py +13 -28
- agenta/client/backend/types/variant_action.py +14 -29
- agenta/client/backend/types/variant_action_enum.py +1 -19
- agenta/client/backend/types/with_pagination.py +26 -0
- agenta/client/backend/types/workspace_member_response.py +23 -0
- agenta/client/backend/types/workspace_permission.py +25 -0
- agenta/client/backend/types/workspace_response.py +29 -0
- agenta/client/backend/types/workspace_role.py +15 -0
- agenta/client/backend/types/workspace_role_response.py +23 -0
- agenta/client/backend/variants/__init__.py +5 -0
- agenta/client/backend/variants/client.py +2814 -0
- agenta/client/backend/variants/types/__init__.py +7 -0
- agenta/client/backend/variants/types/add_variant_from_base_and_config_response.py +8 -0
- agenta/client/backend/vault/__init__.py +1 -0
- agenta/client/backend/vault/client.py +685 -0
- agenta/client/client.py +1 -1
- agenta/config.py +0 -2
- agenta/config.toml +0 -1
- agenta/docker/docker-assets/Dockerfile.cloud.template +2 -1
- agenta/docker/docker-assets/Dockerfile.template +2 -1
- agenta/docker/docker_utils.py +11 -12
- agenta/sdk/__init__.py +58 -7
- agenta/sdk/agenta_init.py +182 -164
- agenta/sdk/assets.py +95 -0
- agenta/sdk/client.py +56 -0
- agenta/sdk/context/__init__.py +0 -0
- agenta/sdk/context/exporting.py +25 -0
- agenta/sdk/context/routing.py +27 -0
- agenta/sdk/context/tracing.py +28 -0
- agenta/sdk/decorators/__init__.py +0 -0
- agenta/sdk/decorators/routing.py +576 -0
- agenta/sdk/decorators/tracing.py +296 -0
- agenta/sdk/litellm/__init__.py +1 -0
- agenta/sdk/litellm/litellm.py +314 -0
- agenta/sdk/litellm/mockllm.py +27 -0
- agenta/sdk/litellm/mocks/__init__.py +26 -0
- agenta/sdk/managers/__init__.py +6 -0
- agenta/sdk/managers/config.py +208 -0
- agenta/sdk/managers/deployment.py +45 -0
- agenta/sdk/managers/secrets.py +38 -0
- agenta/sdk/managers/shared.py +639 -0
- agenta/sdk/managers/variant.py +182 -0
- agenta/sdk/managers/vault.py +16 -0
- agenta/sdk/middleware/__init__.py +0 -0
- agenta/sdk/middleware/auth.py +180 -0
- agenta/sdk/middleware/cache.py +47 -0
- agenta/sdk/middleware/config.py +255 -0
- agenta/sdk/middleware/cors.py +29 -0
- agenta/sdk/middleware/inline.py +38 -0
- agenta/sdk/middleware/mock.py +33 -0
- agenta/sdk/middleware/otel.py +40 -0
- agenta/sdk/middleware/vault.py +145 -0
- agenta/sdk/router.py +0 -7
- agenta/sdk/tracing/__init__.py +1 -0
- agenta/sdk/tracing/attributes.py +141 -0
- agenta/sdk/tracing/conventions.py +49 -0
- agenta/sdk/tracing/exporters.py +103 -0
- agenta/sdk/tracing/inline.py +1146 -0
- agenta/sdk/tracing/processors.py +121 -0
- agenta/sdk/tracing/spans.py +136 -0
- agenta/sdk/tracing/tracing.py +237 -0
- agenta/sdk/types.py +478 -74
- agenta/sdk/utils/__init__.py +0 -0
- agenta/sdk/utils/constants.py +1 -0
- agenta/sdk/utils/{helper/openai_cost.py → costs.py} +3 -0
- agenta/sdk/utils/exceptions.py +59 -0
- agenta/sdk/utils/globals.py +6 -10
- agenta/sdk/utils/helpers.py +8 -0
- agenta/sdk/utils/logging.py +21 -0
- agenta/sdk/utils/singleton.py +13 -0
- agenta/sdk/utils/timing.py +58 -0
- {agenta-0.12.2.dist-info → agenta-0.32.0a1.dist-info}/METADATA +98 -151
- agenta-0.32.0a1.dist-info/RECORD +263 -0
- {agenta-0.12.2.dist-info → agenta-0.32.0a1.dist-info}/WHEEL +1 -1
- agenta/client/backend/types/add_variant_from_base_and_config_response.py +0 -7
- agenta/client/backend/types/app_variant_output.py +0 -47
- agenta/client/backend/types/app_variant_output_extended.py +0 -50
- agenta/client/backend/types/delete_evaluation.py +0 -36
- agenta/client/backend/types/evaluation_webhook.py +0 -36
- agenta/client/backend/types/feedback.py +0 -40
- agenta/client/backend/types/get_config_reponse.py +0 -39
- agenta/client/backend/types/list_api_keys_output.py +0 -39
- agenta/client/backend/types/trace.py +0 -48
- agenta/sdk/agenta_decorator.py +0 -443
- agenta/sdk/context.py +0 -41
- agenta-0.12.2.dist-info/RECORD +0 -114
- {agenta-0.12.2.dist-info → agenta-0.32.0a1.dist-info}/entry_points.txt +0 -0
agenta/config.py
CHANGED
|
@@ -11,14 +11,12 @@ from pathlib import Path
|
|
|
11
11
|
toml_config = toml.load(f"{Path(__file__).parent}/config.toml")
|
|
12
12
|
|
|
13
13
|
# Set the environment variables from the TOML configurations
|
|
14
|
-
os.environ["DATABASE_URL"] = toml_config["database_url"]
|
|
15
14
|
os.environ["REGISTRY"] = toml_config["registry"]
|
|
16
15
|
os.environ["BACKEND_URL_SUFFIX"] = toml_config["backend_url_suffix"]
|
|
17
16
|
os.environ["ALLOW_ORIGINS"] = toml_config["allow_origins"]
|
|
18
17
|
|
|
19
18
|
|
|
20
19
|
class Settings(BaseSettings):
|
|
21
|
-
database_url: str
|
|
22
20
|
registry: str
|
|
23
21
|
backend_url_suffix: str
|
|
24
22
|
allow_origins: str
|
agenta/config.toml
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
FROM public.ecr.aws/
|
|
1
|
+
FROM public.ecr.aws/h3w6n5z0/agentaai/lambda_templates_public:main
|
|
2
2
|
|
|
3
3
|
COPY requirements.txt ${LAMBDA_TASK_ROOT}
|
|
4
|
+
RUN pip install --no-cache-dir --disable-pip-version-check -U agenta
|
|
4
5
|
RUN pip install --no-cache-dir --disable-pip-version-check -r requirements.txt
|
|
5
6
|
RUN pip install --no-cache-dir --disable-pip-version-check mangum
|
|
6
7
|
COPY . ${LAMBDA_TASK_ROOT}
|
|
@@ -4,9 +4,10 @@ WORKDIR /app
|
|
|
4
4
|
|
|
5
5
|
COPY . .
|
|
6
6
|
|
|
7
|
+
RUN pip install --no-cache-dir --disable-pip-version-check -U agenta
|
|
7
8
|
RUN pip install --no-cache-dir --disable-pip-version-check -r requirements.txt
|
|
8
9
|
|
|
9
10
|
EXPOSE 80
|
|
10
11
|
|
|
12
|
+
RUN ["chmod", "+x", "./entrypoint.sh"]
|
|
11
13
|
CMD ["./entrypoint.sh"]
|
|
12
|
-
# uvicorn agenta_backend.main:app --reload --host 0.0.0.0 --port 8881
|
agenta/docker/docker_utils.py
CHANGED
|
@@ -3,19 +3,16 @@ import shutil
|
|
|
3
3
|
import tarfile
|
|
4
4
|
import tempfile
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
|
|
6
|
+
import os
|
|
7
7
|
|
|
8
|
-
import docker
|
|
9
|
-
from agenta.config import settings
|
|
10
|
-
from docker.models.images import Image
|
|
11
8
|
|
|
12
9
|
logger = logging.getLogger(__name__)
|
|
13
10
|
logger.setLevel(logging.DEBUG)
|
|
14
11
|
|
|
15
|
-
DEBUG = False
|
|
12
|
+
DEBUG = os.environ.get("AGENTA_CLI_DEBUG", False)
|
|
16
13
|
|
|
17
14
|
|
|
18
|
-
def create_dockerfile(out_folder: Path):
|
|
15
|
+
def create_dockerfile(out_folder: Path) -> Path:
|
|
19
16
|
"""Creates a dockerfile based on the template in the out_folder.
|
|
20
17
|
|
|
21
18
|
Arguments:
|
|
@@ -55,12 +52,14 @@ def build_tar_docker_container(folder: Path, file_name: Path) -> Path:
|
|
|
55
52
|
shutil.copy(Path(__file__).parent / "docker-assets" / "lambda_function.py", folder)
|
|
56
53
|
shutil.copy(Path(__file__).parent / "docker-assets" / "entrypoint.sh", folder)
|
|
57
54
|
|
|
55
|
+
# Initialize agentaignore_content with an empty string
|
|
56
|
+
agentaignore_content = ""
|
|
57
|
+
|
|
58
58
|
# Read the contents of .gitignore file
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
gitignore_content = gitignore_file.read()
|
|
59
|
+
agentaignore_file_path = folder / ".agentaignore"
|
|
60
|
+
if agentaignore_file_path.exists():
|
|
61
|
+
with open(agentaignore_file_path, "r") as agentaignore_file:
|
|
62
|
+
agentaignore_content = agentaignore_file.read()
|
|
64
63
|
|
|
65
64
|
# Create a temporary directory
|
|
66
65
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
@@ -68,7 +67,7 @@ def build_tar_docker_container(folder: Path, file_name: Path) -> Path:
|
|
|
68
67
|
|
|
69
68
|
# Clean - remove '/' from every files and folders in the gitignore contents
|
|
70
69
|
sanitized_patterns = [
|
|
71
|
-
pattern.replace("/", "") for pattern in
|
|
70
|
+
pattern.replace("/", "") for pattern in agentaignore_content.splitlines()
|
|
72
71
|
]
|
|
73
72
|
|
|
74
73
|
# Function to ignore files based on the patterns
|
agenta/sdk/__init__.py
CHANGED
|
@@ -1,20 +1,71 @@
|
|
|
1
|
+
from typing import Optional, Callable, Any
|
|
2
|
+
|
|
1
3
|
from .utils.preinit import PreInitObject # always the first import!
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
import agenta.client.backend.types as client_types # pylint: disable=wrong-import-order
|
|
6
|
+
|
|
5
7
|
from .types import (
|
|
6
|
-
Context,
|
|
7
8
|
DictInput,
|
|
9
|
+
MultipleChoice,
|
|
8
10
|
FloatParam,
|
|
9
|
-
InFile,
|
|
10
11
|
IntParam,
|
|
11
12
|
MultipleChoiceParam,
|
|
13
|
+
GroupedMultipleChoiceParam,
|
|
12
14
|
TextParam,
|
|
13
15
|
MessagesInput,
|
|
14
16
|
FileInputURL,
|
|
15
17
|
BinaryParam,
|
|
18
|
+
Prompt,
|
|
19
|
+
AgentaNodeDto,
|
|
20
|
+
AgentaNodesResponse,
|
|
16
21
|
)
|
|
17
|
-
|
|
18
|
-
from .
|
|
22
|
+
|
|
23
|
+
from .tracing import Tracing, get_tracer
|
|
24
|
+
from .decorators.tracing import instrument
|
|
25
|
+
from .tracing.conventions import Reference
|
|
26
|
+
from .decorators.routing import entrypoint, app, route
|
|
27
|
+
from .agenta_init import Config, AgentaSingleton, init as _init
|
|
28
|
+
from .utils.costs import calculate_token_usage
|
|
29
|
+
from .managers.vault import VaultManager
|
|
30
|
+
from .managers.secrets import SecretsManager
|
|
31
|
+
from .managers.config import ConfigManager
|
|
32
|
+
from .managers.variant import VariantManager
|
|
33
|
+
from .managers.deployment import DeploymentManager
|
|
19
34
|
|
|
20
35
|
config = PreInitObject("agenta.config", Config)
|
|
36
|
+
DEFAULT_AGENTA_SINGLETON_INSTANCE = AgentaSingleton()
|
|
37
|
+
|
|
38
|
+
types = client_types
|
|
39
|
+
|
|
40
|
+
api = None
|
|
41
|
+
async_api = None
|
|
42
|
+
|
|
43
|
+
tracing = DEFAULT_AGENTA_SINGLETON_INSTANCE.tracing # type: ignore
|
|
44
|
+
tracer = get_tracer(tracing)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def init(
|
|
48
|
+
host: Optional[str] = None,
|
|
49
|
+
api_key: Optional[str] = None,
|
|
50
|
+
config_fname: Optional[str] = None,
|
|
51
|
+
redact: Optional[Callable[..., Any]] = None,
|
|
52
|
+
redact_on_error: Optional[bool] = True,
|
|
53
|
+
# DEPRECATING
|
|
54
|
+
app_id: Optional[str] = None,
|
|
55
|
+
):
|
|
56
|
+
global api, async_api, tracing, tracer # pylint: disable=global-statement
|
|
57
|
+
|
|
58
|
+
_init(
|
|
59
|
+
host=host,
|
|
60
|
+
api_key=api_key,
|
|
61
|
+
config_fname=config_fname,
|
|
62
|
+
redact=redact,
|
|
63
|
+
redact_on_error=redact_on_error,
|
|
64
|
+
app_id=app_id,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
api = DEFAULT_AGENTA_SINGLETON_INSTANCE.api # type: ignore
|
|
68
|
+
async_api = DEFAULT_AGENTA_SINGLETON_INSTANCE.async_api # type: ignore
|
|
69
|
+
|
|
70
|
+
tracing = DEFAULT_AGENTA_SINGLETON_INSTANCE.tracing # type: ignore
|
|
71
|
+
tracer = get_tracer(tracing)
|
agenta/sdk/agenta_init.py
CHANGED
|
@@ -1,33 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
from
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
from typing import Any, Optional
|
|
1
|
+
import toml
|
|
2
|
+
from os import getenv
|
|
3
|
+
from typing import Optional, Callable, Any
|
|
4
|
+
from importlib.metadata import version
|
|
6
5
|
|
|
7
|
-
from .utils.
|
|
6
|
+
from agenta.sdk.utils.logging import log
|
|
7
|
+
from agenta.sdk.utils.globals import set_global
|
|
8
|
+
from agenta.client.backend.client import AgentaApi, AsyncAgentaApi
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
BACKEND_URL_SUFFIX = os.environ.get("BACKEND_URL_SUFFIX", "api")
|
|
14
|
-
CLIENT_API_KEY = os.environ.get("AGENTA_API_KEY")
|
|
15
|
-
CLIENT_HOST = os.environ.get("AGENTA_HOST", "http://localhost")
|
|
16
|
-
|
|
17
|
-
# initialize the client with the backend url and api key
|
|
18
|
-
backend_url = f"{CLIENT_HOST}/{BACKEND_URL_SUFFIX}"
|
|
19
|
-
client = AgentaApi(
|
|
20
|
-
base_url=backend_url,
|
|
21
|
-
api_key=CLIENT_API_KEY if CLIENT_API_KEY else "",
|
|
22
|
-
)
|
|
10
|
+
from agenta.sdk.tracing import Tracing
|
|
11
|
+
from agenta.sdk.context.routing import routing_context
|
|
23
12
|
|
|
24
13
|
|
|
25
14
|
class AgentaSingleton:
|
|
26
15
|
"""Singleton class to save all the "global variables" for the sdk."""
|
|
27
16
|
|
|
28
17
|
_instance = None
|
|
29
|
-
setup = None
|
|
30
18
|
config = None
|
|
19
|
+
tracing = None
|
|
20
|
+
|
|
21
|
+
api = None
|
|
22
|
+
async_api = None
|
|
31
23
|
|
|
32
24
|
def __new__(cls):
|
|
33
25
|
if not cls._instance:
|
|
@@ -36,78 +28,140 @@ class AgentaSingleton:
|
|
|
36
28
|
|
|
37
29
|
def init(
|
|
38
30
|
self,
|
|
39
|
-
|
|
40
|
-
base_name: Optional[str] = None,
|
|
41
|
-
api_key: Optional[str] = None,
|
|
42
|
-
base_id: Optional[str] = None,
|
|
31
|
+
*,
|
|
43
32
|
host: Optional[str] = None,
|
|
44
|
-
|
|
33
|
+
api_key: Optional[str] = None,
|
|
34
|
+
config_fname: Optional[str] = None,
|
|
35
|
+
redact: Optional[Callable[..., Any]] = None,
|
|
36
|
+
redact_on_error: Optional[bool] = True,
|
|
37
|
+
# DEPRECATING
|
|
38
|
+
app_id: Optional[str] = None,
|
|
45
39
|
) -> None:
|
|
46
|
-
"""
|
|
40
|
+
"""
|
|
41
|
+
Main function to initialize the singleton.
|
|
42
|
+
|
|
43
|
+
Initializes the singleton with the given `app_id`, `host`, and `api_key`. The order of precedence for these variables is:
|
|
44
|
+
1. Explicit argument provided in the function call.
|
|
45
|
+
2. Value from the configuration file specified by `config_fname`.
|
|
46
|
+
3. Environment variables.
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
Examples:
|
|
49
|
+
ag.init(app_id="xxxx", api_key="xxx")
|
|
50
|
+
ag.init(config_fname="config.toml")
|
|
51
|
+
ag.init() #assuming env vars are set
|
|
50
52
|
|
|
51
53
|
Args:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
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.
|
|
55
|
+
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.
|
|
56
|
+
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.
|
|
57
|
+
config_fname (Optional[str]): Path to the configuration file (relative or absolute). Defaults to None.
|
|
56
58
|
|
|
57
59
|
Raises:
|
|
58
|
-
ValueError: If `
|
|
60
|
+
ValueError: If `app_id` is not specified either as an argument, in the config file, or in the environment variables.
|
|
59
61
|
"""
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
self.
|
|
100
|
-
|
|
62
|
+
|
|
63
|
+
log.info("Agenta - SDK version: %s", version("agenta"))
|
|
64
|
+
|
|
65
|
+
config = {}
|
|
66
|
+
if config_fname:
|
|
67
|
+
config = toml.load(config_fname)
|
|
68
|
+
|
|
69
|
+
self.host = (
|
|
70
|
+
host
|
|
71
|
+
or getenv("AGENTA_HOST")
|
|
72
|
+
or config.get("backend_host")
|
|
73
|
+
or config.get("host")
|
|
74
|
+
or "https://cloud.agenta.ai"
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
self.app_id = app_id or config.get("app_id") or getenv("AGENTA_APP_ID")
|
|
78
|
+
# if not self.app_id:
|
|
79
|
+
# raise ValueError(
|
|
80
|
+
# "App ID must be specified. You can provide it in one of the following ways:\n"
|
|
81
|
+
# "1. As an argument when calling ag.init(app_id='your_app_id').\n"
|
|
82
|
+
# "2. In the configuration file specified by config_fname.\n"
|
|
83
|
+
# "3. As an environment variable 'AGENTA_APP_ID'."
|
|
84
|
+
# )
|
|
85
|
+
|
|
86
|
+
self.api_key = api_key or getenv("AGENTA_API_KEY") or config.get("api_key")
|
|
87
|
+
|
|
88
|
+
self.base_id = getenv("AGENTA_BASE_ID")
|
|
89
|
+
|
|
90
|
+
self.service_id = getenv("AGENTA_SERVICE_ID") or self.base_id
|
|
91
|
+
|
|
92
|
+
log.info("Agenta - Service ID: %s", self.service_id)
|
|
93
|
+
log.info("Agenta - Application ID: %s", self.app_id)
|
|
94
|
+
|
|
95
|
+
self.tracing = Tracing(
|
|
96
|
+
url=f"{self.host}/api/observability/v1/otlp/traces", # type: ignore
|
|
97
|
+
redact=redact,
|
|
98
|
+
redact_on_error=redact_on_error,
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
self.tracing.configure(
|
|
102
|
+
api_key=self.api_key,
|
|
103
|
+
service_id=self.service_id,
|
|
104
|
+
# DEPRECATING
|
|
105
|
+
app_id=self.app_id,
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
self.api = AgentaApi(
|
|
109
|
+
base_url=self.host + "/api",
|
|
110
|
+
api_key=self.api_key if self.api_key else "",
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
self.async_api = AsyncAgentaApi(
|
|
114
|
+
base_url=self.host + "/api",
|
|
115
|
+
api_key=self.api_key if self.api_key else "",
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
self.config = Config(
|
|
119
|
+
host=self.host,
|
|
120
|
+
base_id=self.base_id,
|
|
121
|
+
api_key=self.api_key,
|
|
122
|
+
)
|
|
101
123
|
|
|
102
124
|
|
|
103
125
|
class Config:
|
|
104
|
-
def __init__(
|
|
105
|
-
self
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
126
|
+
def __init__(
|
|
127
|
+
self,
|
|
128
|
+
# LEGACY
|
|
129
|
+
host: Optional[str] = None,
|
|
130
|
+
base_id: Optional[str] = None,
|
|
131
|
+
api_key: Optional[str] = None,
|
|
132
|
+
# LEGACY
|
|
133
|
+
**kwargs,
|
|
134
|
+
):
|
|
135
|
+
self.default_parameters = {**kwargs}
|
|
136
|
+
|
|
137
|
+
def set_default(self, **kwargs):
|
|
138
|
+
self.default_parameters.update(kwargs)
|
|
139
|
+
|
|
140
|
+
def get_default(self):
|
|
141
|
+
return self.default_parameters
|
|
142
|
+
|
|
143
|
+
def __getattr__(self, key):
|
|
144
|
+
context = routing_context.get()
|
|
145
|
+
|
|
146
|
+
parameters = context.parameters
|
|
147
|
+
|
|
148
|
+
if not parameters:
|
|
149
|
+
return None
|
|
150
|
+
|
|
151
|
+
if key in parameters:
|
|
152
|
+
value = parameters[key]
|
|
153
|
+
|
|
154
|
+
if isinstance(value, dict):
|
|
155
|
+
nested_config = Config()
|
|
156
|
+
nested_config.set_default(**value)
|
|
157
|
+
|
|
158
|
+
return nested_config
|
|
159
|
+
|
|
160
|
+
return value
|
|
161
|
+
|
|
162
|
+
return None
|
|
163
|
+
|
|
164
|
+
### --- LEGACY --- ###
|
|
111
165
|
|
|
112
166
|
def register_default(self, overwrite=False, **kwargs):
|
|
113
167
|
"""alias for default"""
|
|
@@ -119,94 +173,58 @@ class Config:
|
|
|
119
173
|
overwrite: Whether to overwrite the existing configuration or not
|
|
120
174
|
**kwargs: A dict containing the parameters
|
|
121
175
|
"""
|
|
122
|
-
self.set(
|
|
123
|
-
**kwargs
|
|
124
|
-
) # In case there is no connectivity, we still can use the default values
|
|
125
|
-
try:
|
|
126
|
-
self.push(config_name="default", overwrite=overwrite, **kwargs)
|
|
127
|
-
except Exception as ex:
|
|
128
|
-
logger.warning(
|
|
129
|
-
"Unable to push the default configuration to the server." + str(ex)
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
def push(self, config_name: str, overwrite=True, **kwargs):
|
|
133
|
-
"""Pushes the parameters for the app variant to the server
|
|
134
|
-
Args:
|
|
135
|
-
config_name: Name of the configuration to push to
|
|
136
|
-
overwrite: Whether to overwrite the existing configuration or not
|
|
137
|
-
**kwargs: A dict containing the parameters
|
|
138
|
-
"""
|
|
139
|
-
if not self.persist:
|
|
140
|
-
return
|
|
141
|
-
try:
|
|
142
|
-
client.save_config(
|
|
143
|
-
base_id=self.base_id,
|
|
144
|
-
config_name=config_name,
|
|
145
|
-
parameters=kwargs,
|
|
146
|
-
overwrite=overwrite,
|
|
147
|
-
)
|
|
148
|
-
except Exception as ex:
|
|
149
|
-
logger.warning(
|
|
150
|
-
"Failed to push the configuration to the server with error: " + str(ex)
|
|
151
|
-
)
|
|
152
|
-
|
|
153
|
-
def pull(self, config_name: str = "default", environment_name: str = None):
|
|
154
|
-
"""Pulls the parameters for the app variant from the server and sets them to the config"""
|
|
155
|
-
if not self.persist and (
|
|
156
|
-
config_name != "default" or environment_name is not None
|
|
157
|
-
):
|
|
158
|
-
raise Exception(
|
|
159
|
-
"Cannot pull the configuration from the server since the app_name and base_name are not provided."
|
|
160
|
-
)
|
|
161
|
-
if self.persist:
|
|
162
|
-
try:
|
|
163
|
-
if environment_name:
|
|
164
|
-
config = client.get_config(
|
|
165
|
-
base_id=self.base_id, environment_name=environment_name
|
|
166
|
-
)
|
|
167
|
-
|
|
168
|
-
else:
|
|
169
|
-
config = client.get_config(
|
|
170
|
-
base_id=self.base_id,
|
|
171
|
-
config_name=config_name,
|
|
172
|
-
)
|
|
173
|
-
except Exception as ex:
|
|
174
|
-
logger.warning(
|
|
175
|
-
"Failed to pull the configuration from the server with error: "
|
|
176
|
-
+ str(ex)
|
|
177
|
-
)
|
|
178
|
-
try:
|
|
179
|
-
self.set(**config.parameters)
|
|
180
|
-
except Exception as ex:
|
|
181
|
-
logger.warning("Failed to set the configuration with error: " + str(ex))
|
|
176
|
+
self.set(**kwargs)
|
|
182
177
|
|
|
183
|
-
def all(self):
|
|
184
|
-
"""Returns all the parameters for the app variant"""
|
|
185
|
-
return {
|
|
186
|
-
k: v
|
|
187
|
-
for k, v in self.__dict__.items()
|
|
188
|
-
if k
|
|
189
|
-
not in ["app_name", "base_name", "host", "base_id", "api_key", "persist"]
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
# function to set the parameters for the app variant
|
|
193
178
|
def set(self, **kwargs):
|
|
194
|
-
|
|
179
|
+
self.set_default(**kwargs)
|
|
195
180
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
"""
|
|
199
|
-
for key, value in kwargs.items():
|
|
200
|
-
setattr(self, key, value)
|
|
181
|
+
def all(self):
|
|
182
|
+
return self.default_parameters
|
|
201
183
|
|
|
202
184
|
|
|
203
|
-
def init(
|
|
204
|
-
|
|
185
|
+
def init(
|
|
186
|
+
host: Optional[str] = None,
|
|
187
|
+
api_key: Optional[str] = None,
|
|
188
|
+
config_fname: Optional[str] = None,
|
|
189
|
+
redact: Optional[Callable[..., Any]] = None,
|
|
190
|
+
redact_on_error: Optional[bool] = True,
|
|
191
|
+
# DEPRECATING
|
|
192
|
+
app_id: Optional[str] = None,
|
|
193
|
+
):
|
|
194
|
+
"""Main function to initialize the agenta sdk.
|
|
195
|
+
|
|
196
|
+
Initializes agenta with the given `app_id`, `host`, and `api_key`. The order of precedence for these variables is:
|
|
197
|
+
1. Explicit argument provided in the function call.
|
|
198
|
+
2. Value from the configuration file specified by `config_fname`.
|
|
199
|
+
3. Environment variables.
|
|
200
|
+
|
|
201
|
+
- `app_id` is a required parameter (to be specified in one of the above ways)
|
|
202
|
+
- `host` is optional and defaults to "https://cloud.agenta.ai"
|
|
203
|
+
- `api_key` is optional and defaults to "". It is required only when using cloud or enterprise version of agenta.
|
|
204
|
+
|
|
205
205
|
|
|
206
206
|
Args:
|
|
207
|
-
|
|
208
|
-
|
|
207
|
+
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.
|
|
208
|
+
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.
|
|
209
|
+
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.
|
|
210
|
+
config_fname (Optional[str]): Path to the configuration file. Defaults to None.
|
|
211
|
+
|
|
212
|
+
Raises:
|
|
213
|
+
ValueError: If `app_id` is not specified either as an argument, in the config file, or in the environment variables.
|
|
209
214
|
"""
|
|
215
|
+
|
|
210
216
|
singleton = AgentaSingleton()
|
|
211
|
-
|
|
212
|
-
|
|
217
|
+
|
|
218
|
+
singleton.init(
|
|
219
|
+
host=host,
|
|
220
|
+
api_key=api_key,
|
|
221
|
+
config_fname=config_fname,
|
|
222
|
+
redact=redact,
|
|
223
|
+
redact_on_error=redact_on_error,
|
|
224
|
+
app_id=app_id,
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
set_global(
|
|
228
|
+
config=singleton.config,
|
|
229
|
+
tracing=singleton.tracing,
|
|
230
|
+
)
|
agenta/sdk/assets.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
supported_llm_models = {
|
|
2
|
+
"Aleph Alpha": [
|
|
3
|
+
"luminous-base",
|
|
4
|
+
"luminous-base-control",
|
|
5
|
+
"luminous-extended-control",
|
|
6
|
+
"luminous-supreme",
|
|
7
|
+
],
|
|
8
|
+
"Anthropic": [
|
|
9
|
+
"anthropic/claude-3-5-sonnet-20240620",
|
|
10
|
+
"anthropic/claude-3-opus-20240229",
|
|
11
|
+
"anthropic/claude-3-sonnet-20240229",
|
|
12
|
+
"anthropic/claude-3-haiku-20240307",
|
|
13
|
+
"anthropic/claude-2.1",
|
|
14
|
+
"anthropic/claude-2",
|
|
15
|
+
"anthropic/claude-instant-1.2",
|
|
16
|
+
"anthropic/claude-instant-1",
|
|
17
|
+
],
|
|
18
|
+
"Anyscale": [
|
|
19
|
+
"anyscale/meta-llama/Llama-2-13b-chat-hf",
|
|
20
|
+
"anyscale/meta-llama/Llama-2-70b-chat-hf",
|
|
21
|
+
],
|
|
22
|
+
"Cohere": [
|
|
23
|
+
"cohere/command-light",
|
|
24
|
+
"cohere/command-r-plus",
|
|
25
|
+
"cohere/command-nightly",
|
|
26
|
+
],
|
|
27
|
+
"DeepInfra": [
|
|
28
|
+
"deepinfra/meta-llama/Llama-2-70b-chat-hf",
|
|
29
|
+
"deepinfra/meta-llama/Llama-2-13b-chat-hf",
|
|
30
|
+
"deepinfra/codellama/CodeLlama-34b-Instruct-hf",
|
|
31
|
+
"deepinfra/mistralai/Mistral-7B-Instruct-v0.1",
|
|
32
|
+
"deepinfra/jondurbin/airoboros-l2-70b-gpt4-1.4.1",
|
|
33
|
+
],
|
|
34
|
+
"Gemini": [
|
|
35
|
+
"gemini/gemini-1.5-pro-latest",
|
|
36
|
+
"gemini/gemini-1.5-flash",
|
|
37
|
+
],
|
|
38
|
+
"Groq": [
|
|
39
|
+
"groq/llama3-8b-8192",
|
|
40
|
+
"groq/llama3-70b-8192",
|
|
41
|
+
"groq/llama2-70b-4096",
|
|
42
|
+
"groq/mixtral-8x7b-32768",
|
|
43
|
+
"groq/gemma-7b-it",
|
|
44
|
+
],
|
|
45
|
+
"Mistral": [
|
|
46
|
+
"mistral/mistral-tiny",
|
|
47
|
+
"mistral/mistral-small",
|
|
48
|
+
"mistral/mistral-medium",
|
|
49
|
+
"mistral/mistral-large-latest",
|
|
50
|
+
],
|
|
51
|
+
"Open AI": [
|
|
52
|
+
"gpt-3.5-turbo-1106",
|
|
53
|
+
"gpt-3.5-turbo",
|
|
54
|
+
"gpt-4",
|
|
55
|
+
"gpt-4o",
|
|
56
|
+
"gpt-4o-mini",
|
|
57
|
+
"gpt-4-1106-preview",
|
|
58
|
+
],
|
|
59
|
+
"OpenRouter": [
|
|
60
|
+
"openrouter/openai/gpt-3.5-turbo",
|
|
61
|
+
"openrouter/openai/gpt-3.5-turbo-16k",
|
|
62
|
+
"openrouter/anthropic/claude-instant-v1",
|
|
63
|
+
"openrouter/google/palm-2-chat-bison",
|
|
64
|
+
"openrouter/google/palm-2-codechat-bison",
|
|
65
|
+
"openrouter/meta-llama/llama-2-13b-chat",
|
|
66
|
+
"openrouter/meta-llama/llama-2-70b-chat",
|
|
67
|
+
],
|
|
68
|
+
"Perplexity AI": [
|
|
69
|
+
"perplexity/pplx-7b-chat",
|
|
70
|
+
"perplexity/pplx-70b-chat",
|
|
71
|
+
"perplexity/pplx-7b-online",
|
|
72
|
+
"perplexity/pplx-70b-online",
|
|
73
|
+
],
|
|
74
|
+
"Together AI": [
|
|
75
|
+
"together_ai/togethercomputer/llama-2-70b-chat",
|
|
76
|
+
"together_ai/togethercomputer/llama-2-70b",
|
|
77
|
+
"together_ai/togethercomputer/LLaMA-2-7B-32K",
|
|
78
|
+
"together_ai/togethercomputer/Llama-2-7B-32K-Instruct",
|
|
79
|
+
"together_ai/togethercomputer/llama-2-7b",
|
|
80
|
+
"together_ai/togethercomputer/alpaca-7b",
|
|
81
|
+
"together_ai/togethercomputer/CodeLlama-34b-Instruct",
|
|
82
|
+
"together_ai/togethercomputer/CodeLlama-34b-Python",
|
|
83
|
+
"together_ai/WizardLM/WizardCoder-Python-34B-V1.0",
|
|
84
|
+
"together_ai/NousResearch/Nous-Hermes-Llama2-13b",
|
|
85
|
+
"together_ai/Austism/chronos-hermes-13b",
|
|
86
|
+
],
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
providers_list = list(supported_llm_models.keys())
|
|
90
|
+
|
|
91
|
+
model_to_provider_mapping = {
|
|
92
|
+
model: provider
|
|
93
|
+
for provider, models in supported_llm_models.items()
|
|
94
|
+
for model in models
|
|
95
|
+
}
|