Skip to content

Commit

Permalink
feat(client): add status/result
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop committed Oct 7, 2024
1 parent fd07469 commit 86f3b9a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
20 changes: 20 additions & 0 deletions projects/fal_client/src/fal_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,16 @@ async def submit(
def get_handle(self, application: str, request_id: str) -> AsyncRequestHandle:
return AsyncRequestHandle.from_request_id(self._client, application, request_id)

async def status(
self, application: str, request_id: str, *, with_logs: bool = False
) -> Status:
handle = self.get_handle(application, request_id)
return await handle.status(with_logs=with_logs)

async def result(self, application: str, request_id: str) -> AnyJSON:
handle = self.get_handle(application, request_id)
return await handle.get()

async def stream(
self,
application: str,
Expand Down Expand Up @@ -497,6 +507,16 @@ def submit(
def get_handle(self, application: str, request_id: str) -> SyncRequestHandle:
return SyncRequestHandle.from_request_id(self._client, application, request_id)

def status(
self, application: str, request_id: str, *, with_logs: bool = False
) -> Status:
handle = self.get_handle(application, request_id)
return handle.status(with_logs=with_logs)

def result(self, application: str, request_id: str) -> AnyJSON:
handle = self.get_handle(application, request_id)
return handle.get()

def stream(
self,
application: str,
Expand Down
13 changes: 13 additions & 0 deletions projects/fal_client/tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ async def test_fal_client(client: fal_client.AsyncClient):
result = await handle.get()
assert result["seed"] == 42

assert (
await client.result("fal-ai/fast-sdxl/image-to-image", handle.request_id)
== result
)

status = await handle.status(with_logs=False)
assert isinstance(status, fal_client.Completed)
assert status.logs is None
Expand All @@ -42,6 +47,14 @@ async def test_fal_client(client: fal_client.AsyncClient):
assert isinstance(status_w_logs, fal_client.Completed)
assert status_w_logs.logs is not None

assert (
await client.status(
"fal-ai/fast-sdxl/image-to-image",
handle.request_id,
)
== status
)

output = await client.run(
"fal-ai/fast-sdxl",
arguments={
Expand Down
4 changes: 4 additions & 0 deletions projects/fal_client/tests/test_sync_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def test_fal_client(client: fal_client.SyncClient):
result = handle.get()
assert result["seed"] == 42

assert client.result("fal-ai/fast-sdxl/image-to-image", handle.request_id) == result

status = handle.status(with_logs=False)
assert isinstance(status, fal_client.Completed)
assert status.logs is None
Expand All @@ -42,6 +44,8 @@ def test_fal_client(client: fal_client.SyncClient):
new_handle = client.get_handle("fal-ai/fast-sdxl/image-to-image", handle.request_id)
assert new_handle == handle

assert client.status("fal-ai/fast-sdxl/image-to-image", handle.request_id) == status

output = client.run(
"fal-ai/fast-sdxl",
arguments={
Expand Down

0 comments on commit 86f3b9a

Please sign in to comment.