Skip to content

Commit 6c1163d

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
feat(api): OpenAPI spec update via Stainless API (#135)
1 parent 7a89e81 commit 6c1163d

File tree

6 files changed

+306
-46
lines changed

6 files changed

+306
-46
lines changed

api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2652,7 +2652,7 @@ from cloudflare.types.workers import AIRunResponse
26522652

26532653
Methods:
26542654

2655-
- <code title="post /accounts/{account_id}/ai/run/{model_name}">client.workers.ai.<a href="./src/cloudflare/resources/workers/ai.py">run</a>(model_name, \*, account_id, \*\*<a href="src/cloudflare/types/workers/ai_run_params.py">params</a>) -> <a href="./src/cloudflare/types/workers/ai_run_response.py">object</a></code>
2655+
- <code title="post /accounts/{account_id}/ai/run/{model_name}">client.workers.ai.<a href="./src/cloudflare/resources/workers/ai.py">run</a>(model_name, \*, account_id, \*\*<a href="src/cloudflare/types/workers/ai_run_params.py">params</a>) -> <a href="./src/cloudflare/types/workers/ai_run_response.py">Optional</a></code>
26562656

26572657
## Scripts
26582658

src/cloudflare/resources/workers/ai.py

+36-26
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

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

77
import httpx
88

@@ -23,7 +23,7 @@
2323
from ..._base_client import (
2424
make_request_options,
2525
)
26-
from ...types.workers import ai_run_params
26+
from ...types.workers import AIRunResponse, ai_run_params
2727

2828
__all__ = ["AI", "AsyncAI"]
2929

@@ -42,14 +42,14 @@ def run(
4242
model_name: str,
4343
*,
4444
account_id: str,
45-
body: object,
45+
body: ai_run_params.Body,
4646
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
4747
# The extra values given here take precedence over values defined on the client or passed to this method.
4848
extra_headers: Headers | None = None,
4949
extra_query: Query | None = None,
5050
extra_body: Body | None = None,
5151
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
52-
) -> object:
52+
) -> Optional[AIRunResponse]:
5353
"""
5454
This endpoint provides users with the capability to run specific AI models
5555
on-demand.
@@ -74,17 +74,22 @@ def run(
7474
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
7575
if not model_name:
7676
raise ValueError(f"Expected a non-empty value for `model_name` but received {model_name!r}")
77-
return self._post(
78-
f"/accounts/{account_id}/ai/run/{model_name}",
79-
body=maybe_transform(body, ai_run_params.AIRunParams),
80-
options=make_request_options(
81-
extra_headers=extra_headers,
82-
extra_query=extra_query,
83-
extra_body=extra_body,
84-
timeout=timeout,
85-
post_parser=ResultWrapper._unwrapper,
77+
return cast(
78+
Optional[AIRunResponse],
79+
self._post(
80+
f"/accounts/{account_id}/ai/run/{model_name}",
81+
body=maybe_transform(body, ai_run_params.AIRunParams),
82+
options=make_request_options(
83+
extra_headers=extra_headers,
84+
extra_query=extra_query,
85+
extra_body=extra_body,
86+
timeout=timeout,
87+
post_parser=ResultWrapper._unwrapper,
88+
),
89+
cast_to=cast(
90+
Any, ResultWrapper[AIRunResponse]
91+
), # Union types cannot be passed in as arguments in the type system
8692
),
87-
cast_to=cast(Type[object], ResultWrapper[object]),
8893
)
8994

9095

@@ -102,14 +107,14 @@ async def run(
102107
model_name: str,
103108
*,
104109
account_id: str,
105-
body: object,
110+
body: ai_run_params.Body,
106111
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
107112
# The extra values given here take precedence over values defined on the client or passed to this method.
108113
extra_headers: Headers | None = None,
109114
extra_query: Query | None = None,
110115
extra_body: Body | None = None,
111116
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
112-
) -> object:
117+
) -> Optional[AIRunResponse]:
113118
"""
114119
This endpoint provides users with the capability to run specific AI models
115120
on-demand.
@@ -134,17 +139,22 @@ async def run(
134139
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
135140
if not model_name:
136141
raise ValueError(f"Expected a non-empty value for `model_name` but received {model_name!r}")
137-
return await self._post(
138-
f"/accounts/{account_id}/ai/run/{model_name}",
139-
body=await async_maybe_transform(body, ai_run_params.AIRunParams),
140-
options=make_request_options(
141-
extra_headers=extra_headers,
142-
extra_query=extra_query,
143-
extra_body=extra_body,
144-
timeout=timeout,
145-
post_parser=ResultWrapper._unwrapper,
142+
return cast(
143+
Optional[AIRunResponse],
144+
await self._post(
145+
f"/accounts/{account_id}/ai/run/{model_name}",
146+
body=await async_maybe_transform(body, ai_run_params.AIRunParams),
147+
options=make_request_options(
148+
extra_headers=extra_headers,
149+
extra_query=extra_query,
150+
extra_body=extra_body,
151+
timeout=timeout,
152+
post_parser=ResultWrapper._unwrapper,
153+
),
154+
cast_to=cast(
155+
Any, ResultWrapper[AIRunResponse]
156+
), # Union types cannot be passed in as arguments in the type system
146157
),
147-
cast_to=cast(Type[object], ResultWrapper[object]),
148158
)
149159

150160

src/cloudflare/types/workers/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .workers_domain import WorkersDomain as WorkersDomain
77
from .workers_routes import WorkersRoutes as WorkersRoutes
88
from .workers_script import WorkersScript as WorkersScript
9+
from .ai_run_response import AIRunResponse as AIRunResponse
910
from .workers_filters import WorkersFilters as WorkersFilters
1011
from .domain_list_params import DomainListParams as DomainListParams
1112
from .route_create_params import RouteCreateParams as RouteCreateParams

src/cloudflare/types/workers/ai_run_params.py

+126-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,136 @@
22

33
from __future__ import annotations
44

5+
from typing import List, Union, Iterable
56
from typing_extensions import Required, TypedDict
67

7-
__all__ = ["AIRunParams"]
8+
from ..._types import FileTypes
9+
10+
__all__ = [
11+
"AIRunParams",
12+
"Body",
13+
"BodyTextClassification",
14+
"BodyTextToImage",
15+
"BodySentenceSimilarity",
16+
"BodyTextEmbeddings",
17+
"BodyAudio",
18+
"BodyImage",
19+
"BodyUnionMember10",
20+
"BodyUnionMember11",
21+
"BodyUnionMember11Message",
22+
"BodyTranslation",
23+
"BodySummarization",
24+
"BodyUnionMember15",
25+
]
826

927

1028
class AIRunParams(TypedDict, total=False):
1129
account_id: Required[str]
1230

13-
body: Required[object]
31+
body: Required[Body]
32+
33+
34+
class BodyTextClassification(TypedDict, total=False):
35+
text: Required[str]
36+
37+
38+
class BodyTextToImage(TypedDict, total=False):
39+
prompt: Required[str]
40+
41+
guidance: float
42+
43+
image: Iterable[float]
44+
45+
mask: Iterable[float]
46+
47+
num_steps: int
48+
49+
strength: float
50+
51+
52+
class BodySentenceSimilarity(TypedDict, total=False):
53+
sentences: Required[List[str]]
54+
55+
source: Required[str]
56+
57+
58+
class BodyTextEmbeddings(TypedDict, total=False):
59+
text: Required[Union[str, List[str]]]
60+
61+
62+
class BodyAudio(TypedDict, total=False):
63+
audio: Iterable[float]
64+
65+
66+
class BodyImage(TypedDict, total=False):
67+
image: Iterable[float]
68+
69+
70+
class BodyImage(TypedDict, total=False):
71+
image: Iterable[float]
72+
73+
74+
class BodyUnionMember10(TypedDict, total=False):
75+
prompt: Required[str]
76+
77+
max_tokens: int
78+
79+
raw: bool
80+
81+
stream: bool
82+
83+
84+
class BodyUnionMember11Message(TypedDict, total=False):
85+
content: Required[str]
86+
87+
role: Required[str]
88+
89+
90+
class BodyUnionMember11(TypedDict, total=False):
91+
messages: Required[Iterable[BodyUnionMember11Message]]
92+
93+
max_tokens: int
94+
95+
stream: bool
96+
97+
98+
class BodyTranslation(TypedDict, total=False):
99+
target_lang: Required[str]
100+
101+
text: Required[str]
102+
103+
source_lang: str
104+
105+
106+
class BodySummarization(TypedDict, total=False):
107+
input_text: Required[str]
108+
109+
max_length: int
110+
111+
112+
class BodyUnionMember15(TypedDict, total=False):
113+
image: Iterable[float]
114+
115+
max_tokens: int
116+
117+
prompt: str
118+
119+
120+
Body = Union[
121+
BodyTextClassification,
122+
BodyTextToImage,
123+
BodySentenceSimilarity,
124+
BodyTextEmbeddings,
125+
FileTypes,
126+
BodyAudio,
127+
FileTypes,
128+
BodyImage,
129+
FileTypes,
130+
BodyImage,
131+
BodyUnionMember10,
132+
BodyUnionMember11,
133+
BodyTranslation,
134+
BodySummarization,
135+
FileTypes,
136+
BodyUnionMember15,
137+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# File generated from our OpenAPI spec by Stainless.
2+
3+
from typing import List, Union, Optional
4+
5+
from ..._models import BaseModel
6+
7+
__all__ = [
8+
"AIRunResponse",
9+
"TextClassification",
10+
"TextEmbeddings",
11+
"SpeechRecognition",
12+
"SpeechRecognitionWord",
13+
"ImageClassification",
14+
"ObjectDetection",
15+
"ObjectDetectionBox",
16+
"Response",
17+
"Translation",
18+
"Summarization",
19+
"ImageToText",
20+
]
21+
22+
23+
class TextClassification(BaseModel):
24+
label: Optional[str] = None
25+
26+
score: Optional[float] = None
27+
28+
29+
class TextEmbeddings(BaseModel):
30+
data: Optional[List[List[float]]] = None
31+
32+
shape: Optional[List[float]] = None
33+
34+
35+
class SpeechRecognitionWord(BaseModel):
36+
end: Optional[float] = None
37+
38+
start: Optional[float] = None
39+
40+
word: Optional[str] = None
41+
42+
43+
class SpeechRecognition(BaseModel):
44+
text: str
45+
46+
word_count: Optional[float] = None
47+
48+
words: Optional[List[SpeechRecognitionWord]] = None
49+
50+
51+
class ImageClassification(BaseModel):
52+
label: Optional[str] = None
53+
54+
score: Optional[float] = None
55+
56+
57+
class ObjectDetectionBox(BaseModel):
58+
xmax: Optional[float] = None
59+
60+
xmin: Optional[float] = None
61+
62+
ymax: Optional[float] = None
63+
64+
ymin: Optional[float] = None
65+
66+
67+
class ObjectDetection(BaseModel):
68+
box: Optional[ObjectDetectionBox] = None
69+
70+
label: Optional[str] = None
71+
72+
score: Optional[float] = None
73+
74+
75+
class Response(BaseModel):
76+
response: Optional[str] = None
77+
78+
79+
class Translation(BaseModel):
80+
translated_text: Optional[str] = None
81+
82+
83+
class Summarization(BaseModel):
84+
summary: Optional[str] = None
85+
86+
87+
class ImageToText(BaseModel):
88+
description: Optional[str] = None
89+
90+
91+
AIRunResponse = Union[
92+
List[TextClassification],
93+
object,
94+
List[float],
95+
TextEmbeddings,
96+
SpeechRecognition,
97+
List[ImageClassification],
98+
List[ObjectDetection],
99+
Response,
100+
object,
101+
Translation,
102+
Summarization,
103+
ImageToText,
104+
]

0 commit comments

Comments
 (0)