Skip to content

Commit

Permalink
Merge pull request #59 from gizatechxyz/feature/retrieve-job-and-endp…
Browse files Browse the repository at this point in the history
…oints-logs

Add log retrieval for jobs and endpoints
  • Loading branch information
Gonmeso authored May 22, 2024
2 parents 3499804 + fe5cebd commit 5759b68
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 185 deletions.
81 changes: 81 additions & 0 deletions giza/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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.logs import Logs
from giza.schemas.message import Msg
from giza.schemas.models import Model, ModelCreate, ModelList, ModelUpdate
from giza.schemas.proofs import Proof, ProofList
Expand Down Expand Up @@ -667,6 +668,37 @@ def get(self, endpoint_id: int) -> Endpoint:

return Endpoint(**response.json())

@auth
def get_logs(self, endpoint_id: int) -> Logs:
"""
Get the latest logs of an endpoint.
Args:
endpoint_id: Endpoint identifier
Returns:
Logs: The logs of the specified deployment
"""
headers = copy.deepcopy(self.default_headers)
headers.update(self._get_auth_header())

response = self.session.get(
"/".join(
[
self.url,
self.ENDPOINTS,
str(endpoint_id),
"logs",
]
),
headers=headers,
)

self._echo_debug(str(response))
response.raise_for_status()

return Logs(**response.json())

@auth
def delete(self, endpoint_id: int) -> None:
"""
Expand Down Expand Up @@ -958,6 +990,30 @@ def get(self, job_id: int, params: Optional[dict[str, str]] = None) -> Job:

return Job(**response.json())

@auth
def get_logs(self, job_id: int) -> Logs:
"""
Make a call to the API to retrieve job logs.
Args:
job_id: Job identfier to retrieve the logs for
Returns:
Logs: the logs of the specified job
"""
headers = copy.deepcopy(self.default_headers)
headers.update(self._get_auth_header())

response = self.session.get(
f"{self.url}/{self.JOBS_ENDPOINT}/{job_id}/logs",
headers=headers,
)
self._echo_debug(str(response))

response.raise_for_status()

return Logs(**response.json())

@auth
def create(
self,
Expand Down Expand Up @@ -1312,6 +1368,31 @@ def get(self, model_id: int, version_id: int) -> Version:

return Version(**response.json())

@auth
def get_logs(self, model_id: int, version_id: int) -> Logs:
"""
Get a version transpilation logs.
Args:
model_id: Model identifier
version_id: Version identifier
Returns:
The version transpilation logs
"""
headers = copy.deepcopy(self.default_headers)
headers.update(self._get_auth_header())

response = self.session.get(
f"{self._get_version_url(model_id)}/{version_id}/logs",
headers=headers,
)

self._echo_debug(str(response))
response.raise_for_status()

return Logs(**response.json())

@auth
def upload_cairo(self, model_id: int, version_id: int, file_path: str) -> Version:
"""
Expand Down
68 changes: 19 additions & 49 deletions giza/commands/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@

from giza import API_HOST
from giza.client import AgentsClient, EndpointsClient
from giza.options import DEBUG_OPTION
from giza.options import (
AGENT_OPTION,
DEBUG_OPTION,
DESCRIPTION_OPTION,
ENDPOINT_OPTION,
MODEL_OPTION,
NAME_OPTION,
VERSION_OPTION,
)
from giza.schemas.agents import AgentCreate, AgentList, AgentUpdate
from giza.utils import echo
from giza.utils.exception_handling import ExceptionHandler
Expand All @@ -27,30 +35,11 @@
""",
)
def create(
model_id: Optional[int] = typer.Option(
None,
"--model-id",
"-m",
help="The ID of the model used to create the agent",
),
version_id: Optional[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"
),
model_id: Optional[int] = MODEL_OPTION,
version_id: Optional[int] = VERSION_OPTION,
endpoint_id: int = ENDPOINT_OPTION,
name: Optional[str] = NAME_OPTION,
description: Optional[str] = DESCRIPTION_OPTION,
debug: Optional[bool] = DEBUG_OPTION,
) -> None:
echo("Creating agent ✅ ")
Expand Down Expand Up @@ -155,12 +144,7 @@ def list(
""",
)
def get(
agent_id: int = typer.Option(
None,
"--agent-id",
"-a",
help="The ID of the agent",
),
agent_id: int = AGENT_OPTION,
debug: Optional[bool] = DEBUG_OPTION,
) -> None:
echo(f"Getting agent {agent_id} ✅ ")
Expand All @@ -179,12 +163,7 @@ def get(
""",
)
def delete_agent(
agent_id: int = typer.Option(
None,
"--agent-id",
"-a",
help="The ID of the agent",
),
agent_id: int = AGENT_OPTION,
debug: Optional[bool] = DEBUG_OPTION,
) -> None:
echo(f"Deleting agent {agent_id} ✅ ")
Expand All @@ -207,18 +186,9 @@ def delete_agent(
""",
)
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"
),
agent_id: int = AGENT_OPTION,
name: Optional[str] = NAME_OPTION,
description: Optional[str] = DESCRIPTION_OPTION,
parameters: Optional[List[str]] = typer.Option(
None, "--parameters", "-p", help="The parameters of the agent"
),
Expand Down
Loading

0 comments on commit 5759b68

Please sign in to comment.