From 1770885b49cc90df6ac1d7dfb139b488910b0d13 Mon Sep 17 00:00:00 2001 From: Alexis Deprez Date: Tue, 1 Oct 2024 12:06:55 +0200 Subject: [PATCH] style: rename API client to LaVague --- .../lavague/drivers/cloud/base.py | 4 ++-- lavague-sdk/lavague/sdk/agent.py | 12 ++++++------ lavague-sdk/lavague/sdk/client.py | 10 +++++----- lavague-sdk/lavague/sdk/trajectory/base.py | 2 +- lavague-sdk/lavague/sdk/trajectory/controller.py | 2 +- lavague-sdk/lavague/sdk/trajectory/mock.py | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lavague-integrations/drivers/lavague-drivers-cloud/lavague/drivers/cloud/base.py b/lavague-integrations/drivers/lavague-drivers-cloud/lavague/drivers/cloud/base.py index 60b9b0fd..d12f8cd2 100644 --- a/lavague-integrations/drivers/lavague-drivers-cloud/lavague/drivers/cloud/base.py +++ b/lavague-integrations/drivers/lavague-drivers-cloud/lavague/drivers/cloud/base.py @@ -1,4 +1,4 @@ -from lavague.sdk.client import LaVagueClient +from lavague.sdk.client import LaVague from lavague.sdk.base_driver import BaseDriver @@ -7,5 +7,5 @@ class CloudDriver(BaseDriver): Cloud driver class, used to interact with the cloud. """ - def __init__(self, client: LaVagueClient): + def __init__(self, client: LaVague): self.client = client diff --git a/lavague-sdk/lavague/sdk/agent.py b/lavague-sdk/lavague/sdk/agent.py index 88045416..5201d146 100644 --- a/lavague-sdk/lavague/sdk/agent.py +++ b/lavague-sdk/lavague/sdk/agent.py @@ -1,6 +1,6 @@ from typing import Optional from lavague.sdk.trajectory import Trajectory -from lavague.sdk.client import LaVagueClient +from lavague.sdk.client import LaVague from lavague.sdk.utilities.config import get_config @@ -9,24 +9,24 @@ class WebAgent: Web agent class, used to interact with the web. """ - client: LaVagueClient + client: LaVague def __init__( self, api_key: Optional[str] = None, - client: Optional[LaVagueClient] = None, + client: Optional[LaVague] = None, ): if client is None: if api_key is None: api_key = get_config("LAVAGUE_API_KEY") - client = LaVagueClient(api_key=api_key) + client = LaVague(api_key=api_key) self.client = client def run(self, url: str, objective: str, async_run=False) -> Trajectory: - trajectory = self.client.create_run(url, objective, step_by_step=True) + trajectory = self.client.run(url, objective, step_by_step=True) if not async_run: trajectory.run_to_completion() return trajectory def load(self, run_id: str) -> Trajectory: - return self.client.load_run(run_id) + return self.client.load(run_id) diff --git a/lavague-sdk/lavague/sdk/client.py b/lavague-sdk/lavague/sdk/client.py index 094fac73..64688abe 100644 --- a/lavague-sdk/lavague/sdk/client.py +++ b/lavague-sdk/lavague/sdk/client.py @@ -9,7 +9,7 @@ import requests -class LaVagueClient(TrajectoryController): +class LaVague(TrajectoryController): """Client to interact with the LaVague API.""" def __init__( @@ -44,7 +44,7 @@ def request_api( raise ApiException(response.text) return response.content - def create_run(self, url: str, objective: str, step_by_step=False) -> Trajectory: + def run(self, url: str, objective: str, step_by_step=False) -> Trajectory: content = self.request_api( "/runs", "POST", @@ -52,7 +52,7 @@ def create_run(self, url: str, objective: str, step_by_step=False) -> Trajectory ) return Trajectory.from_data(content, self.parser, self) - def load_run(self, run_id: str) -> Trajectory: + def load(self, run_id: str) -> Trajectory: content = self.request_api(f"/runs/{run_id}", "GET") return Trajectory.from_data(content, self.parser, self) @@ -63,7 +63,7 @@ def next_step(self, run_id: str) -> StepCompletion: ) return StepCompletion.model_validate_json(content) - def stop_run(self, run_id: str) -> None: + def stop(self, run_id: str) -> None: self.request_api( f"/runs/{run_id}/stop", "POST", @@ -77,7 +77,7 @@ def get_postaction_screenshot(self, step_id: str) -> ImageFile.ImageFile: content = self.request_api(f"/steps/{step_id}/screenshot/preaction", "GET") return Image.open(BytesIO(content)) - def get_run_screenshot(self, run_id: str) -> ImageFile.ImageFile: + def get_screenshot(self, run_id: str) -> ImageFile.ImageFile: content = self.request_api(f"/runs/{run_id}/screenshot", "GET") return Image.open(BytesIO(content)) diff --git a/lavague-sdk/lavague/sdk/trajectory/base.py b/lavague-sdk/lavague/sdk/trajectory/base.py index 54292ae6..c68285fb 100644 --- a/lavague-sdk/lavague/sdk/trajectory/base.py +++ b/lavague-sdk/lavague/sdk/trajectory/base.py @@ -31,7 +31,7 @@ def run_to_completion(self): return self.status def stop_run(self): - self._controller.stop_run(self.run_id) + self._controller.stop(self.run_id) self.status = RunStatus.CANCELLED def iter_actions(self) -> Iterator[Action]: diff --git a/lavague-sdk/lavague/sdk/trajectory/controller.py b/lavague-sdk/lavague/sdk/trajectory/controller.py index b18cb1e7..24735a58 100644 --- a/lavague-sdk/lavague/sdk/trajectory/controller.py +++ b/lavague-sdk/lavague/sdk/trajectory/controller.py @@ -8,5 +8,5 @@ def next_step(self, run_id: str) -> StepCompletion: pass @abstractmethod - def stop_run(self, run_id: str) -> None: + def stop(self, run_id: str) -> None: pass diff --git a/lavague-sdk/lavague/sdk/trajectory/mock.py b/lavague-sdk/lavague/sdk/trajectory/mock.py index 0d7ff531..75b50ce0 100644 --- a/lavague-sdk/lavague/sdk/trajectory/mock.py +++ b/lavague-sdk/lavague/sdk/trajectory/mock.py @@ -28,7 +28,7 @@ def get_completion_status(self) -> RunStatus: else RunStatus.FAILED ) - def stop_run(self, run_id: str): + def stop(self, run_id: str): pass @classmethod