Skip to content

Commit

Permalink
style: rename API client to LaVague
Browse files Browse the repository at this point in the history
  • Loading branch information
adeprez committed Oct 1, 2024
1 parent 8b82d76 commit 1770885
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from lavague.sdk.client import LaVagueClient
from lavague.sdk.client import LaVague
from lavague.sdk.base_driver import BaseDriver


Expand All @@ -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
12 changes: 6 additions & 6 deletions lavague-sdk/lavague/sdk/agent.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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)
10 changes: 5 additions & 5 deletions lavague-sdk/lavague/sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import requests


class LaVagueClient(TrajectoryController):
class LaVague(TrajectoryController):
"""Client to interact with the LaVague API."""

def __init__(
Expand Down Expand Up @@ -44,15 +44,15 @@ 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",
{"url": url, "objective": objective, "step_by_step": step_by_step},
)
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)

Expand All @@ -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",
Expand All @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion lavague-sdk/lavague/sdk/trajectory/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
2 changes: 1 addition & 1 deletion lavague-sdk/lavague/sdk/trajectory/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lavague-sdk/lavague/sdk/trajectory/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1770885

Please sign in to comment.