Skip to content

Commit 42e4d4b

Browse files
feat(api): Autogen spec updates
1 parent ca26ad1 commit 42e4d4b

21 files changed

+293
-431
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 15
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/runwayml%2Frunwayml-c2a88516fa0c20ca73f742f8d876f5e773747b4f6903508b1824c0939b313b82.yml
3-
openapi_spec_hash: 660d0eec8f3940727f541dd05121627b
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/runwayml%2Frunwayml-6dab1bdab5d3264fa80bccb641a17fbf0944197c00c08b826fbd17e29ba250a1.yml
3+
openapi_spec_hash: 846f29a2fd9ceb6867c2343494e1c319
44
config_hash: b98eed33f1bba05e3c2a3e20d85d582a

src/runwayml/lib/polling.py

Lines changed: 84 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import time
22
import random
3-
from typing import TYPE_CHECKING, Type, Union, TypeVar, cast
4-
from typing_extensions import ParamSpec
3+
from typing import TYPE_CHECKING, Type, Union, TypeVar, Callable, Annotated, Coroutine, cast
4+
from typing_extensions import ParamSpec, TypeAlias
55

66
import anyio
77

8+
from runwayml._utils import PropertyInfo
9+
810
from .._models import BaseModel
9-
from ..types.task_retrieve_response import TaskRetrieveResponse
11+
from ..types.task_retrieve_response import (
12+
Failed,
13+
Pending,
14+
Running,
15+
Cancelled,
16+
Succeeded,
17+
Throttled,
18+
TaskRetrieveResponse,
19+
)
1020

1121
if TYPE_CHECKING:
1222
from .._client import RunwayML, AsyncRunwayML
@@ -40,10 +50,6 @@ class NewTaskCreatedResponse(AwaitableTaskResponseMixin, BaseModel):
4050
id: str
4151

4252

