Skip to content

Commit 1022f30

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
feat(api): OpenAPI spec update via Stainless API (#1187)
1 parent 84d7b0d commit 1022f30

5 files changed

Lines changed: 200 additions & 321 deletions

File tree

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 1256
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-e9e968f2bf05402754affac40563fb49a9f7979ad72579fd407bedb0ba702ff5.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-7c1304c4f3acd7dbe8b476827fe5df13055ab6634accc43a8edbbb82e1208a98.yml

src/cloudflare/resources/workers/ai/ai.py

Lines changed: 80 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -50,42 +50,6 @@ def with_raw_response(self) -> AIResourceWithRawResponse:
5050
def with_streaming_response(self) -> AIResourceWithStreamingResponse:
5151
return AIResourceWithStreamingResponse(self)
5252

53-
@overload
54-
def run(
55-
self,
56-
model_name: str,
57-
*,
58-
account_id: str,
59-
body: object,
60-
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
61-
# The extra values given here take precedence over values defined on the client or passed to this method.
62-
extra_headers: Headers | None = None,
63-
extra_query: Query | None = None,
64-
extra_body: Body | None = None,
65-
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
66-
) -> Optional[AIRunResponse]:
67-
"""
68-
This endpoint provides users with the capability to run specific AI models
69-
on-demand.
70-
71-
By submitting the required input data, users can receive real-time predictions
72-
or results generated by the chosen AI model. The endpoint supports various AI
73-
model types, ensuring flexibility and adaptability for diverse use cases.
74-
75-
Model specific inputs available in
76-
[Cloudflare Docs](https://developers.cloudflare.com/workers-ai/models/).
77-
78-
Args:
79-
extra_headers: Send extra headers
80-
81-
extra_query: Add additional query parameters to the request
82-
83-
extra_body: Add additional JSON properties to the request
84-
85-
timeout: Override the client-level default timeout for this request, in seconds
86-
"""
87-
...
88-
8953
@overload
9054
def run(
9155
self,
@@ -367,15 +331,15 @@ def run(
367331
model_name: str,
368332
*,
369333
account_id: str,
370-
messages: Iterable[ai_run_params.Variant8Message],
334+
messages: Iterable[ai_run_params.Variant7Message],
371335
frequency_penalty: float | NotGiven = NOT_GIVEN,
372336
max_tokens: int | NotGiven = NOT_GIVEN,
373337
presence_penalty: float | NotGiven = NOT_GIVEN,
374338
repetition_penalty: float | NotGiven = NOT_GIVEN,
375339
seed: int | NotGiven = NOT_GIVEN,
376340
stream: bool | NotGiven = NOT_GIVEN,
377341
temperature: float | NotGiven = NOT_GIVEN,
378-
tools: Iterable[ai_run_params.Variant8Tool] | NotGiven = NOT_GIVEN,
342+
tools: Iterable[ai_run_params.Variant7Tool] | NotGiven = NOT_GIVEN,
379343
top_k: int | NotGiven = NOT_GIVEN,
380344
top_p: float | NotGiven = NOT_GIVEN,
381345
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -524,7 +488,6 @@ def run(
524488
...
525489

526490
@required_args(
527-
["account_id", "body"],
528491
["account_id", "text"],
529492
["account_id", "prompt"],
530493
["account_id", "audio"],
@@ -539,7 +502,6 @@ def run(
539502
model_name: str,
540503
*,
541504
account_id: str,
542-
body: object | NotGiven = NOT_GIVEN,
543505
text: str | Union[str, List[str]] | NotGiven = NOT_GIVEN,
544506
prompt: str | NotGiven = NOT_GIVEN,
545507
guidance: float | NotGiven = NOT_GIVEN,
@@ -565,8 +527,8 @@ def run(
565527
temperature: float | NotGiven = NOT_GIVEN,
566528
top_k: int | NotGiven = NOT_GIVEN,
567529
top_p: float | NotGiven = NOT_GIVEN,
568-
messages: Iterable[ai_run_params.Variant8Message] | NotGiven = NOT_GIVEN,
569-
tools: Iterable[ai_run_params.Variant8Tool] | NotGiven = NOT_GIVEN,
530+
messages: Iterable[ai_run_params.Variant7Message] | NotGiven = NOT_GIVEN,
531+
tools: Iterable[ai_run_params.Variant7Tool] | NotGiven = NOT_GIVEN,
570532
target_lang: str | NotGiven = NOT_GIVEN,
571533
source_lang: str | NotGiven = NOT_GIVEN,
572534
input_text: str | NotGiven = NOT_GIVEN,
@@ -586,7 +548,42 @@ def run(
586548
Optional[AIRunResponse],
587549
self._post(
588550
f"/accounts/{account_id}/ai/run/{model_name}",
589-
body=maybe_transform(body, ai_run_params.AIRunParams),
551+
body=maybe_transform(
552+
{
553+
"text": text,
554+
"prompt": prompt,
555+
"guidance": guidance,
556+
"height": height,
557+
"image": image,
558+
"image_b64": image_b64,
559+
"lora_weights": lora_weights,
560+
"loras": loras,
561+
"mask": mask,
562+
"negative_prompt": negative_prompt,
563+
"num_steps": num_steps,
564+
"seed": seed,
565+
"strength": strength,
566+
"width": width,
567+
"audio": audio,
568+
"frequency_penalty": frequency_penalty,
569+
"lora": lora,
570+
"max_tokens": max_tokens,
571+
"presence_penalty": presence_penalty,
572+
"raw": raw,
573+
"repetition_penalty": repetition_penalty,
574+
"stream": stream,
575+
"temperature": temperature,
576+
"top_k": top_k,
577+
"top_p": top_p,
578+
"messages": messages,
579+
"tools": tools,
580+
"target_lang": target_lang,
581+
"source_lang": source_lang,
582+
"input_text": input_text,
583+
"max_length": max_length,
584+
},
585+
ai_run_params.AIRunParams,
586+
),
590587
options=make_request_options(
591588
extra_headers=extra_headers,
592589
extra_query=extra_query,
@@ -614,42 +611,6 @@ def with_raw_response(self) -> AsyncAIResourceWithRawResponse:
614611
def with_streaming_response(self) -> AsyncAIResourceWithStreamingResponse:
615612
return AsyncAIResourceWithStreamingResponse(self)
616613

617-
@overload
618-
async def run(
619-
self,
620-
model_name: str,
621-
*,
622-
account_id: str,
623-
body: object,
624-
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
625-
# The extra values given here take precedence over values defined on the client or passed to this method.
626-
extra_headers: Headers | None = None,
627-
extra_query: Query | None = None,
628-
extra_body: Body | None = None,
629-
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
630-
) -> Optional[AIRunResponse]:
631-
"""
632-
This endpoint provides users with the capability to run specific AI models
633-
on-demand.
634-
635-
By submitting the required input data, users can receive real-time predictions
636-
or results generated by the chosen AI model. The endpoint supports various AI
637-
model types, ensuring flexibility and adaptability for diverse use cases.
638-
639-
Model specific inputs available in
640-
[Cloudflare Docs](https://developers.cloudflare.com/workers-ai/models/).
641-
642-
Args:
643-
extra_headers: Send extra headers
644-
645-
extra_query: Add additional query parameters to the request
646-
647-
extra_body: Add additional JSON properties to the request
648-
649-
timeout: Override the client-level default timeout for this request, in seconds
650-
"""
651-
...
652-
653614
@overload
654615
async def run(
655616
self,
@@ -931,15 +892,15 @@ async def run(
931892
model_name: str,
932893
*,
933894
account_id: str,
934-
messages: Iterable[ai_run_params.Variant8Message],
895+
messages: Iterable[ai_run_params.Variant7Message],
935896
frequency_penalty: float | NotGiven = NOT_GIVEN,
936897
max_tokens: int | NotGiven = NOT_GIVEN,
937898
presence_penalty: float | NotGiven = NOT_GIVEN,
938899
repetition_penalty: float | NotGiven = NOT_GIVEN,
939900
seed: int | NotGiven = NOT_GIVEN,
940901
stream: bool | NotGiven = NOT_GIVEN,
941902
temperature: float | NotGiven = NOT_GIVEN,
942-
tools: Iterable[ai_run_params.Variant8Tool] | NotGiven = NOT_GIVEN,
903+
tools: Iterable[ai_run_params.Variant7Tool] | NotGiven = NOT_GIVEN,
943904
top_k: int | NotGiven = NOT_GIVEN,
944905
top_p: float | NotGiven = NOT_GIVEN,
945906
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -1088,7 +1049,6 @@ async def run(
10881049
...
10891050

10901051
@required_args(
1091-
["account_id", "body"],
10921052
["account_id", "text"],
10931053
["account_id", "prompt"],
10941054
["account_id", "audio"],
@@ -1103,7 +1063,6 @@ async def run(
11031063
model_name: str,
11041064
*,
11051065
account_id: str,
1106-
body: object | NotGiven = NOT_GIVEN,
11071066
text: str | Union[str, List[str]] | NotGiven = NOT_GIVEN,
11081067
prompt: str | NotGiven = NOT_GIVEN,
11091068
guidance: float | NotGiven = NOT_GIVEN,
@@ -1129,8 +1088,8 @@ async def run(
11291088
temperature: float | NotGiven = NOT_GIVEN,
11301089
top_k: int | NotGiven = NOT_GIVEN,
11311090
top_p: float | NotGiven = NOT_GIVEN,
1132-
messages: Iterable[ai_run_params.Variant8Message] | NotGiven = NOT_GIVEN,
1133-
tools: Iterable[ai_run_params.Variant8Tool] | NotGiven = NOT_GIVEN,
1091+
messages: Iterable[ai_run_params.Variant7Message] | NotGiven = NOT_GIVEN,
1092+
tools: Iterable[ai_run_params.Variant7Tool] | NotGiven = NOT_GIVEN,
11341093
target_lang: str | NotGiven = NOT_GIVEN,
11351094
source_lang: str | NotGiven = NOT_GIVEN,
11361095
input_text: str | NotGiven = NOT_GIVEN,
@@ -1150,7 +1109,42 @@ async def run(
11501109
Optional[AIRunResponse],
11511110
await self._post(
11521111
f"/accounts/{account_id}/ai/run/{model_name}",
1153-
body=await async_maybe_transform(body, ai_run_params.AIRunParams),
1112+
body=await async_maybe_transform(
1113+
{
1114+
"text": text,
1115+
"prompt": prompt,
1116+
"guidance": guidance,
1117+
"height": height,
1118+
"image": image,
1119+
"image_b64": image_b64,
1120+
"lora_weights": lora_weights,
1121+
"loras": loras,
1122+
"mask": mask,
1123+
"negative_prompt": negative_prompt,
1124+
"num_steps": num_steps,
1125+
"seed": seed,
1126+
"strength": strength,
1127+
"width": width,
1128+
"audio": audio,
1129+
"frequency_penalty": frequency_penalty,
1130+
"lora": lora,
1131+
"max_tokens": max_tokens,
1132+
"presence_penalty": presence_penalty,
1133+
"raw": raw,
1134+
"repetition_penalty": repetition_penalty,
1135+
"stream": stream,
1136+
"temperature": temperature,
1137+
"top_k": top_k,
1138+
"top_p": top_p,
1139+
"messages": messages,
1140+
"tools": tools,
1141+
"target_lang": target_lang,
1142+
"source_lang": source_lang,
1143+
"input_text": input_text,
1144+
"max_length": max_length,
1145+
},
1146+
ai_run_params.AIRunParams,
1147+
),
11541148
options=make_request_options(
11551149
extra_headers=extra_headers,
11561150
extra_query=extra_query,

src/cloudflare/types/workers/ai_run_params.py

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,26 @@
77

88
__all__ = [
99
"AIRunParams",
10-
"DumbPipe",
1110
"TextClassification",
1211
"TextToImage",
1312
"TextEmbeddings",
1413
"AutomaticSpeechRecognition",
1514
"ImageClassification",
1615
"ObjectDetection",
16+
"Variant6",
1717
"Variant7",
18-
"Variant8",
19-
"Variant8Message",
20-
"Variant8Tool",
21-
"Variant8ToolFunction",
22-
"Variant8ToolFunctionParameters",
23-
"Variant8ToolFunctionParametersProperties",
18+
"Variant7Message",
19+
"Variant7Tool",
20+
"Variant7ToolFunction",
21+
"Variant7ToolFunctionParameters",
22+
"Variant7ToolFunctionParametersProperties",
2423
"Translation",
2524
"Summarization",
2625
"ImageToText",
2726
"ImageToTextMessage",
2827
]
2928

3029

31-
class DumbPipe(TypedDict, total=False):
32-
account_id: Required[str]
33-
34-
body: Required[object]
35-
36-
3730
class TextClassification(TypedDict, total=False):
3831
account_id: Required[str]
3932

@@ -94,7 +87,7 @@ class ObjectDetection(TypedDict, total=False):
9487
image: Iterable[float]
9588

9689

97-
class Variant7(TypedDict, total=False):
90+
class Variant6(TypedDict, total=False):
9891
account_id: Required[str]
9992

10093
prompt: Required[str]
@@ -122,10 +115,10 @@ class Variant7(TypedDict, total=False):
122115
top_p: float
123116

124117

125-
class Variant8(TypedDict, total=False):
118+
class Variant7(TypedDict, total=False):
126119
account_id: Required[str]
127120

128-
messages: Required[Iterable[Variant8Message]]
121+
messages: Required[Iterable[Variant7Message]]
129122

130123
frequency_penalty: float
131124

@@ -141,43 +134,43 @@ class Variant8(TypedDict, total=False):
141134

142135
temperature: float
143136

144-
tools: Iterable[Variant8Tool]
137+
tools: Iterable[Variant7Tool]
145138

146139
top_k: int
147140

148141
top_p: float
149142

150143

151-
class Variant8Message(TypedDict, total=False):
144+
class Variant7Message(TypedDict, total=False):
152145
content: Required[str]
153146

154147
role: Required[str]
155148

156149

157-
class Variant8ToolFunctionParametersProperties(TypedDict, total=False):
150+
class Variant7ToolFunctionParametersProperties(TypedDict, total=False):
158151
description: str
159152

160153
type: str
161154

162155

163-
class Variant8ToolFunctionParameters(TypedDict, total=False):
164-
properties: Dict[str, Variant8ToolFunctionParametersProperties]
156+
class Variant7ToolFunctionParameters(TypedDict, total=False):
157+
properties: Dict[str, Variant7ToolFunctionParametersProperties]
165158

166159
required: List[str]
167160

168161
type: str
169162

170163

171-
class Variant8ToolFunction(TypedDict, total=False):
164+
class Variant7ToolFunction(TypedDict, total=False):
172165
description: str
173166

174167
name: str
175168

176-
parameters: Variant8ToolFunctionParameters
169+
parameters: Variant7ToolFunctionParameters
177170

178171

179-
class Variant8Tool(TypedDict, total=False):
180-
function: Variant8ToolFunction
172+
class Variant7Tool(TypedDict, total=False):
173+
function: Variant7ToolFunction
181174

182175
type: str
183176

@@ -223,15 +216,14 @@ class ImageToTextMessage(TypedDict, total=False):
223216

224217

225218
AIRunParams = Union[
226-
DumbPipe,
227219
TextClassification,
228220
TextToImage,
229221
TextEmbeddings,
230222
AutomaticSpeechRecognition,
231223
ImageClassification,
232224
ObjectDetection,
225+
Variant6,
233226
Variant7,
234-
Variant8,
235227
Translation,
236228
Summarization,
237229
ImageToText,

0 commit comments

Comments
 (0)