Skip to content

Commit

Permalink
feat(api): OpenAPI spec update via Stainless API (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Apr 23, 2024
1 parent d7aa7ad commit 0c9946d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/cloudflare/resources/workers/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,12 @@ def run(
model_name: str,
*,
account_id: str,
image: Iterable[float] | NotGiven = NOT_GIVEN,
image: Iterable[float],
max_tokens: int | NotGiven = NOT_GIVEN,
messages: Iterable[ai_run_params.ImageToTextMessage] | NotGiven = NOT_GIVEN,
prompt: str | NotGiven = NOT_GIVEN,
raw: bool | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
# 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,
Expand Down Expand Up @@ -461,7 +464,7 @@ def run(
["account_id"],
["account_id", "target_lang", "text"],
["account_id", "input_text"],
["account_id"],
["account_id", "image"],
)
def run(
self,
Expand All @@ -487,6 +490,7 @@ def run(
source_lang: str | NotGiven = NOT_GIVEN,
input_text: str | NotGiven = NOT_GIVEN,
max_length: int | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
# 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,
Expand Down Expand Up @@ -523,6 +527,7 @@ def run(
"source_lang": source_lang,
"input_text": input_text,
"max_length": max_length,
"temperature": temperature,
},
ai_run_params.AIRunParams,
),
Expand Down Expand Up @@ -929,9 +934,12 @@ async def run(
model_name: str,
*,
account_id: str,
image: Iterable[float] | NotGiven = NOT_GIVEN,
image: Iterable[float],
max_tokens: int | NotGiven = NOT_GIVEN,
messages: Iterable[ai_run_params.ImageToTextMessage] | NotGiven = NOT_GIVEN,
prompt: str | NotGiven = NOT_GIVEN,
raw: bool | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
# 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,
Expand Down Expand Up @@ -972,7 +980,7 @@ async def run(
["account_id"],
["account_id", "target_lang", "text"],
["account_id", "input_text"],
["account_id"],
["account_id", "image"],
)
async def run(
self,
Expand All @@ -998,6 +1006,7 @@ async def run(
source_lang: str | NotGiven = NOT_GIVEN,
input_text: str | NotGiven = NOT_GIVEN,
max_length: int | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
# 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,
Expand Down Expand Up @@ -1034,6 +1043,7 @@ async def run(
"source_lang": source_lang,
"input_text": input_text,
"max_length": max_length,
"temperature": temperature,
},
ai_run_params.AIRunParams,
),
Expand Down
15 changes: 14 additions & 1 deletion src/cloudflare/types/workers/ai_run_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"Translation",
"Summarization",
"ImageToText",
"ImageToTextMessage",
]


Expand Down Expand Up @@ -119,12 +120,24 @@ class Summarization(TypedDict, total=False):
class ImageToText(TypedDict, total=False):
account_id: Required[str]

image: Iterable[float]
image: Required[Iterable[float]]

max_tokens: int

messages: Iterable[ImageToTextMessage]

prompt: str

raw: bool

temperature: float


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

role: Required[str]


AIRunParams = Union[
TextClassification,
Expand Down
42 changes: 42 additions & 0 deletions tests/api_resources/workers/test_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ def test_method_run_overload_11(self, client: Cloudflare) -> None:
ai = client.workers.ai.run(
"string",
account_id="023e105f4ecef8ad9ca31a8372d0c353",
image=[0, 0, 0],
)
assert_matches_type(Optional[AIRunResponse], ai, path=["response"])

Expand All @@ -690,7 +691,23 @@ def test_method_run_with_all_params_overload_11(self, client: Cloudflare) -> Non
account_id="023e105f4ecef8ad9ca31a8372d0c353",
image=[0, 0, 0],
max_tokens=0,
messages=[
{
"content": "string",
"role": "string",
},
{
"content": "string",
"role": "string",
},
{
"content": "string",
"role": "string",
},
],
prompt="string",
raw=True,
temperature=0,
)
assert_matches_type(Optional[AIRunResponse], ai, path=["response"])

Expand All @@ -700,6 +717,7 @@ def test_raw_response_run_overload_11(self, client: Cloudflare) -> None:
response = client.workers.ai.with_raw_response.run(
"string",
account_id="023e105f4ecef8ad9ca31a8372d0c353",
image=[0, 0, 0],
)

assert response.is_closed is True
Expand All @@ -713,6 +731,7 @@ def test_streaming_response_run_overload_11(self, client: Cloudflare) -> None:
with client.workers.ai.with_streaming_response.run(
"string",
account_id="023e105f4ecef8ad9ca31a8372d0c353",
image=[0, 0, 0],
) as response:
assert not response.is_closed
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
Expand All @@ -729,12 +748,14 @@ def test_path_params_run_overload_11(self, client: Cloudflare) -> None:
client.workers.ai.with_raw_response.run(
"string",
account_id="",
image=[0, 0, 0],
)

with pytest.raises(ValueError, match=r"Expected a non-empty value for `model_name` but received ''"):
client.workers.ai.with_raw_response.run(
"",
account_id="023e105f4ecef8ad9ca31a8372d0c353",
image=[0, 0, 0],
)


Expand Down Expand Up @@ -1403,6 +1424,7 @@ async def test_method_run_overload_11(self, async_client: AsyncCloudflare) -> No
ai = await async_client.workers.ai.run(
"string",
account_id="023e105f4ecef8ad9ca31a8372d0c353",
image=[0, 0, 0],
)
assert_matches_type(Optional[AIRunResponse], ai, path=["response"])

Expand All @@ -1414,7 +1436,23 @@ async def test_method_run_with_all_params_overload_11(self, async_client: AsyncC
account_id="023e105f4ecef8ad9ca31a8372d0c353",
image=[0, 0, 0],
max_tokens=0,
messages=[
{
"content": "string",
"role": "string",
},
{
"content": "string",
"role": "string",
},
{
"content": "string",
"role": "string",
},
],
prompt="string",
raw=True,
temperature=0,
)
assert_matches_type(Optional[AIRunResponse], ai, path=["response"])

Expand All @@ -1424,6 +1462,7 @@ async def test_raw_response_run_overload_11(self, async_client: AsyncCloudflare)
response = await async_client.workers.ai.with_raw_response.run(
"string",
account_id="023e105f4ecef8ad9ca31a8372d0c353",
image=[0, 0, 0],
)

assert response.is_closed is True
Expand All @@ -1437,6 +1476,7 @@ async def test_streaming_response_run_overload_11(self, async_client: AsyncCloud
async with async_client.workers.ai.with_streaming_response.run(
"string",
account_id="023e105f4ecef8ad9ca31a8372d0c353",
image=[0, 0, 0],
) as response:
assert not response.is_closed
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
Expand All @@ -1453,10 +1493,12 @@ async def test_path_params_run_overload_11(self, async_client: AsyncCloudflare)
await async_client.workers.ai.with_raw_response.run(
"string",
account_id="",
image=[0, 0, 0],
)

with pytest.raises(ValueError, match=r"Expected a non-empty value for `model_name` but received ''"):
await async_client.workers.ai.with_raw_response.run(
"",
account_id="023e105f4ecef8ad9ca31a8372d0c353",
image=[0, 0, 0],
)

0 comments on commit 0c9946d

Please sign in to comment.