43-
class AwaitableTaskRetrieveResponse(AwaitableTaskResponseMixin, TaskRetrieveResponse):
44-
pass
45-
46-
4753
class AsyncAwaitableTaskResponseMixin:
4854
async def wait_for_task_output(self, timeout: Union[float, None] = 60 * 10) -> TaskRetrieveResponse: # type: ignore[empty-body]
4955
"""
@@ -67,10 +73,6 @@ class AsyncNewTaskCreatedResponse(AsyncAwaitableTaskResponseMixin, BaseModel):
6773
id: str
6874

6975

70-
class AsyncAwaitableTaskRetrieveResponse(AsyncAwaitableTaskResponseMixin, TaskRetrieveResponse):
71-
pass
72-
73-
7476
def create_waitable_resource(base_class: Type[T], client: "RunwayML") -> Type[NewTaskCreatedResponse]:
7577
class WithClient(base_class): # type: ignore[valid-type,misc]
7678
id: str
@@ -125,3 +127,74 @@ class TaskTimeoutError(Exception):
125127
def __init__(self, task_details: TaskRetrieveResponse):
126128
self.task_details = task_details
127129
super().__init__(f"Task timed out")
130+
131+
132+
133+
class AwaitablePending(AwaitableTaskResponseMixin, Pending): ...
134+
class AwaitableThrottled(AwaitableTaskResponseMixin, Throttled): ...
135+
class AwaitableCancelled(AwaitableTaskResponseMixin, Cancelled): ...
136+
class AwaitableRunning(AwaitableTaskResponseMixin, Running): ...
137+
class AwaitableFailed(AwaitableTaskResponseMixin, Failed): ...
138+
class AwaitableSucceeded(AwaitableTaskResponseMixin, Succeeded): ...
139+
140+
AwaitableTaskRetrieveResponse: TypeAlias = Annotated[
141+
Union[AwaitablePending, AwaitableThrottled, AwaitableCancelled, AwaitableRunning, AwaitableFailed, AwaitableSucceeded],
142+
PropertyInfo(discriminator="status")
143+
]
144+
145+
class AsyncAwaitablePending(AsyncAwaitableTaskResponseMixin, Pending): ...
146+
class AsyncAwaitableThrottled(AsyncAwaitableTaskResponseMixin, Throttled): ...
147+
class AsyncAwaitableCancelled(AsyncAwaitableTaskResponseMixin, Cancelled): ...
148+
class AsyncAwaitableRunning(AsyncAwaitableTaskResponseMixin, Running): ...
149+
class AsyncAwaitableFailed(AsyncAwaitableTaskResponseMixin, Failed): ...
150+
class AsyncAwaitableSucceeded(AsyncAwaitableTaskResponseMixin, Succeeded): ...
151+
152+
AsyncAwaitableTaskRetrieveResponse: TypeAlias = Annotated[
153+
Union[AsyncAwaitablePending, AsyncAwaitableThrottled, AsyncAwaitableCancelled, AsyncAwaitableRunning, AsyncAwaitableFailed, AsyncAwaitableSucceeded],
154+
PropertyInfo(discriminator="status")
155+
]
156+
157+
def _make_sync_wait_for_task_output(client: "RunwayML") -> Callable[["AwaitableTaskResponseMixin", Union[float, None]], TaskRetrieveResponse]:
158+
"""Create a wait_for_task_output method bound to the given client."""
159+
def wait_for_task_output(self: "AwaitableTaskResponseMixin", timeout: Union[float, None] = 60 * 10) -> TaskRetrieveResponse:
160+
start_time = time.time()
161+
while True:
162+
time.sleep(POLL_TIME + random.random() * POLL_JITTER - POLL_JITTER / 2)
163+
task_details = client.tasks.retrieve(self.id) # type: ignore[attr-defined]
164+
if task_details.status == "SUCCEEDED":
165+
return task_details
166+
if task_details.status == "FAILED":
167+
raise TaskFailedError(task_details)
168+
if timeout is not None and time.time() - start_time > timeout:
169+
raise TaskTimeoutError(task_details)
170+
return wait_for_task_output
171+
172+
173+
def inject_sync_wait_method(client: "RunwayML", response: T) -> T:
174+
"""Inject the wait_for_task_output method onto the response instance."""
175+
import types
176+
response.wait_for_task_output = types.MethodType(_make_sync_wait_for_task_output(client), response) # type: ignore[attr-defined]
177+
return response
178+
179+
180+
def _make_async_wait_for_task_output(client: "AsyncRunwayML") -> Callable[["AsyncAwaitableTaskResponseMixin", Union[float, None]], Coroutine[None, None, TaskRetrieveResponse]]:
181+
"""Create an async wait_for_task_output method bound to the given client."""
182+
async def wait_for_task_output(self: "AsyncAwaitableTaskResponseMixin", timeout: Union[float, None] = 60 * 10) -> TaskRetrieveResponse:
183+
start_time = anyio.current_time()
184+
while True:
185+
await anyio.sleep(POLL_TIME + random.random() * POLL_JITTER - POLL_JITTER / 2)
186+
task_details = await client.tasks.retrieve(self.id) # type: ignore[attr-defined]
187+
if task_details.status == "SUCCEEDED":
188+
return task_details
189+
if task_details.status == "FAILED" or task_details.status == "CANCELLED":
190+
raise TaskFailedError(task_details)
191+
if timeout is not None and anyio.current_time() - start_time > timeout:
192+
raise TaskTimeoutError(task_details)
193+
return wait_for_task_output
194+
195+
196+
def inject_async_wait_method(client: "AsyncRunwayML", response: T) -> T:
197+
"""Inject the async wait_for_task_output method onto the response instance."""
198+
import types
199+
response.wait_for_task_output = types.MethodType(_make_async_wait_for_task_output(client), response) # type: ignore[attr-defined]
200+
return response

src/runwayml/resources/tasks.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import cast
5+
from typing import Any, cast
66

77
import httpx
88

@@ -18,11 +18,10 @@
1818
from ..lib.polling import (
1919
AwaitableTaskRetrieveResponse,
2020
AsyncAwaitableTaskRetrieveResponse,
21-
create_waitable_resource,
22-
create_async_waitable_resource,
21+
inject_sync_wait_method,
22+
inject_async_wait_method,
2323
)
2424
from .._base_client import make_request_options
25-
from ..types.task_retrieve_response import TaskRetrieveResponse
2625

2726
__all__ = ["TasksResource", "AsyncTasksResource"]
2827

@@ -74,15 +73,14 @@ def retrieve(
7473
"""
7574
if not id:
7675
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
77-
return self._get(
76+
response = self._get(
7877
f"/v1/tasks/{id}",
7978
options=make_request_options(
8079
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
8180
),
82-
cast_to=cast(
83-
type[AwaitableTaskRetrieveResponse], create_waitable_resource(TaskRetrieveResponse, self._client)
84-
),
81+
cast_to=cast(Any, AwaitableTaskRetrieveResponse), # Union types cannot be passed in as arguments in the type system
8582
)
83+
return cast(AwaitableTaskRetrieveResponse, inject_sync_wait_method(self._client, response))
8684

8785
def delete(
8886
self,
@@ -171,16 +169,14 @@ async def retrieve(
171169
"""
172170
if not id:
173171
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
174-
return await self._get(
172+
response = await self._get(
175173
f"/v1/tasks/{id}",
176174
options=make_request_options(
177175
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
178176
),
179-
cast_to=cast(
180-
type[AsyncAwaitableTaskRetrieveResponse],
181-
create_async_waitable_resource(TaskRetrieveResponse, self._client),
182-
),
177+
cast_to=cast(Any, AsyncAwaitableTaskRetrieveResponse), # Union types cannot be passed in as arguments in the type system
183178
)
179+
return cast(AsyncAwaitableTaskRetrieveResponse, inject_async_wait_method(self._client, response))
184180

185181
async def delete(
186182
self,
@@ -267,4 +263,4 @@ def __init__(self, tasks: AsyncTasksResource) -> None:
267263
)
268264
self.delete = async_to_streamed_response_wrapper(
269265
tasks.delete,
270-
)
266+
)

src/runwayml/resources/text_to_image.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,38 @@ def create(
246246
"720:960",
247247
"1680:720",
248248
]
249+
| Literal[
250+
"1344:768",
251+
"768:1344",
252+
"1024:1024",
253+
"1184:864",
254+
"864:1184",
255+
"1536:672",
256+
"832:1248",
257+
"1248:832",
258+
"896:1152",
259+
"1152:896",
260+
"2048:2048",
261+
"1696:2528",
262+
"2528:1696",
263+
"1792:2400",
264+
"2400:1792",
265+
"1856:2304",
266+
"2304:1856",
267+
"1536:2752",
268+
"2752:1536",
269+
"3168:1344",
270+
"4096:4096",
271+
"3392:5056",
272+
"5056:3392",
273+
"3584:4800",
274+
"4800:3584",
275+
"3712:4608",
276+
"4608:3712",
277+
"3072:5504",
278+
"5504:3072",
279+
"6336:2688",
280+
]
249281
| Literal[
250282
"1344:768",
251283
"768:1344",
@@ -509,6 +541,38 @@ async def create(
509541
"720:960",
510542
"1680:720",
511543
]
544+
| Literal[
545+
"1344:768",
546+
"768:1344",
547+
"1024:1024",
548+
"1184:864",
549+
"864:1184",
550+
"1536:672",
551+
"832:1248",
552+
"1248:832",
553+
"896:1152",
554+
"1152:896",
555+
"2048:2048",
556+
"1696:2528",
557+
"2528:1696",
558+
"1792:2400",
559+
"2400:1792",
560+
"1856:2304",
561+
"2304:1856",
562+
"1536:2752",
563+
"2752:1536",
564+
"3168:1344",
565+
"4096:4096",
566+
"3392:5056",
567+
"5056:3392",
568+
"3584:4800",
569+
"4800:3584",
570+
"3712:4608",
571+
"4608:3712",
572+
"3072:5504",
573+
"5504:3072",
574+
"6336:2688",
575+
]
512576
| Literal[
513577
"1344:768",
514578
"768:1344",

src/runwayml/types/character_performance_create_response.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77

88
class CharacterPerformanceCreateResponse(BaseModel):
99
id: str
10+
"""The ID of the task that was created. Use this to retrieve the task later."""

src/runwayml/types/image_to_video_create_response.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77

88
class ImageToVideoCreateResponse(BaseModel):
99
id: str
10+
"""The ID of the task that was created. Use this to retrieve the task later."""

0 commit comments

Comments
 (0)