Skip to content

Commit

Permalink
feat(api): OpenAPI spec update via Stainless API (#1187)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Jul 15, 2024
1 parent 84d7b0d commit 1022f30
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 321 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 1256
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-e9e968f2bf05402754affac40563fb49a9f7979ad72579fd407bedb0ba702ff5.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-7c1304c4f3acd7dbe8b476827fe5df13055ab6634accc43a8edbbb82e1208a98.yml
166 changes: 80 additions & 86 deletions src/cloudflare/resources/workers/ai/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,42 +50,6 @@ def with_raw_response(self) -> AIResourceWithRawResponse:
def with_streaming_response(self) -> AIResourceWithStreamingResponse:
return AIResourceWithStreamingResponse(self)

@overload
def run(
self,
model_name: str,
*,
account_id: str,
body: object,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Optional[AIRunResponse]:
"""
This endpoint provides users with the capability to run specific AI models
on-demand.
By submitting the required input data, users can receive real-time predictions
or results generated by the chosen AI model. The endpoint supports various AI
model types, ensuring flexibility and adaptability for diverse use cases.
Model specific inputs available in
[Cloudflare Docs](https://developers.cloudflare.com/workers-ai/models/).
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
...

@overload
def run(
self,
Expand Down Expand Up @@ -367,15 +331,15 @@ def run(
model_name: str,
*,
account_id: str,
messages: Iterable[ai_run_params.Variant8Message],
messages: Iterable[ai_run_params.Variant7Message],
frequency_penalty: float | NotGiven = NOT_GIVEN,
max_tokens: int | NotGiven = NOT_GIVEN,
presence_penalty: float | NotGiven = NOT_GIVEN,
repetition_penalty: float | NotGiven = NOT_GIVEN,
seed: int | NotGiven = NOT_GIVEN,
stream: bool | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
tools: Iterable[ai_run_params.Variant8Tool] | NotGiven = NOT_GIVEN,
tools: Iterable[ai_run_params.Variant7Tool] | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
Expand Down Expand Up @@ -524,7 +488,6 @@ def run(
...

@required_args(
["account_id", "body"],
["account_id", "text"],
["account_id", "prompt"],
["account_id", "audio"],
Expand All @@ -539,7 +502,6 @@ def run(
model_name: str,
*,
account_id: str,
body: object | NotGiven = NOT_GIVEN,
text: str | Union[str, List[str]] | NotGiven = NOT_GIVEN,
prompt: str | NotGiven = NOT_GIVEN,
guidance: float | NotGiven = NOT_GIVEN,
Expand All @@ -565,8 +527,8 @@ def run(
temperature: float | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
messages: Iterable[ai_run_params.Variant8Message] | NotGiven = NOT_GIVEN,
tools: Iterable[ai_run_params.Variant8Tool] | NotGiven = NOT_GIVEN,
messages: Iterable[ai_run_params.Variant7Message] | NotGiven = NOT_GIVEN,
tools: Iterable[ai_run_params.Variant7Tool] | NotGiven = NOT_GIVEN,
target_lang: str | NotGiven = NOT_GIVEN,
source_lang: str | NotGiven = NOT_GIVEN,
input_text: str | NotGiven = NOT_GIVEN,
Expand All @@ -586,7 +548,42 @@ def run(
Optional[AIRunResponse],
self._post(
f"/accounts/{account_id}/ai/run/{model_name}",
body=maybe_transform(body, ai_run_params.AIRunParams),
body=maybe_transform(
{
"text": text,
"prompt": prompt,
"guidance": guidance,
"height": height,
"image": image,
"image_b64": image_b64,
"lora_weights": lora_weights,
"loras": loras,
"mask": mask,
"negative_prompt": negative_prompt,
"num_steps": num_steps,
"seed": seed,
"strength": strength,
"width": width,
"audio": audio,
"frequency_penalty": frequency_penalty,
"lora": lora,
"max_tokens": max_tokens,
"presence_penalty": presence_penalty,
"raw": raw,
"repetition_penalty": repetition_penalty,
"stream": stream,
"temperature": temperature,
"top_k": top_k,
"top_p": top_p,
"messages": messages,
"tools": tools,
"target_lang": target_lang,
"source_lang": source_lang,
"input_text": input_text,
"max_length": max_length,
},
ai_run_params.AIRunParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
Expand Down Expand Up @@ -614,42 +611,6 @@ def with_raw_response(self) -> AsyncAIResourceWithRawResponse:
def with_streaming_response(self) -> AsyncAIResourceWithStreamingResponse:
return AsyncAIResourceWithStreamingResponse(self)

@overload
async def run(
self,
model_name: str,
*,
account_id: str,
body: object,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Optional[AIRunResponse]:
"""
This endpoint provides users with the capability to run specific AI models
on-demand.
By submitting the required input data, users can receive real-time predictions
or results generated by the chosen AI model. The endpoint supports various AI
model types, ensuring flexibility and adaptability for diverse use cases.
Model specific inputs available in
[Cloudflare Docs](https://developers.cloudflare.com/workers-ai/models/).
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
...

@overload
async def run(
self,
Expand Down Expand Up @@ -931,15 +892,15 @@ async def run(
model_name: str,
*,
account_id: str,
messages: Iterable[ai_run_params.Variant8Message],
messages: Iterable[ai_run_params.Variant7Message],
frequency_penalty: float | NotGiven = NOT_GIVEN,
max_tokens: int | NotGiven = NOT_GIVEN,
presence_penalty: float | NotGiven = NOT_GIVEN,
repetition_penalty: float | NotGiven = NOT_GIVEN,
seed: int | NotGiven = NOT_GIVEN,
stream: bool | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
tools: Iterable[ai_run_params.Variant8Tool] | NotGiven = NOT_GIVEN,
tools: Iterable[ai_run_params.Variant7Tool] | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
Expand Down Expand Up @@ -1088,7 +1049,6 @@ async def run(
...

@required_args(
["account_id", "body"],
["account_id", "text"],
["account_id", "prompt"],
["account_id", "audio"],
Expand All @@ -1103,7 +1063,6 @@ async def run(
model_name: str,
*,
account_id: str,
body: object | NotGiven = NOT_GIVEN,
text: str | Union[str, List[str]] | NotGiven = NOT_GIVEN,
prompt: str | NotGiven = NOT_GIVEN,
guidance: float | NotGiven = NOT_GIVEN,
Expand All @@ -1129,8 +1088,8 @@ async def run(
temperature: float | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
messages: Iterable[ai_run_params.Variant8Message] | NotGiven = NOT_GIVEN,
tools: Iterable[ai_run_params.Variant8Tool] | NotGiven = NOT_GIVEN,
messages: Iterable[ai_run_params.Variant7Message] | NotGiven = NOT_GIVEN,
tools: Iterable[ai_run_params.Variant7Tool] | NotGiven = NOT_GIVEN,
target_lang: str | NotGiven = NOT_GIVEN,
source_lang: str | NotGiven = NOT_GIVEN,
input_text: str | NotGiven = NOT_GIVEN,
Expand All @@ -1150,7 +1109,42 @@ async def run(
Optional[AIRunResponse],
await self._post(
f"/accounts/{account_id}/ai/run/{model_name}",
body=await async_maybe_transform(body, ai_run_params.AIRunParams),
body=await async_maybe_transform(
{
"text": text,
"prompt": prompt,
"guidance": guidance,
"height": height,
"image": image,
"image_b64": image_b64,
"lora_weights": lora_weights,
"loras": loras,
"mask": mask,
"negative_prompt": negative_prompt,
"num_steps": num_steps,
"seed": seed,
"strength": strength,
"width": width,
"audio": audio,
"frequency_penalty": frequency_penalty,
"lora": lora,
"max_tokens": max_tokens,
"presence_penalty": presence_penalty,
"raw": raw,
"repetition_penalty": repetition_penalty,
"stream": stream,
"temperature": temperature,
"top_k": top_k,
"top_p": top_p,
"messages": messages,
"tools": tools,
"target_lang": target_lang,
"source_lang": source_lang,
"input_text": input_text,
"max_length": max_length,
},
ai_run_params.AIRunParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
Expand Down
46 changes: 19 additions & 27 deletions src/cloudflare/types/workers/ai_run_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,26 @@

__all__ = [
"AIRunParams",
"DumbPipe",
"TextClassification",
"TextToImage",
"TextEmbeddings",
"AutomaticSpeechRecognition",
"ImageClassification",
"ObjectDetection",
"Variant6",
"Variant7",
"Variant8",
"Variant8Message",
"Variant8Tool",
"Variant8ToolFunction",
"Variant8ToolFunctionParameters",
"Variant8ToolFunctionParametersProperties",
"Variant7Message",
"Variant7Tool",
"Variant7ToolFunction",
"Variant7ToolFunctionParameters",
"Variant7ToolFunctionParametersProperties",
"Translation",
"Summarization",
"ImageToText",
"ImageToTextMessage",
]


class DumbPipe(TypedDict, total=False):
account_id: Required[str]

body: Required[object]


class TextClassification(TypedDict, total=False):
account_id: Required[str]

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


class Variant7(TypedDict, total=False):
class Variant6(TypedDict, total=False):
account_id: Required[str]

prompt: Required[str]
Expand Down Expand Up @@ -122,10 +115,10 @@ class Variant7(TypedDict, total=False):
top_p: float


class Variant8(TypedDict, total=False):
class Variant7(TypedDict, total=False):
account_id: Required[str]

messages: Required[Iterable[Variant8Message]]
messages: Required[Iterable[Variant7Message]]

frequency_penalty: float

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

temperature: float

tools: Iterable[Variant8Tool]
tools: Iterable[Variant7Tool]

top_k: int

top_p: float


class Variant8Message(TypedDict, total=False):
class Variant7Message(TypedDict, total=False):
content: Required[str]

role: Required[str]


class Variant8ToolFunctionParametersProperties(TypedDict, total=False):
class Variant7ToolFunctionParametersProperties(TypedDict, total=False):
description: str

type: str


class Variant8ToolFunctionParameters(TypedDict, total=False):
properties: Dict[str, Variant8ToolFunctionParametersProperties]
class Variant7ToolFunctionParameters(TypedDict, total=False):
properties: Dict[str, Variant7ToolFunctionParametersProperties]

required: List[str]

type: str


class Variant8ToolFunction(TypedDict, total=False):
class Variant7ToolFunction(TypedDict, total=False):
description: str

name: str

parameters: Variant8ToolFunctionParameters
parameters: Variant7ToolFunctionParameters


class Variant8Tool(TypedDict, total=False):
function: Variant8ToolFunction
class Variant7Tool(TypedDict, total=False):
function: Variant7ToolFunction

type: str

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


AIRunParams = Union[
DumbPipe,
TextClassification,
TextToImage,
TextEmbeddings,
AutomaticSpeechRecognition,
ImageClassification,
ObjectDetection,
Variant6,
Variant7,
Variant8,
Translation,
Summarization,
ImageToText,
Expand Down
Loading

0 comments on commit 1022f30

Please sign in to comment.