From 2a98aae53f9ab69526c229c9a3350743a4691fe9 Mon Sep 17 00:00:00 2001 From: Gonzalo Mellizo-Soto Date: Tue, 9 Apr 2024 01:23:17 +0200 Subject: [PATCH 1/9] Add agents command --- giza/cli.py | 8 ++ giza/client.py | 158 ++++++++++++++++++++++++++++ giza/commands/agents.py | 221 ++++++++++++++++++++++++++++++++++++++++ giza/schemas/agents.py | 29 ++++++ giza/utils/misc.py | 37 ++++++- 5 files changed, 452 insertions(+), 1 deletion(-) create mode 100644 giza/commands/agents.py create mode 100644 giza/schemas/agents.py diff --git a/giza/cli.py b/giza/cli.py index 1960969..2681929 100644 --- a/giza/cli.py +++ b/giza/cli.py @@ -4,6 +4,7 @@ from rich.traceback import install from giza.commands.actions import app as actions_app +from giza.commands.agents import app as agents_app from giza.commands.endpoints import app as deployments_app from giza.commands.endpoints import deploy from giza.commands.models import app as models_app @@ -27,6 +28,13 @@ help="""๐Ÿ’ป Utilities for managing users""", ) +app.add_typer( + agents_app, + name="agents", + short_help="๐Ÿ’ป Utilities for managing agents", + help="""๐Ÿ’ป Utilities for managing agents""", +) + app.add_typer( models_app, name="models", diff --git a/giza/client.py b/giza/client.py index b93e791..c8e959b 100644 --- a/giza/client.py +++ b/giza/client.py @@ -13,6 +13,7 @@ from rich import print, print_json from giza.schemas import users +from giza.schemas.agents import Agent, AgentCreate, AgentList, AgentUpdate from giza.schemas.endpoints import Endpoint, EndpointCreate, EndpointsList from giza.schemas.jobs import Job, JobCreate, JobList from giza.schemas.message import Msg @@ -1550,3 +1551,160 @@ def delete(self) -> None: self._echo_debug(str(response)) response.raise_for_status() + + +class AgentsClient(ApiClient): + """ + Client to interact with `agents` endpoint. + """ + + # Change once API is updated + AGENTS_ENDPOINT = "agents" + + @auth + def create( + self, + agent_create: AgentCreate, + ) -> Agent: + """ + Create a new agent. + + Args: + agent_create: Agent information to create + + Returns: + The recently created agent + """ + headers = copy.deepcopy(self.default_headers) + headers.update(self._get_auth_header()) + + response = self.session.post( + "/".join( + [ + self.url, + self.AGENTS_ENDPOINT, + ] + ), + headers=headers, + json=agent_create.model_dump(), + ) + self._echo_debug(str(response)) + + response.raise_for_status() + + return Agent(**response.json()) + + @auth + def list(self, params: Optional[Dict[str, str]] = None) -> AgentList: + """ + List endpoints. + + Returns: + A list of endpoints created by the user + """ + headers = copy.deepcopy(self.default_headers) + headers.update(self._get_auth_header()) + + response = self.session.get( + "/".join( + [ + self.url, + self.AGENTS_ENDPOINT, + ] + ), + headers=headers, + params=params, + ) + self._echo_debug(str(response)) + + response.raise_for_status() + + return AgentList(root=[Agent(**agent) for agent in response.json()]) + + @auth + def get(self, agent_id: int, params: Optional[Dict[str, Any]] = None) -> Agent: + """ + Get an agent. + + Args: + agent_id: Agent identifier + + Returns: + The agent information + """ + headers = copy.deepcopy(self.default_headers) + headers.update(self._get_auth_header()) + + response = self.session.get( + "/".join( + [ + self.url, + self.AGENTS_ENDPOINT, + str(agent_id), + ] + ), + headers=headers, + params=params, + ) + + self._echo_debug(str(response)) + response.raise_for_status() + + return Agent(**response.json()) + + @auth + def delete(self, agent_id: int) -> None: + """ + Delete an agent. + + Args: + agent_id: Agent identifier + """ + headers = copy.deepcopy(self.default_headers) + headers.update(self._get_auth_header()) + + response = self.session.delete( + "/".join( + [ + self.url, + self.AGENTS_ENDPOINT, + str(agent_id), + ] + ), + headers=headers, + ) + + self._echo_debug(str(response)) + response.raise_for_status() + + @auth + def patch(self, agent_id: int, agent_update: AgentUpdate) -> Agent: + """ + Update an agent. + + Args: + agent_id: Agent identifier + agent_update: Agent information to update + + Returns: + The updated agent information + """ + headers = copy.deepcopy(self.default_headers) + headers.update(self._get_auth_header()) + + response = self.session.patch( + "/".join( + [ + self.url, + self.AGENTS_ENDPOINT, + str(agent_id), + ] + ), + headers=headers, + json=agent_update.model_dump(exclude_none=True), + ) + print(agent_update.model_dump()) + self._echo_debug(str(response)) + response.raise_for_status() + + return Agent(**response.json()) diff --git a/giza/commands/agents.py b/giza/commands/agents.py new file mode 100644 index 0000000..692a94b --- /dev/null +++ b/giza/commands/agents.py @@ -0,0 +1,221 @@ +import json +import sys +from enum import StrEnum +from typing import List, Optional + +import typer +from rich import print_json +from rich.console import Console +from rich.table import Table + +from giza import API_HOST +from giza.client import AgentsClient, EndpointsClient +from giza.options import DEBUG_OPTION +from giza.schemas.agents import AgentCreate, AgentList, AgentUpdate +from giza.utils import echo +from giza.utils.exception_handling import ExceptionHandler +from giza.utils.misc import get_ape_accounts, get_parameters_from_str + +app = typer.Typer() + + +@app.command( + short_help="๐Ÿ•ต๏ธโ€โ™‚๏ธ Creates an agent to interact with smart contracts", + help="""๐Ÿ•ต๏ธโ€โ™‚๏ธ Creates an agent to interact with smart contracts. + + This command will create an agent to use in Giza. The agent is used to interact with smart contracts and perform inference requests. + The agent will handle the communication between the user account (wallet) and the smart contract, while also providing the handling of proof verification. + """, +) +def create( + model_id: int = typer.Option( + None, + "--model-id", + "-m", + help="The ID of the model used to create the agent", + ), + version_id: int = typer.Option( + None, + "--version-id", + "-v", + help="The ID of the version used to create the agent", + ), + endpoint_id: int = typer.Option( + None, + "--endpoint-id", + "-e", + help="The ID of the endpoint used to create the agent", + ), + name: Optional[str] = typer.Option( + None, "--name", "-n", help="The name of the agent" + ), + description: Optional[str] = typer.Option( + None, "--description", "-d", help="The description of the agent" + ), + debug: Optional[bool] = DEBUG_OPTION, +) -> None: + echo("Creating agent โœ… ") + + if not model_id and not version_id and not endpoint_id: + echo.error("Please provide a model id and version id or endpoint id") + sys.exit(1) + elif endpoint_id: + echo.info( + "Using endpoint id to create agent, retrieving model id and version id" + ) + endpoints_client = EndpointsClient(API_HOST) + endpoint = endpoints_client.get(endpoint_id) + model_id = endpoint.model_id + version_id = endpoint.version_id + elif model_id and version_id: + echo.info("Using model id and version id to create agent") + with ExceptionHandler(debug=debug): + client = AgentsClient(API_HOST) + available_accounts = get_ape_accounts() + if available_accounts == {}: + echo.error( + "No available accounts found. Please create an account first running `ape accounts generate `." + ) + sys.exit(1) + table = Table() + + table.add_column("Accounts", justify="center", style="orange3") + for account in available_accounts: + table.add_row(account) + + echo.info("Select an existing account to create the agent.") + echo.info("Available accounts are:") + console = Console() + console.print(table) + + accounts_enum = StrEnum( # type: ignore + "Accounts", {account: account for account in available_accounts} + ) + selected_account = typer.prompt("Enter the account name", type=accounts_enum) + + with open(str(available_accounts.get(selected_account))) as f: + keyfile = json.load(f) + + agent_create = AgentCreate( + name=name, + description=description, + parameters={ + "model_id": model_id, + "version_id": version_id, + "endpoint_id": endpoint_id, + "alias": selected_account, + "account_data": keyfile, + }, + ) + agent = client.create(agent_create) + print_json(agent.model_dump_json()) + + +@app.command( + short_help="๐Ÿ“œ List the available agents.", + help="""๐Ÿ“œ Lists all the available agents in Giza. + This command retrieves and displays a list of all agents stored in the server. + Each agent information is printed in a json format for easy readability and further processing. + If there are no agents available, an empty list is printed. + """, +) +def list( + parameters: Optional[List[str]] = typer.Option( + None, "--parameters", "-p", help="The parameters of the agent" + ), + debug: Optional[bool] = DEBUG_OPTION, +) -> None: + echo("Listing agents โœ… ") + with ExceptionHandler(debug=debug): + client = AgentsClient(API_HOST) + q = get_parameters_from_str(parameters) if parameters else None + if q: + echo(f"Filtering agents with parameters: {q}") + params = {"q": [f"{k}=={v}" for k, v in q.items()]} + agents: AgentList = client.list(params=params) + print_json(agents.model_dump_json()) + + +# giza/commands/deployments.py +@app.command( + short_help="๐ŸŽฏ Get an agent.", + help="""๐ŸŽฏ Get a specific agent in Giza. + This command retrieves and displays a specific agent stored in the server. + The agent information is printed in a json format for easy readability and further processing. + If the agent is not available, an error message is printed. + """, +) +def get( + agent_id: int = typer.Option( + None, + "--agent-id", + "-a", + help="The ID of the agent", + ), + debug: Optional[bool] = DEBUG_OPTION, +) -> None: + echo(f"Getting agent {agent_id} โœ… ") + with ExceptionHandler(debug=debug): + client = AgentsClient(API_HOST) + deployment = client.get(agent_id) + print_json(deployment.model_dump_json()) + + +@app.command( + name="delete", + short_help="๐Ÿ—‘๏ธ Deletes an agent.", + help="""๐Ÿ—‘๏ธ Deletes an agent and erases all the metadata from Giza. + + This command will remove the `agent` metadata from Giza. The agent will no longer be available for use. + """, +) +def delete_agent( + agent_id: int = typer.Option( + None, + "--agent-id", + "-a", + help="The ID of the agent", + ), + debug: Optional[bool] = DEBUG_OPTION, +) -> None: + echo(f"Deleting agent {agent_id} โœ… ") + with ExceptionHandler(debug=debug): + client = AgentsClient(API_HOST) + client.delete(agent_id) + echo(f"Agent {agent_id} deleted โœ… ") + + +@app.command( + short_help="๐Ÿ”„ Updates an agent.", + help="""๐Ÿ”„ Updates an agent in Giza. + + This command will update the agent metadata in Giza. The agent information will be updated with the provided parameters. + """, +) +def update( + agent_id: int = typer.Option( + None, + "--agent-id", + "-a", + help="The ID of the agent", + ), + name: Optional[str] = typer.Option( + None, "--name", "-n", help="The name of the agent" + ), + description: Optional[str] = typer.Option( + None, "--description", "-d", help="The description of the agent" + ), + parameters: Optional[List[str]] = typer.Option( + None, "--parameters", "-p", help="The parameters of the agent" + ), + debug: Optional[bool] = DEBUG_OPTION, +) -> None: + echo(f"Updating agent {agent_id} โœ… ") + with ExceptionHandler(debug=debug): + client = AgentsClient(API_HOST) + update_params = get_parameters_from_str(parameters) if parameters else None + agent_update = AgentUpdate( + name=name, description=description, parameters=update_params + ) + agent = client.patch(agent_id, agent_update) + print_json(agent.model_dump_json()) diff --git a/giza/schemas/agents.py b/giza/schemas/agents.py new file mode 100644 index 0000000..af01745 --- /dev/null +++ b/giza/schemas/agents.py @@ -0,0 +1,29 @@ +import datetime +from typing import Any, Dict, Optional + +from pydantic import BaseModel, RootModel + + +class Agent(BaseModel): + id: int + name: Optional[str] = None + description: Optional[str] = None + parameters: Dict[str, Any] = {} + created_date: Optional[datetime.datetime] = None + last_update: Optional[datetime.datetime] = None + + +class AgentUpdate(BaseModel): + name: Optional[str] = None + description: Optional[str] = None + parameters: Optional[Dict[str, Any]] = None + + +class AgentCreate(BaseModel): + name: Optional[str] = None + description: Optional[str] = None + parameters: Dict[str, Any] = {} + + +class AgentList(RootModel): + root: list[Agent] diff --git a/giza/utils/misc.py b/giza/utils/misc.py index 8e3f5ce..ec44d40 100644 --- a/giza/utils/misc.py +++ b/giza/utils/misc.py @@ -3,7 +3,8 @@ import subprocess import zipfile from io import BytesIO -from typing import Optional +from pathlib import Path +from typing import Dict, List, Optional from giza.exceptions import PasswordError, ScarbBuildError, ScarbNotFound from giza.utils import echo @@ -100,3 +101,37 @@ def scarb_build(folder) -> None: echo.error("Compilation failed") raise ScarbBuildError("Compilation failed") from e echo("Compilation successful") + + +def get_ape_accounts() -> Dict[str, Path]: + """ + Get the available APE accounts. + + Returns: + list: list of available APE accounts + """ + home = Path.home() + ape_home = home / ".ape" / "accounts" + + if not ape_home.exists(): + return {} + + accounts_paths = list(ape_home.glob("*")) + accounts = [ + account_path.name.removesuffix(".json") for account_path in accounts_paths + ] + + return dict(zip(accounts, accounts_paths, strict=False)) + + +def get_parameters_from_str(parameters: List[str]) -> Dict[str, str]: + """ + Get the parameters from a string. + + Args: + parameters (List[str]): parameters + + Returns: + Dict[str, str]: parameters + """ + return dict([param.split("=") for param in parameters]) From 8e6dd5bc862e22de1f40c234b7e94bd8f5e66596 Mon Sep 17 00:00:00 2001 From: Gonzalo Mellizo-Soto Date: Tue, 9 Apr 2024 11:11:38 +0200 Subject: [PATCH 2/9] Remove print --- giza/client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/giza/client.py b/giza/client.py index c8e959b..66bc1ae 100644 --- a/giza/client.py +++ b/giza/client.py @@ -1703,7 +1703,6 @@ def patch(self, agent_id: int, agent_update: AgentUpdate) -> Agent: headers=headers, json=agent_update.model_dump(exclude_none=True), ) - print(agent_update.model_dump()) self._echo_debug(str(response)) response.raise_for_status() From 16a82e9a644c68228b160175d9c2d09943fa3712 Mon Sep 17 00:00:00 2001 From: Gonzalo Mellizo-Soto Date: Tue, 9 Apr 2024 11:49:00 +0200 Subject: [PATCH 3/9] Add agents tests --- giza/commands/agents.py | 21 ++- giza/utils/misc.py | 15 ++ tests/commands/test_agents.py | 292 ++++++++++++++++++++++++++++++++++ 3 files changed, 322 insertions(+), 6 deletions(-) create mode 100644 tests/commands/test_agents.py diff --git a/giza/commands/agents.py b/giza/commands/agents.py index 692a94b..669ebf1 100644 --- a/giza/commands/agents.py +++ b/giza/commands/agents.py @@ -1,4 +1,3 @@ -import json import sys from enum import StrEnum from typing import List, Optional @@ -14,7 +13,7 @@ from giza.schemas.agents import AgentCreate, AgentList, AgentUpdate from giza.utils import echo from giza.utils.exception_handling import ExceptionHandler -from giza.utils.misc import get_ape_accounts, get_parameters_from_str +from giza.utils.misc import get_ape_accounts, get_parameters_from_str, load_json_file app = typer.Typer() @@ -93,8 +92,7 @@ def create( ) selected_account = typer.prompt("Enter the account name", type=accounts_enum) - with open(str(available_accounts.get(selected_account))) as f: - keyfile = json.load(f) + keyfile = load_json_file(str(available_accounts.get(selected_account))) agent_create = AgentCreate( name=name, @@ -115,6 +113,10 @@ def create( short_help="๐Ÿ“œ List the available agents.", help="""๐Ÿ“œ Lists all the available agents in Giza. This command retrieves and displays a list of all agents stored in the server. + + To filter by parameters, use the `--parameters` flag. The parameters should be provided in the format `key=value`. + Example: `--parameters key1=value1 --parameters key2=value2` + Each agent information is printed in a json format for easy readability and further processing. If there are no agents available, an empty list is printed. """, @@ -131,8 +133,10 @@ def list( q = get_parameters_from_str(parameters) if parameters else None if q: echo(f"Filtering agents with parameters: {q}") - params = {"q": [f"{k}=={v}" for k, v in q.items()]} - agents: AgentList = client.list(params=params) + query_params = {"q": [f"{k}=={v}" for k, v in q.items()]} + else: + query_params = None + agents: AgentList = client.list(params=query_params) print_json(agents.model_dump_json()) @@ -190,6 +194,11 @@ def delete_agent( help="""๐Ÿ”„ Updates an agent in Giza. This command will update the agent metadata in Giza. The agent information will be updated with the provided parameters. + + To update the parameters, use the `--parameters` flag. The parameters should be provided in the format `key=value`. + Example: `--parameters key1=value1 --parameters key2=value2` + + The updated agent information is printed in a json format for easy readability and further processing. """, ) def update( diff --git a/giza/utils/misc.py b/giza/utils/misc.py index ec44d40..37b8755 100644 --- a/giza/utils/misc.py +++ b/giza/utils/misc.py @@ -1,3 +1,4 @@ +import json import os import re import subprocess @@ -135,3 +136,17 @@ def get_parameters_from_str(parameters: List[str]) -> Dict[str, str]: Dict[str, str]: parameters """ return dict([param.split("=") for param in parameters]) + + +def load_json_file(file_path: str) -> Dict: + """ + Load a json file. + + Args: + file_path (str): path to the file + + Returns: + Dict: json content + """ + with open(file_path) as file_: + return json.load(file_) diff --git a/tests/commands/test_agents.py b/tests/commands/test_agents.py new file mode 100644 index 0000000..97586c1 --- /dev/null +++ b/tests/commands/test_agents.py @@ -0,0 +1,292 @@ +from pathlib import Path +from unittest.mock import patch + +from giza.commands.agents import AgentsClient, EndpointsClient +from giza.schemas.agents import Agent, AgentList, AgentUpdate +from giza.schemas.endpoints import Endpoint +from tests.conftest import invoke_cli_runner + + +def test_get_agent(): + """ + Test the `get` command of the `agents` command group. + """ + + agent = Agent( + id=1, + name="test agent", + description="test", + parameters={}, + ) + with patch.object(AgentsClient, "get", return_value=agent) as mock_get: + result = invoke_cli_runner( + [ + "agents", + "get", + "--agent-id", + "1", + ] + ) + mock_get.assert_called_once() + assert result.exit_code == 0 + assert "test agent" in result.output + + +def test_create_agent_with_model_id_and_version_id(): + """ + Test the `create` command of the `agents` command group with model id and version id. + """ + + agent = Agent( + id=1, + name="test agent", + description="test", + parameters={}, + ) + with patch.object(AgentsClient, "create", return_value=agent) as mock_create, patch( + "giza.commands.agents.get_ape_accounts", + return_value={"test": Path("dummy.json")}, + ) as mock_accounts, patch( + "typer.prompt", side_effect=["test"] + ) as mock_prompt, patch( + "giza.commands.agents.load_json_file", return_value={} + ) as mock_load: + result = invoke_cli_runner( + [ + "agents", + "create", + "--model-id", + "1", + "--version-id", + "1", + "--name", + "test agent", + "--description", + "test", + ] + ) + mock_create.assert_called_once() + mock_accounts.assert_called_once() + mock_prompt.assert_called_once() + mock_load.assert_called_once() + assert result.exit_code == 0 + assert "Using model id and version id to create agent" in result.output + assert "test agent" in result.output + + +def test_create_agent_with_endpoint_id(): + """ + Test the `create` command of the `agents` command group with model id and version id. + """ + + agent = Agent( + id=1, + name="test agent endpoint", + description="test", + parameters={}, + ) + with patch.object(AgentsClient, "create", return_value=agent) as mock_create, patch( + "giza.commands.agents.get_ape_accounts", + return_value={"test": Path("dummy.json")}, + ) as mock_accounts, patch( + "typer.prompt", side_effect=["test"] + ) as mock_prompt, patch( + "giza.commands.agents.load_json_file", return_value={} + ) as mock_load, patch.object( + EndpointsClient, + "get", + return_value=Endpoint(id=1, size="S", model_id=1, version_id=1, is_active=True), + ) as mock_endpoints: + result = invoke_cli_runner( + [ + "agents", + "create", + "--endpoint-id", + "1", + "--name", + "test agent endpoint", + "--description", + "test", + ] + ) + mock_create.assert_called_once() + mock_accounts.assert_called_once() + mock_prompt.assert_called_once() + mock_load.assert_called_once() + mock_endpoints.assert_called_once() + assert result.exit_code == 0 + assert "Using endpoint id to create agent" in result.output + assert "test agent endpoint" in result.output + + +def test_create_agent_no_ids(): + """ + Test the `create` command of the `agents` command group with model id and version id. + """ + result = invoke_cli_runner( + [ + "agents", + "create", + "--name", + "test agent", + "--description", + "test", + ], + expected_error=True, + ) + assert result.exit_code == 1 + assert "Please provide a model id and version id or endpoint id" in result.output + + +def test_list_agents(): + """ + Test the `list` command of the `agents` command group. + """ + + agents = AgentList( + root=[ + Agent( + id=1, + name="test agent", + description="test", + parameters={}, + ), + Agent( + id=2, + name="test agent 2", + description="test", + parameters={}, + ), + ] + ) + with patch.object(AgentsClient, "list", return_value=agents) as mock_list: + result = invoke_cli_runner( + [ + "agents", + "list", + ] + ) + + mock_list.assert_called_once() + assert result.exit_code == 0 + assert "test agent" in result.output + assert "test agent 2" in result.output + + +def test_list_agents_with_params(): + """ + Test the `list` command of the `agents` command group. + """ + + agents = AgentList( + root=[ + Agent( + id=1, + name="test agent", + description="test", + parameters={ + "account": "test", + }, + ), + ] + ) + with patch.object(AgentsClient, "list", return_value=agents) as mock_list: + result = invoke_cli_runner( + [ + "agents", + "list", + "--parameters", + "account=test", + ] + ) + + mock_list.assert_called_once_with(params={"q": ["account==test"]}) + assert result.exit_code == 0 + assert "test agent" in result.output + + +def test_delete_agent(): + """ + Test the `delete` command of the `agents` command group. + """ + + with patch.object(AgentsClient, "delete") as mock_delete: + result = invoke_cli_runner( + [ + "agents", + "delete", + "--agent-id", + "1", + ] + ) + mock_delete.assert_called_once() + assert result.exit_code == 0 + assert "Agent 1 deleted" in result.output + + +def test_update_agent(): + """ + Test the `update` command of the `agents` command group. + """ + + agent = Agent( + id=1, + name="updated agent", + description="test", + parameters={}, + ) + with patch.object(AgentsClient, "patch", return_value=agent) as mock_patch: + result = invoke_cli_runner( + [ + "agents", + "update", + "--agent-id", + "1", + "--name", + "test agent", + "--description", + "test", + ] + ) + mock_patch.assert_called_once() + assert result.exit_code == 0 + assert "updated agent" in result.output + + +def test_update_agent_with_parameters(): + """ + Test the `update` command of the `agents` command group. + """ + + agent = Agent( + id=1, + name="test agent", + description="test", + parameters={ + "account": "test", + }, + ) + with patch.object(AgentsClient, "patch", return_value=agent) as mock_patch: + result = invoke_cli_runner( + [ + "agents", + "update", + "--agent-id", + "1", + "--name", + "test agent", + "--description", + "test", + "--parameters", + "account=test", + ] + ) + mock_patch.assert_called_once_with( + 1, + AgentUpdate( + name="test agent", description="test", parameters={"account": "test"} + ), + ) + assert result.exit_code == 0 + assert "test agent" in result.output + assert "account" in result.output From 69dbdb5a722bf8bcec33d753ed98af842ba40124 Mon Sep 17 00:00:00 2001 From: Gonzalo Mellizo-Soto Date: Tue, 9 Apr 2024 15:53:12 +0200 Subject: [PATCH 4/9] Bumping version from 0.14.1 to 0.15.0 --- docs/README.md | 2 +- docs/examples/full_transpilation.md | 2 +- examples/mnist/mnist_pytorch.ipynb | 2 +- examples/mnist/requirements.txt | 2 +- giza/__init__.py | 2 +- pyproject.toml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/README.md b/docs/README.md index 9887b82..9d094a2 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,5 +1,5 @@ --- -description: Giza CLI 0.14.1 +description: Giza CLI 0.15.0 --- # Giza CLI diff --git a/docs/examples/full_transpilation.md b/docs/examples/full_transpilation.md index 0572cca..470d0f3 100644 --- a/docs/examples/full_transpilation.md +++ b/docs/examples/full_transpilation.md @@ -21,7 +21,7 @@ pip install -r requirements.txt Or: ```bash -pip install giza-cli==0.14.1 onnx==1.14.1 torch==2.1.0 torchvision==0.16.0 +pip install giza-cli==0.15.0 onnx==1.14.1 torch==2.1.0 torchvision==0.16.0 ``` We will use the libraries for the following purposes: diff --git a/examples/mnist/mnist_pytorch.ipynb b/examples/mnist/mnist_pytorch.ipynb index ffae75a..fe0ba78 100644 --- a/examples/mnist/mnist_pytorch.ipynb +++ b/examples/mnist/mnist_pytorch.ipynb @@ -41,7 +41,7 @@ "Or:\n", "\n", "```bash\n", - "pip install giza-cli==0.14.1 onnx==1.14.1 torch==2.1.0 torchvision==0.16.0\n", + "pip install giza-cli==0.15.0 onnx==1.14.1 torch==2.1.0 torchvision==0.16.0\n", "```\n", "\n", "We will use the libraries for the following purposes:\n", diff --git a/examples/mnist/requirements.txt b/examples/mnist/requirements.txt index afa2249..ae29df2 100644 --- a/examples/mnist/requirements.txt +++ b/examples/mnist/requirements.txt @@ -1,4 +1,4 @@ -giza-cli==0.14.1 +giza-cli==0.15.0 onnx==1.14.1 tf2onnx==1.15.1 torch==2.1.0 diff --git a/giza/__init__.py b/giza/__init__.py index 1909ef8..3588b8c 100644 --- a/giza/__init__.py +++ b/giza/__init__.py @@ -1,5 +1,5 @@ import os -__version__ = "0.14.1" +__version__ = "0.15.0" # Until DNS is fixed API_HOST = os.environ.get("GIZA_API_HOST", "https://api.gizatech.xyz") diff --git a/pyproject.toml b/pyproject.toml index a57cdcf..351d821 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "giza-cli" -version = "0.14.1" +version = "0.15.0" description = "CLI for interacting with Giza" authors = ["Gonzalo Mellizo-Soto "] readme = "README.md" From 19ab2e22be74d3e47019fb5426906db45e9dcbb8 Mon Sep 17 00:00:00 2001 From: Gonzalo Mellizo-Soto Date: Tue, 9 Apr 2024 16:41:33 +0200 Subject: [PATCH 5/9] Fix small error --- giza/commands/agents.py | 5 +++++ tests/commands/test_agents.py | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/giza/commands/agents.py b/giza/commands/agents.py index 669ebf1..bea4e08 100644 --- a/giza/commands/agents.py +++ b/giza/commands/agents.py @@ -68,6 +68,11 @@ def create( version_id = endpoint.version_id elif model_id and version_id: echo.info("Using model id and version id to create agent") + endpoints_client = EndpointsClient(API_HOST) + endpoint = endpoints_client.list( + params={"model_id": model_id, "version_id": version_id} + ).root[0] + endpoint_id = endpoint.id with ExceptionHandler(debug=debug): client = AgentsClient(API_HOST) available_accounts = get_ape_accounts() diff --git a/tests/commands/test_agents.py b/tests/commands/test_agents.py index 97586c1..465c032 100644 --- a/tests/commands/test_agents.py +++ b/tests/commands/test_agents.py @@ -3,7 +3,7 @@ from giza.commands.agents import AgentsClient, EndpointsClient from giza.schemas.agents import Agent, AgentList, AgentUpdate -from giza.schemas.endpoints import Endpoint +from giza.schemas.endpoints import Endpoint, EndpointsList from tests.conftest import invoke_cli_runner @@ -50,7 +50,13 @@ def test_create_agent_with_model_id_and_version_id(): "typer.prompt", side_effect=["test"] ) as mock_prompt, patch( "giza.commands.agents.load_json_file", return_value={} - ) as mock_load: + ) as mock_load, patch.object( + EndpointsClient, + "list", + return_value=EndpointsList( + root=[Endpoint(id=1, size="S", model_id=1, version_id=1, is_active=True)] + ), + ) as mock_endpoints: result = invoke_cli_runner( [ "agents", @@ -69,6 +75,8 @@ def test_create_agent_with_model_id_and_version_id(): mock_accounts.assert_called_once() mock_prompt.assert_called_once() mock_load.assert_called_once() + mock_endpoints.assert_called_once() + assert result.exit_code == 0 assert "Using model id and version id to create agent" in result.output assert "test agent" in result.output From 071aaccf7c5161132e5f044239d3c2a6130dc2ad Mon Sep 17 00:00:00 2001 From: Gonzalo Mellizo-Soto Date: Wed, 10 Apr 2024 13:00:50 +0200 Subject: [PATCH 6/9] Add agents commands documentation --- docs/SUMMARY.md | 1 + docs/reference/api/README.md | 10 + docs/reference/api/cli.md | 2 +- docs/reference/api/client.md | 377 +++++++++++++++++------ docs/reference/api/commands.actions.md | 2 +- docs/reference/api/commands.agents.md | 152 +++++++++ docs/reference/api/commands.endpoints.md | 6 +- docs/reference/api/commands.users.md | 10 +- docs/reference/api/utils.misc.md | 75 ++++- docs/resources/agents.md | 159 ++++++++++ 10 files changed, 688 insertions(+), 106 deletions(-) create mode 100644 docs/reference/api/commands.agents.md create mode 100644 docs/resources/agents.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index a74a959..cf54d6e 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -15,6 +15,7 @@ * [Versions](resources/versions.md) * [Workspaces](resources/workspaces.md) * [Endpoints](resources/endpoints.md) +* [Agents](resources/agents.md) ## ๐Ÿ“š Frameworks diff --git a/docs/reference/api/README.md b/docs/reference/api/README.md index 73def96..08a5576 100644 --- a/docs/reference/api/README.md +++ b/docs/reference/api/README.md @@ -9,6 +9,7 @@ - [`client`](./client.md#module-client) - [`commands`](./commands.md#module-commands) - [`commands.actions`](./commands.actions.md#module-commandsactions) +- [`commands.agents`](./commands.agents.md#module-commandsagents) - [`commands.endpoints`](./commands.endpoints.md#module-commandsendpoints) - [`commands.models`](./commands.models.md#module-commandsmodels) - [`commands.prove`](./commands.prove.md#module-commandsprove) @@ -32,6 +33,7 @@ ## Classes +- [`client.AgentsClient`](./client.md#class-agentsclient): Client to interact with `agents` endpoint. - [`client.ApiClient`](./client.md#class-apiclient): Implementation of the API client to interact with core-services - [`client.EndpointsClient`](./client.md#class-endpointsclient): Client to interact with `endpoints` endpoint. - [`client.EndpointsClient`](./client.md#class-endpointsclient): Client to interact with `endpoints` endpoint. @@ -61,6 +63,11 @@ - [`callbacks.version_callback`](./callbacks.md#function-version_callback): Prints the current version when `--version` flag is added to a call. - [`cli.entrypoint`](./cli.md#function-entrypoint) - [`actions.new`](./commands.actions.md#function-new): This command will create a new action by generating a Python project. +- [`agents.create`](./commands.agents.md#function-create) +- [`agents.delete_agent`](./commands.agents.md#function-delete_agent) +- [`agents.get`](./commands.agents.md#function-get) +- [`agents.list`](./commands.agents.md#function-list) +- [`agents.update`](./commands.agents.md#function-update) - [`endpoints.delete_endpoint`](./commands.endpoints.md#function-delete_endpoint) - [`endpoints.deploy`](./commands.endpoints.md#function-deploy) - [`endpoints.download_proof`](./commands.endpoints.md#function-download_proof) @@ -105,5 +112,8 @@ - [`utils.get_response_info`](./utils.md#function-get_response_info): Utility to retrieve information of the client response. - [`decorators.auth`](./utils.decorators.md#function-auth): Check that we have the token and it is not expired before executing - [`misc.download_model_or_sierra`](./utils.misc.md#function-download_model_or_sierra): Download the model or sierra file. +- [`misc.get_ape_accounts`](./utils.misc.md#function-get_ape_accounts): Get the available APE accounts. +- [`misc.get_parameters_from_str`](./utils.misc.md#function-get_parameters_from_str): Get the parameters from a string. +- [`misc.load_json_file`](./utils.misc.md#function-load_json_file): Load a json file. - [`misc.scarb_build`](./utils.misc.md#function-scarb_build): Build the scarb model. - [`misc.zip_folder`](./utils.misc.md#function-zip_folder): Zip the folder to a specific location. diff --git a/docs/reference/api/cli.md b/docs/reference/api/cli.md index f85e4c1..0d692ce 100644 --- a/docs/reference/api/cli.md +++ b/docs/reference/api/cli.md @@ -13,7 +13,7 @@ --- - + ## function `entrypoint` diff --git a/docs/reference/api/client.md b/docs/reference/api/client.md index 9ffd4ab..31aa326 100644 --- a/docs/reference/api/client.md +++ b/docs/reference/api/client.md @@ -17,12 +17,12 @@ --- - + ## class `ApiClient` Implementation of the API client to interact with core-services - + ### method `__init__` @@ -46,7 +46,7 @@ __init__( --- - + ### method `retrieve_api_key` @@ -70,7 +70,7 @@ Retrieve the API key from the `~/.giza/.api_key.json` file. --- - + ### method `retrieve_token` @@ -103,12 +103,12 @@ First, it will try to get it from GIZA_TOKEN. Second, from ~/.giza/.credentials --- - + ## class `UsersClient` Client to interact with `users` endpoint. - + ### method `__init__` @@ -132,7 +132,7 @@ __init__( --- - + ### method `create` @@ -156,7 +156,7 @@ Call the API to create a new user --- - + ### method `create_api_key` @@ -174,7 +174,7 @@ Call the API to create a new API key --- - + ### method `me` @@ -192,7 +192,7 @@ Retrieve information about the current user. Must have a valid token to perform --- - + ### method `request_reset_password_token` @@ -216,7 +216,7 @@ Sends a request to the server to generate a password reset token. The token is s --- - + ### method `resend_email` @@ -240,7 +240,7 @@ Resend the verification email to the user. --- - + ### method `reset_password` @@ -265,7 +265,7 @@ Resets the user's password using the provided token and new password. --- - + ### method `retrieve_api_key` @@ -289,7 +289,7 @@ Retrieve the API key from the `~/.giza/.api_key.json` file. --- - + ### method `retrieve_token` @@ -322,12 +322,12 @@ First, it will try to get it from GIZA_TOKEN. Second, from ~/.giza/.credentials --- - + ## class `EndpointsClient` Client to interact with `endpoints` endpoint. - + ### method `__init__` @@ -351,7 +351,7 @@ __init__( --- - + ### method `create` @@ -379,7 +379,7 @@ Create a new deployment. --- - + ### method `delete` @@ -397,7 +397,7 @@ Delete an endpoint. --- - + ### method `download_proof` @@ -420,7 +420,7 @@ Download a proof. --- - + ### method `get` @@ -443,7 +443,7 @@ Get a deployment. --- - + ### method `get_proof` @@ -460,7 +460,7 @@ Return information about a specific proof. `proof_if` is the identifier of the p --- - + ### method `list` @@ -477,7 +477,7 @@ List endpoints. --- - + ### method `list_jobs` @@ -494,7 +494,7 @@ List proofs. --- - + ### method `list_proofs` @@ -511,7 +511,7 @@ List proofs. --- - + ### method `retrieve_api_key` @@ -535,7 +535,7 @@ Retrieve the API key from the `~/.giza/.api_key.json` file. --- - + ### method `retrieve_token` @@ -568,12 +568,12 @@ First, it will try to get it from GIZA_TOKEN. Second, from ~/.giza/.credentials --- - + ## class `EndpointsClient` Client to interact with `endpoints` endpoint. - + ### method `__init__` @@ -597,7 +597,7 @@ __init__( --- - + ### method `create` @@ -625,7 +625,7 @@ Create a new deployment. --- - + ### method `delete` @@ -643,7 +643,7 @@ Delete an endpoint. --- - + ### method `download_proof` @@ -666,7 +666,7 @@ Download a proof. --- - + ### method `get` @@ -689,7 +689,7 @@ Get a deployment. --- - + ### method `get_proof` @@ -706,7 +706,7 @@ Return information about a specific proof. `proof_if` is the identifier of the p --- - + ### method `list` @@ -723,7 +723,7 @@ List endpoints. --- - + ### method `list_jobs` @@ -740,7 +740,7 @@ List proofs. --- - + ### method `list_proofs` @@ -757,7 +757,7 @@ List proofs. --- - + ### method `retrieve_api_key` @@ -781,7 +781,7 @@ Retrieve the API key from the `~/.giza/.api_key.json` file. --- - + ### method `retrieve_token` @@ -814,12 +814,12 @@ First, it will try to get it from GIZA_TOKEN. Second, from ~/.giza/.credentials --- - + ## class `TranspileClient` Client to interact with `users` endpoint. - + ### method `__init__` @@ -843,7 +843,7 @@ __init__( --- - + ### method `retrieve_api_key` @@ -867,7 +867,7 @@ Retrieve the API key from the `~/.giza/.api_key.json` file. --- - + ### method `retrieve_token` @@ -899,7 +899,7 @@ First, it will try to get it from GIZA_TOKEN. Second, from ~/.giza/.credentials --- - + ### method `transpile` @@ -923,7 +923,7 @@ Make a call to the API transpile endpoint with the model as a file. --- - + ### method `update_transpilation` @@ -952,12 +952,12 @@ Make a call to the API transpile endpoint with the model as a file. --- - + ## class `ModelsClient` Client to interact with `models` endpoint. - + ### method `__init__` @@ -981,7 +981,7 @@ __init__( --- - + ### method `create` @@ -1011,7 +1011,7 @@ Create a new model. --- - + ### method `get` @@ -1035,7 +1035,7 @@ Make a call to the API to retrieve model information. --- - + ### method `get_by_name` @@ -1059,7 +1059,7 @@ Make a call to the API to retrieve model information by its name. --- - + ### method `list` @@ -1076,7 +1076,7 @@ List all the models related to the user. --- - + ### method `retrieve_api_key` @@ -1100,7 +1100,7 @@ Retrieve the API key from the `~/.giza/.api_key.json` file. --- - + ### method `retrieve_token` @@ -1132,7 +1132,7 @@ First, it will try to get it from GIZA_TOKEN. Second, from ~/.giza/.credentials --- - + ### method `update` @@ -1158,12 +1158,12 @@ Update a model. --- - + ## class `JobsClient` Client to interact with `jobs` endpoint. - + ### method `__init__` @@ -1187,7 +1187,7 @@ __init__( --- - + ### method `create` @@ -1222,7 +1222,7 @@ Create a new job. --- - + ### method `get` @@ -1246,7 +1246,7 @@ Make a call to the API to retrieve job information. --- - + ### method `list` @@ -1263,7 +1263,7 @@ List jobs. --- - + ### method `retrieve_api_key` @@ -1287,7 +1287,7 @@ Retrieve the API key from the `~/.giza/.api_key.json` file. --- - + ### method `retrieve_token` @@ -1320,12 +1320,12 @@ First, it will try to get it from GIZA_TOKEN. Second, from ~/.giza/.credentials --- - + ## class `VersionJobsClient` Client to interact with `jobs` endpoint. - + ### method `__init__` @@ -1349,7 +1349,7 @@ __init__( --- - + ### method `create` @@ -1385,7 +1385,7 @@ Create a new job. --- - + ### method `get` @@ -1409,7 +1409,7 @@ Make a call to the API to retrieve job information. --- - + ### method `list` @@ -1426,7 +1426,7 @@ List jobs. --- - + ### method `retrieve_api_key` @@ -1450,7 +1450,7 @@ Retrieve the API key from the `~/.giza/.api_key.json` file. --- - + ### method `retrieve_token` @@ -1483,12 +1483,12 @@ First, it will try to get it from GIZA_TOKEN. Second, from ~/.giza/.credentials --- - + ## class `ProofsClient` Client to interact with `proofs` endpoint. - + ### method `__init__` @@ -1512,7 +1512,7 @@ __init__( --- - + ### method `download` @@ -1535,7 +1535,7 @@ Download a proof. --- - + ### method `get` @@ -1559,7 +1559,7 @@ Make a call to the API to retrieve proof information. --- - + ### method `get_by_job_id` @@ -1583,7 +1583,7 @@ Make a call to the API to retrieve proof information based on the job id. --- - + ### method `list` @@ -1600,7 +1600,7 @@ List all the proofs related to the user. --- - + ### method `retrieve_api_key` @@ -1624,7 +1624,7 @@ Retrieve the API key from the `~/.giza/.api_key.json` file. --- - + ### method `retrieve_token` @@ -1657,12 +1657,12 @@ First, it will try to get it from GIZA_TOKEN. Second, from ~/.giza/.credentials --- - + ## class `VersionsClient` Client to interact with `versions` endpoint. - + ### method `__init__` @@ -1686,7 +1686,7 @@ __init__( --- - + ### method `create` @@ -1714,7 +1714,7 @@ Create a new version. --- - + ### method `download` @@ -1739,7 +1739,7 @@ Download a version. --- - + ### method `download_original` @@ -1763,7 +1763,7 @@ Download the original version. --- - + ### method `get` @@ -1787,7 +1787,7 @@ Get a version. --- - + ### method `list` @@ -1810,7 +1810,7 @@ List all the versions related to a model. --- - + ### method `retrieve_api_key` @@ -1834,7 +1834,7 @@ Retrieve the API key from the `~/.giza/.api_key.json` file. --- - + ### method `retrieve_token` @@ -1866,7 +1866,7 @@ First, it will try to get it from GIZA_TOKEN. Second, from ~/.giza/.credentials --- - + ### method `update` @@ -1891,7 +1891,7 @@ Update a specific version. --- - + ### method `upload_cairo` @@ -1916,12 +1916,12 @@ Get the Cairo model URL. --- - + ## class `WorkspaceClient` Client to interact with `workspaces` endpoint. - + ### method `__init__` @@ -1945,7 +1945,7 @@ __init__( --- - + ### method `create` @@ -1963,7 +1963,7 @@ Call the API to create a new workspace. If the workspace already exists it will --- - + ### method `delete` @@ -1980,7 +1980,7 @@ Call the API to delete the workspace. If the workspace does not exist it will re --- - + ### method `get` @@ -1998,7 +1998,7 @@ Make a call to the API to retrieve workspace information. Only one should exist. --- - + ### method `retrieve_api_key` @@ -2022,7 +2022,198 @@ Retrieve the API key from the `~/.giza/.api_key.json` file. --- - + + +### method `retrieve_token` + +```python +retrieve_token( + user: Optional[str] = None, + password: Optional[str] = None, + renew: bool = False +) โ†’ None +``` + +Get the JWT token. + +First, it will try to get it from GIZA_TOKEN. Second, from ~/.giza/.credentials.json. And finally it will try to retrieve it from the API login the user in. + + + +**Args:** + + - `user`: if provided it will be used to check against current credentials and if provided with `password` used to retrieve a new token. + - `password`: if provided with `user` it will be used to retrieve a new token. + - `renew`: for renewal of the JWT token by user login. + + + +**Raises:** + + - `Exception`: if token could not be retrieved in any way + + +--- + + + +## class `AgentsClient` +Client to interact with `agents` endpoint. + + + +### method `__init__` + +```python +__init__( + host: str, + token: Optional[str] = None, + api_key: Optional[str] = None, + api_version: str = 'v1', + verify: bool = True, + debug: Optional[bool] = False +) โ†’ None +``` + + + + + + + + +--- + + + +### method `create` + +```python +create(agent_create: AgentCreate) โ†’ Agent +``` + +Create a new agent. + + + +**Args:** + + - `agent_create`: Agent information to create + + + +**Returns:** + The recently created agent + +--- + + + +### method `delete` + +```python +delete(agent_id: int) โ†’ None +``` + +Delete an agent. + + + +**Args:** + + - `agent_id`: Agent identifier + +--- + + + +### method `get` + +```python +get(agent_id: int, params: Optional[Dict[str, Any]] = None) โ†’ Agent +``` + +Get an agent. + + + +**Args:** + + - `agent_id`: Agent identifier + + + +**Returns:** + The agent information + +--- + + + +### method `list` + +```python +list(params: Optional[Dict[str, str]] = None) โ†’ AgentList +``` + +List endpoints. + + + +**Returns:** + A list of endpoints created by the user + +--- + + + +### method `patch` + +```python +patch(agent_id: int, agent_update: AgentUpdate) โ†’ Agent +``` + +Update an agent. + + + +**Args:** + + - `agent_id`: Agent identifier + - `agent_update`: Agent information to update + + + +**Returns:** + The updated agent information + +--- + + + +### method `retrieve_api_key` + +```python +retrieve_api_key() โ†’ None +``` + +Retrieve the API key from the `~/.giza/.api_key.json` file. + + + +**Raises:** + + - `Exception`: if the file does not exist + + + +**Returns:** + + - `str`: the API key + +--- + + ### method `retrieve_token` diff --git a/docs/reference/api/commands.actions.md b/docs/reference/api/commands.actions.md index 66f8adf..9652986 100644 --- a/docs/reference/api/commands.actions.md +++ b/docs/reference/api/commands.actions.md @@ -15,7 +15,7 @@ ## function `new` ```python -new(project_name: str = ) +new(project_name: str = ) ``` This command will create a new action by generating a Python project. diff --git a/docs/reference/api/commands.agents.md b/docs/reference/api/commands.agents.md new file mode 100644 index 0000000..a36fbcb --- /dev/null +++ b/docs/reference/api/commands.agents.md @@ -0,0 +1,152 @@ + + + + +# module `commands.agents` + + + + +**Global Variables** +--------------- +- **API_HOST** + +--- + + + +## function `create` + +```python +create( + model_id: int = typer.Option( + None, + "--model-id", + "-m", + help="The ID of the model used to create the agent", + ), + version_id: int = typer.Option( + None, + "--version-id", + "-v", + help="The ID of the version used to create the agent", + ), + endpoint_id: int = typer.Option( + None, + "--endpoint-id", + "-e", + help="The ID of the endpoint used to create the agent", + ), + name: Optional[str] = typer.Option( + None, "--name", "-n", help="The name of the agent" + ), + description: Optional[str] = typer.Option( + None, "--description", "-d", help="The description of the agent" + ), + debug: Optional[bool] = DEBUG_OPTION, +) โ†’ None +``` + + + + + + +--- + + + +## function `list` + +```python +list( + parameters: Optional[List[str]] = typer.Option( + None, "--parameters", "-p", help="The parameters of the agent" + ), + debug: Optional[bool] = DEBUG_OPTION, +) โ†’ None +``` + + + + + + +--- + + + +## function `get` + +```python +get( + agent_id: int = typer.Option( + None, + "--agent-id", + "-a", + help="The ID of the agent", + ), + debug: Optional[bool] = DEBUG_OPTION, +) โ†’ None +``` + + + + + + +--- + + + +## function `delete_agent` + +```python +delete_agent( + agent_id: int = typer.Option( + None, + "--agent-id", + "-a", + help="The ID of the agent", + ), + debug: Optional[bool] = DEBUG_OPTION, +) โ†’ None +``` + + + + + + +--- + + + +## function `update` + +```python +update( + agent_id: int = typer.Option( + None, + "--agent-id", + "-a", + help="The ID of the agent", + ), + name: Optional[str] = typer.Option( + None, "--name", "-n", help="The name of the agent" + ), + description: Optional[str] = typer.Option( + None, "--description", "-d", help="The description of the agent" + ), + parameters: Optional[List[str]] = typer.Option( + None, "--parameters", "-p", help="The parameters of the agent" + ), + debug: Optional[bool] = DEBUG_OPTION, +) โ†’ None +``` + + + + + + diff --git a/docs/reference/api/commands.endpoints.md b/docs/reference/api/commands.endpoints.md index b2dc23e..18e4d14 100644 --- a/docs/reference/api/commands.endpoints.md +++ b/docs/reference/api/commands.endpoints.md @@ -141,7 +141,7 @@ list_proofs( --- - + ## function `get_proof` @@ -169,7 +169,7 @@ get_proof( --- - + ## function `download_proof` @@ -203,7 +203,7 @@ download_proof( --- - + ## function `list_jobs` diff --git a/docs/reference/api/commands.users.md b/docs/reference/api/commands.users.md index 73d2be1..2dd8013 100644 --- a/docs/reference/api/commands.users.md +++ b/docs/reference/api/commands.users.md @@ -13,7 +13,7 @@ --- - + ## function `create` @@ -41,7 +41,7 @@ Command to create a user. Asks for the new users information and validates the i --- - + ## function `login` @@ -70,7 +70,7 @@ Logs the current user into Giza. Under the hood this will retrieve the token for --- - + ## function `create_api_key` @@ -98,7 +98,7 @@ Create an API key for your user. You need to be logged in to create an API key. --- - + ## function `me` @@ -119,7 +119,7 @@ Retrieve information about the current user and print it as json to stdout. --- - + ## function `resend_email` diff --git a/docs/reference/api/utils.misc.md b/docs/reference/api/utils.misc.md index 587a341..d1549a6 100644 --- a/docs/reference/api/utils.misc.md +++ b/docs/reference/api/utils.misc.md @@ -10,7 +10,7 @@ --- - + ## function `download_model_or_sierra` @@ -35,7 +35,7 @@ Download the model or sierra file. --- - + ## function `zip_folder` @@ -61,7 +61,7 @@ Zip the folder to a specific location. --- - + ## function `scarb_build` @@ -78,3 +78,72 @@ Build the scarb model. - `folder` (str): path to the folder +--- + + + +## function `get_ape_accounts` + +```python +get_ape_accounts() โ†’ Dict[str, Path] +``` + +Get the available APE accounts. + + + +**Returns:** + + - `list`: list of available APE accounts + + +--- + + + +## function `get_parameters_from_str` + +```python +get_parameters_from_str(parameters: List[str]) โ†’ Dict[str, str] +``` + +Get the parameters from a string. + + + +**Args:** + + - `parameters` (List[str]): parameters + + + +**Returns:** + + - `Dict[str, str]`: parameters + + +--- + + + +## function `load_json_file` + +```python +load_json_file(file_path: str) โ†’ Dict +``` + +Load a json file. + + + +**Args:** + + - `file_path` (str): path to the file + + + +**Returns:** + + - `Dict`: json content + + diff --git a/docs/resources/agents.md b/docs/resources/agents.md new file mode 100644 index 0000000..dba0cce --- /dev/null +++ b/docs/resources/agents.md @@ -0,0 +1,159 @@ +# Agents + +Agents are entities designed to assist users in interacting with Smart Contracts by managing the proof verification of verifiable ML models and executing these contracts using Ape's framework. + +Agents serve as intermediaries between users and Smart Contracts, facilitating seamless interaction with verifiable ML models and executing associated contracts. They handle the verification of proofs, ensuring the integrity and authenticity of data used in contract execution. + +## Creating an agent + +To create an agent, first you need to have an endpoint already deployed and an [ape account](https://docs.apeworx.io/ape/stable/userguides/accounts.html) created locally. If you have not yet deployed an endpoint, please refer to the [endpoints](./endpoints.md) documentation. To create the ape account, you can use the `ape accounts generate` command: + +```console +$ ape accounts generate +Enhance the security of your account by adding additional random input: +Show mnemonic? [Y/n]: n +Create Passphrase to encrypt account: +Repeat for confirmation: +SUCCESS: A new account '0x766867bB2E3E1A6E6245F4930b47E9aF54cEba0C' with HDPath m/44'/60'/0'/0/0 has been added with the id '' +``` + +{% hint style="danger" %} +The passphrase must be kept secret and secure, as it is used to encrypt the account and is required to access it. The account name is used to identify the account and along with the passphrase to perform transactions in the smart contracts. +{% endhint %} + +To create an agent, users can employ the `create` command. This command facilitates the creation of an agent, allowing users to interact with deployed endpoints and execute associated contracts. + +During the creation you will be asked to select an account to create the agent. The account is used to sign the transactions in the smart contracts. + +```console +> giza agents create --model-id --version-id --name --description + +[giza][2024-04-10 11:50:24.005] Creating agent โœ… +[giza][2024-04-10 11:50:24.006] Using endpoint id to create agent, retrieving model id and version id +[giza][2024-04-10 11:50:53.480] Select an existing account to create the agent. +[giza][2024-04-10 11:50:53.480] Available accounts are: +โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“ +โ”ƒ Accounts โ”ƒ +โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ +โ”‚ my_account โ”‚ +โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ +Enter the account name: my_account +{ + "id": 1, + "name": , + "description": , + "parameters": { + "model_id": , + "version_id": , + "endpoint_id": , + "alias": "my_account" + }, + "created_date": "2024-04-10T09:51:04.226448", + "last_update": "2024-04-10T09:51:04.226448" +} +``` + +An Agent can also be created using the `--endpoint-id` flag, which allows users to specify the endpoint ID directly. + +```console +> giza agents create --endpoint-id --name --description +``` + +## Listing agents + +The list command is designed to retrieve information about all existing agents and the parameters of them. + +```console +> giza agents list +[giza][2024-04-10 12:30:05.038] Listing agents โœ… +[ + { + "id": 1, + "name": "Agent one", + "description": "Agent to handle liquidity pools", + "parameters": { + "model_id": 1, + "version_id": 1, + "endpoint_id": 1, + "account": "awesome_account", + }, + "created_date": "2024-04-09T15:07:14.282177", + "last_update": "2024-04-10T10:06:36.928941" + }, + { + "id": 2, + "name": "Agent two", + "description": "Agent to handle volatility", + "parameters": { + "model_id": 1, + "version_id": 2, + "endpoint_id": 2, + "account": "another_awesome_account" + }, + "created_date": "2024-04-10T09:51:04.226448", + "last_update": "2024-04-10T10:12:18.975737" + } +] +``` + +## Retrieving an Agent + +For retrieving detailed information about a specific agent, users can utilize the `get` command. This command allows users view the details of a specific agent: + +```console +> giza agents get --agent-id 1 +{ + "id": 1, + "name": "Agent one", + "description": "Agent to handle liquidity pools", + "parameters": { + "model_id": 1, + "version_id": 1, + "endpoint_id": 1, + "account": "awesome_account", + }, + "created_date": "2024-04-09T15:07:14.282177", + "last_update": "2024-04-10T10:06:36.928941" +} +``` + +## Updating an Agent + +To update an agent, users can use the `update` command. This command facilitates the modification of an agent, allowing users to update the agent's name, description, and parameters. + +```console +> giza agents update --agent-id 1 --name "Agent one updated" --description "Agent to handle liquidity pools updated" --parameters chain=ethereum:mainnet:geth + +{ + "id": 1, + "name": "Agent one updated", + "description": "Agent to handle liquidity pools updated", + "parameters": { + "model_id": 1, + "version_id": 1, + "endpoint_id": 1, + "chain": "ethereum:mainnet:geth", + "account": "awesome_account", + }, + "created_date": "2024-04-10T09:51:04.226448", + "last_update": "2024-04-10T10:37:28.285500" +} +``` + +The parameters can be updated using the `--parameters` flag, which allows users to specify the parameters to be updated. + +```console +> giza agents update --agent-id 1 --parameters chain=ethereum:mainnet:geth --parameters account=awesome_account +``` + +The --parameters flag can be used multiple times to update multiple parameters and expects a key-value pair separated by an equal sign, `parameter_key=parameter_value`. + +## Delete an Agent + +For deleting an Agent, users can use the `delete` command. This command will erase any related data to the agent. + +```console +> giza agents delete --agent-id 1 +[giza][2024-04-10 12:40:33.959] Deleting agent 1 โœ… +[giza][2024-04-10 12:40:34.078] Agent 1 deleted โœ… +``` From 8eee2d63c761274bdf3019fa042be2f5cfdca979 Mon Sep 17 00:00:00 2001 From: Gonzalo Mellizo-Soto Date: Wed, 10 Apr 2024 16:18:56 +0200 Subject: [PATCH 7/9] Add more information --- docs/resources/agents.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/resources/agents.md b/docs/resources/agents.md index dba0cce..b752684 100644 --- a/docs/resources/agents.md +++ b/docs/resources/agents.md @@ -157,3 +157,7 @@ For deleting an Agent, users can use the `delete` command. This command will era [giza][2024-04-10 12:40:33.959] Deleting agent 1 โœ… [giza][2024-04-10 12:40:34.078] Agent 1 deleted โœ… ``` + +## More Information + +For more information about agents, and their usage in AI Actions, please refer to the [Agents](add_final_page) documentation. From 81386649a11ce865f0ea2098918d704f655fa4c0 Mon Sep 17 00:00:00 2001 From: Gonzalo Mellizo-Soto Date: Wed, 10 Apr 2024 16:19:59 +0200 Subject: [PATCH 8/9] Ignore .build/ folder --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 1115bec..dfc6368 100644 --- a/.gitignore +++ b/.gitignore @@ -134,3 +134,5 @@ smart_contracts/ .ruff_cache/ cairo_model/ + +.build/ From 203c689ab4f40f9268a7941446d46ac317c6961b Mon Sep 17 00:00:00 2001 From: Gonzalo Mellizo-Soto Date: Mon, 15 Apr 2024 21:58:46 +0200 Subject: [PATCH 9/9] Update metadata for account --- giza/commands/agents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/giza/commands/agents.py b/giza/commands/agents.py index bea4e08..0cfdc58 100644 --- a/giza/commands/agents.py +++ b/giza/commands/agents.py @@ -106,7 +106,7 @@ def create( "model_id": model_id, "version_id": version_id, "endpoint_id": endpoint_id, - "alias": selected_account, + "account": selected_account, "account_data": keyfile, }, )