From 18d92722631b70c7e1f509a5b5b7885eafe1a465 Mon Sep 17 00:00:00 2001 From: Gonzalo Mellizo-Soto Date: Mon, 22 Apr 2024 17:32:07 +0200 Subject: [PATCH 1/2] Update verification so its done through api instead of jobs --- giza_actions/agent.py | 36 ++++++++++---------------------- poetry.lock | 8 ++++---- tests/test_agent.py | 48 +++++++++++++------------------------------ 3 files changed, 29 insertions(+), 63 deletions(-) diff --git a/giza_actions/agent.py b/giza_actions/agent.py index 669498a..c08e36b 100644 --- a/giza_actions/agent.py +++ b/giza_actions/agent.py @@ -13,9 +13,9 @@ from giza import API_HOST from giza.client import AgentsClient, EndpointsClient, JobsClient, ProofsClient from giza.schemas.agents import Agent, AgentList, AgentUpdate -from giza.schemas.jobs import Job, JobCreate, JobList +from giza.schemas.jobs import Job, JobList from giza.schemas.proofs import Proof -from giza.utils.enums import JobKind, JobSize, JobStatus +from giza.utils.enums import JobKind, JobStatus from requests import HTTPError from giza_actions.model import GizaModel @@ -363,9 +363,7 @@ def _verify(self): return self._wait_for_proof(self._jobs_client, self._timeout, self._poll_interval) - self._verify_job = self._start_verify_job(self._jobs_client) - self._wait_for_verify(self._jobs_client, self._timeout, self._poll_interval) - self.verified = True + self.verified = self._verify_proof(self._endpoint_client) def _wait_for_proof( self, client: JobsClient, timeout: int = 600, poll_interval: int = 10 @@ -378,29 +376,17 @@ def _wait_for_proof( self._endpoint_id, self._proof_job.request_id ) - def _start_verify_job(self, client: JobsClient) -> Job: + def _verify_proof(self, client: EndpointsClient) -> bool: """ - Start the verify job. + Verify the proof. """ - job_create = JobCreate( - size=JobSize.S, - framework=self._framework, - model_id=self._model_id, - version_id=self._version_id, - proof_id=self._proof.id, - kind=JobKind.VERIFY, + verify_result = client.verify_proof( + self._endpoint_id, + self._proof.id, ) - verify_job = client.create(job_create, trace=None) - logger.info(f"Verify job created with ID {verify_job.id}") - return verify_job - - def _wait_for_verify( - self, client: JobsClient, timeout: int = 600, poll_interval: int = 10 - ): - """ - Wait for the verify job to finish. - """ - self._wait_for(self._verify_job, client, timeout, poll_interval, JobKind.VERIFY) + logger.info(f"Verify result is {verify_result.verification}") + logger.info(f"Verify time is {verify_result.verification_time}") + return True def _wait_for( self, diff --git a/poetry.lock b/poetry.lock index 9bfa9a7..54d12e5 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2039,13 +2039,13 @@ tqdm = ["tqdm"] [[package]] name = "giza-cli" -version = "0.15.0" +version = "0.15.1" description = "CLI for interacting with Giza" optional = false python-versions = "<4.0,>=3.11" files = [ - {file = "giza_cli-0.15.0-py3-none-any.whl", hash = "sha256:c4c1194208212e8507684184cb220fa177986f093ae16bc899cd38343aa4ee14"}, - {file = "giza_cli-0.15.0.tar.gz", hash = "sha256:74c90cd6304e2d0cfd498b12459cf05a8a146a08800d368a35b8e48dad4b0aeb"}, + {file = "giza_cli-0.15.1-py3-none-any.whl", hash = "sha256:0704eaf90ec6310358bc7aa0985a7b01684f9c814e0a957c01895e1181918db6"}, + {file = "giza_cli-0.15.1.tar.gz", hash = "sha256:7914a5b04bd1c635f0bec3301cc79ca691aa3236c5ba368be8b9dcb7613f7183"}, ] [package.dependencies] @@ -3994,8 +3994,8 @@ files = [ [package.dependencies] numpy = [ - {version = ">=1.23.5", markers = "python_version >= \"3.11\" and python_version < \"3.12\""}, {version = ">=1.26.0", markers = "python_version >= \"3.12\""}, + {version = ">=1.23.5", markers = "python_version >= \"3.11\" and python_version < \"3.12\""}, ] [[package]] diff --git a/tests/test_agent.py b/tests/test_agent.py index b1a0033..7fcfa07 100644 --- a/tests/test_agent.py +++ b/tests/test_agent.py @@ -4,6 +4,7 @@ from ape.exceptions import NetworkError from giza.schemas.jobs import Job, JobList from giza.schemas.proofs import Proof +from giza.schemas.verify import VerifyResponse from giza_actions.agent import AgentResult, ContractHandler, GizaAgent @@ -21,6 +22,12 @@ def get_proof(self, *args, **kwargs): id=1, job_id=1, created_date="2022-01-01T00:00:00Z", request_id="123" ) + def verify_proof(self, *args, **kwargs): + return VerifyResponse( + verification=True, + verification_time=1, + ) + class JobsClientStub: def __init__(self, *args, **kwargs): @@ -235,11 +242,8 @@ def test_agentresult__get_proof_job(): @patch("giza_actions.agent.AgentResult._wait_for_proof") -@patch("giza_actions.agent.AgentResult._start_verify_job") -@patch("giza_actions.agent.AgentResult._wait_for_verify") -def test_agentresult__verify( - mock_wait_for_verify, mock_start_verify_job, mock_wait_for_proof -): +@patch("giza_actions.agent.AgentResult._verify_proof", return_value=True) +def test_agentresult__verify(mock_verify, mock_wait_for_proof): result = AgentResult( input=[], result=[1], @@ -252,8 +256,7 @@ def test_agentresult__verify( assert result.verified is True mock_wait_for_proof.assert_called_once() - mock_start_verify_job.assert_called_once() - mock_wait_for_verify.assert_called_once() + mock_verify.assert_called_once() @patch("giza_actions.agent.AgentResult._wait_for") @@ -273,43 +276,20 @@ def test_agentresult__wait_for_proof(mock_wait_for): mock_wait_for.assert_called_once() -def test_agentresult__start_verify_job(): - agent = Mock() - agent.framework = "CAIRO" - agent.model_id = 1 - agent.version_id = 1 - +def test_agentresult__verify_proof(): result = AgentResult( input=[], result=[1], request_id="123", - agent=agent, + agent=Mock(), endpoint_client=EndpointsClientStub(), ) - + # Add a dummy proof to the result so we can verify it result._proof = Proof( id=1, job_id=1, created_date="2022-01-01T00:00:00Z", request_id="123" ) - job = result._start_verify_job(JobsClientStub()) - - assert job.id == 1 - assert job.size == "S" - assert job.status == "COMPLETED" - - -@patch("giza_actions.agent.AgentResult._wait_for") -def test_agentresult__wait_for_verify(mock_wait_for): - result = AgentResult( - input=[], - result=[1], - request_id="123", - agent=Mock(), - endpoint_client=EndpointsClientStub(), - ) - - result._wait_for_verify(JobsClientStub()) - mock_wait_for.assert_called_once() + assert result._verify_proof(EndpointsClientStub()) def test_agentresult__wait_for_job_completed(): From 3abacc7458f19e0ee8f221ed432b409e1eb15139 Mon Sep 17 00:00:00 2001 From: Gonzalo Mellizo-Soto Date: Mon, 22 Apr 2024 17:32:36 +0200 Subject: [PATCH 2/2] Bumping version from 0.3.0 to 0.3.12 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index bd23655..4eaf040 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "giza-actions" -version = "0.3.0" +version = "0.3.1" description = "A Python SDK for Giza platform" authors = [