diff --git a/ai21/clients/studio/resources/maestro/run.py b/ai21/clients/studio/resources/maestro/run.py index c8b7f690..7cc26903 100644 --- a/ai21/clients/studio/resources/maestro/run.py +++ b/ai21/clients/studio/resources/maestro/run.py @@ -63,7 +63,7 @@ def poll_for_status(self, *, run_id: str, poll_interval_sec: float, poll_timeout return run if (time.time() - start_time) >= poll_timeout_sec: - return run + raise TimeoutError(f"Timeout of {poll_timeout_sec} while polling for status of run with id {run_id}") time.sleep(poll_interval_sec) @@ -139,7 +139,7 @@ async def poll_for_status(self, *, run_id: str, poll_interval_sec: float, poll_t return run if (time.time() - start_time) >= poll_timeout_sec: - return run + raise TimeoutError(f"Timeout of {poll_timeout_sec} while polling for status of run with id {run_id}") await asyncio.sleep(poll_interval_sec) diff --git a/examples/studio/maestro/async_run.py b/examples/studio/maestro/async_run.py index f96f220a..b3b634c7 100644 --- a/examples/studio/maestro/async_run.py +++ b/examples/studio/maestro/async_run.py @@ -6,22 +6,25 @@ async def main(): - run_result = await client.beta.maestro.runs.create_and_poll( - input="Write a poem about the ocean", - requirements=[ - { - "name": "length requirement", - "description": "The length of the poem should be less than 1000 characters", - }, - { - "name": "rhyme requirement", - "description": "The poem should rhyme", - }, - ], - include=["requirements_result"], - ) + try: + run_result = await client.beta.maestro.runs.create_and_poll( + input="Write a poem about the ocean", + requirements=[ + { + "name": "length requirement", + "description": "The length of the poem should be less than 1000 characters", + }, + { + "name": "rhyme requirement", + "description": "The poem should rhyme", + }, + ], + include=["requirements_result"], + ) - print(run_result) + print(run_result) + except TimeoutError: + print("The run timed out") if __name__ == "__main__": diff --git a/examples/studio/maestro/run.py b/examples/studio/maestro/run.py index 7d6fa5b5..b32258e4 100644 --- a/examples/studio/maestro/run.py +++ b/examples/studio/maestro/run.py @@ -4,22 +4,25 @@ def main(): - run_result = client.beta.maestro.runs.create_and_poll( - input="Write a poem about the ocean", - requirements=[ - { - "name": "length requirement", - "description": "The length of the poem should be less than 1000 characters", - }, - { - "name": "rhyme requirement", - "description": "The poem should rhyme", - }, - ], - include=["requirements_result"], - ) + try: + run_result = client.beta.maestro.runs.create_and_poll( + input="Write a poem about the ocean", + requirements=[ + { + "name": "length requirement", + "description": "The length of the poem should be less than 1000 characters", + }, + { + "name": "rhyme requirement", + "description": "The poem should rhyme", + }, + ], + include=["requirements_result"], + ) - print(run_result) + print(run_result) + except TimeoutError: + print("The run timed out") if __name__ == "__main__":