From bd391285901325bd8cc1aa6462ed76bd1295b91d Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 23 Apr 2024 21:38:38 +0000 Subject: [PATCH] feat(api): OpenAPI spec update via Stainless API (#358) --- src/cloudflare/resources/workers/ai.py | 18 ++++++-- src/cloudflare/types/workers/ai_run_params.py | 15 ++++++- tests/api_resources/workers/test_ai.py | 42 +++++++++++++++++++ 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/src/cloudflare/resources/workers/ai.py b/src/cloudflare/resources/workers/ai.py index 7d95c1efb76..ecd0be332d2 100644 --- a/src/cloudflare/resources/workers/ai.py +++ b/src/cloudflare/resources/workers/ai.py @@ -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, @@ -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, @@ -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, @@ -523,6 +527,7 @@ def run( "source_lang": source_lang, "input_text": input_text, "max_length": max_length, + "temperature": temperature, }, ai_run_params.AIRunParams, ), @@ -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, @@ -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, @@ -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, @@ -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, ), diff --git a/src/cloudflare/types/workers/ai_run_params.py b/src/cloudflare/types/workers/ai_run_params.py index f29e3068b68..888e17d7d99 100644 --- a/src/cloudflare/types/workers/ai_run_params.py +++ b/src/cloudflare/types/workers/ai_run_params.py @@ -19,6 +19,7 @@ "Translation", "Summarization", "ImageToText", + "ImageToTextMessage", ] @@ -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, diff --git a/tests/api_resources/workers/test_ai.py b/tests/api_resources/workers/test_ai.py index 3ad76d766d6..9b149b9f72b 100644 --- a/tests/api_resources/workers/test_ai.py +++ b/tests/api_resources/workers/test_ai.py @@ -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"]) @@ -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"]) @@ -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 @@ -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" @@ -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], ) @@ -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"]) @@ -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"]) @@ -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 @@ -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" @@ -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], )