Skip to content

Commit 0c9946d

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
feat(api): OpenAPI spec update via Stainless API (#358)
1 parent d7aa7ad commit 0c9946d

File tree

3 files changed

+70
-5
lines changed

3 files changed

+70
-5
lines changed

src/cloudflare/resources/workers/ai.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,12 @@ def run(
418418
model_name: str,
419419
*,
420420
account_id: str,
421-
image: Iterable[float] | NotGiven = NOT_GIVEN,
421+
image: Iterable[float],
422422
max_tokens: int | NotGiven = NOT_GIVEN,
423+
messages: Iterable[ai_run_params.ImageToTextMessage] | NotGiven = NOT_GIVEN,
423424
prompt: str | NotGiven = NOT_GIVEN,
425+
raw: bool | NotGiven = NOT_GIVEN,
426+
temperature: float | NotGiven = NOT_GIVEN,
424427
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
425428
# The extra values given here take precedence over values defined on the client or passed to this method.
426429
extra_headers: Headers | None = None,
@@ -461,7 +464,7 @@ def run(
461464
["account_id"],
462465
["account_id", "target_lang", "text"],
463466
["account_id", "input_text"],
464-
["account_id"],
467+
["account_id", "image"],
465468
)
466469
def run(
467470
self,
@@ -487,6 +490,7 @@ def run(
487490
source_lang: str | NotGiven = NOT_GIVEN,
488491
input_text: str | NotGiven = NOT_GIVEN,
489492
max_length: int | NotGiven = NOT_GIVEN,
493+
temperature: float | NotGiven = NOT_GIVEN,
490494
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
491495
# The extra values given here take precedence over values defined on the client or passed to this method.
492496
extra_headers: Headers | None = None,
@@ -523,6 +527,7 @@ def run(
523527
"source_lang": source_lang,
524528
"input_text": input_text,
525529
"max_length": max_length,
530+
"temperature": temperature,
526531
},
527532
ai_run_params.AIRunParams,
528533
),
@@ -929,9 +934,12 @@ async def run(
929934
model_name: str,
930935
*,
931936
account_id: str,
932-
image: Iterable[float] | NotGiven = NOT_GIVEN,
937+
image: Iterable[float],
933938
max_tokens: int | NotGiven = NOT_GIVEN,
939+
messages: Iterable[ai_run_params.ImageToTextMessage] | NotGiven = NOT_GIVEN,
934940
prompt: str | NotGiven = NOT_GIVEN,
941+
raw: bool | NotGiven = NOT_GIVEN,
942+
temperature: float | NotGiven = NOT_GIVEN,
935943
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
936944
# The extra values given here take precedence over values defined on the client or passed to this method.
937945
extra_headers: Headers | None = None,
@@ -972,7 +980,7 @@ async def run(
972980
["account_id"],
973981
["account_id", "target_lang", "text"],
974982
["account_id", "input_text"],
975-
["account_id"],
983+
["account_id", "image"],
976984
)
977985
async def run(
978986
self,
@@ -998,6 +1006,7 @@ async def run(
9981006
source_lang: str | NotGiven = NOT_GIVEN,
9991007
input_text: str | NotGiven = NOT_GIVEN,
10001008
max_length: int | NotGiven = NOT_GIVEN,
1009+
temperature: float | NotGiven = NOT_GIVEN,
10011010
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
10021011
# The extra values given here take precedence over values defined on the client or passed to this method.
10031012
extra_headers: Headers | None = None,
@@ -1034,6 +1043,7 @@ async def run(
10341043
"source_lang": source_lang,
10351044
"input_text": input_text,
10361045
"max_length": max_length,
1046+
"temperature": temperature,
10371047
},
10381048
ai_run_params.AIRunParams,
10391049
),

src/cloudflare/types/workers/ai_run_params.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"Translation",
2020
"Summarization",
2121
"ImageToText",
22+
"ImageToTextMessage",
2223
]
2324

2425

@@ -119,12 +120,24 @@ class Summarization(TypedDict, total=False):
119120
class ImageToText(TypedDict, total=False):
120121
account_id: Required[str]
121122

122-
image: Iterable[float]
123+
image: Required[Iterable[float]]
123124

124125
max_tokens: int
125126

127+
messages: Iterable[ImageToTextMessage]
128+
126129
prompt: str
127130

131+
raw: bool
132+
133+
temperature: float
134+
135+
136+
class ImageToTextMessage(TypedDict, total=False):
137+
content: Required[str]
138+
139+
role: Required[str]
140+
128141

129142
AIRunParams = Union[
130143
TextClassification,

tests/api_resources/workers/test_ai.py

+42
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ def test_method_run_overload_11(self, client: Cloudflare) -> None:
679679
ai = client.workers.ai.run(
680680
"string",
681681
account_id="023e105f4ecef8ad9ca31a8372d0c353",
682+
image=[0, 0, 0],
682683
)
683684
assert_matches_type(Optional[AIRunResponse], ai, path=["response"])
684685

@@ -690,7 +691,23 @@ def test_method_run_with_all_params_overload_11(self, client: Cloudflare) -> Non
690691
account_id="023e105f4ecef8ad9ca31a8372d0c353",
691692
image=[0, 0, 0],
692693
max_tokens=0,
694+
messages=[
695+
{
696+
"content": "string",
697+
"role": "string",
698+
},
699+
{
700+
"content": "string",
701+
"role": "string",
702+
},
703+
{
704+
"content": "string",
705+
"role": "string",
706+
},
707+
],
693708
prompt="string",
709+
raw=True,
710+
temperature=0,
694711
)
695712
assert_matches_type(Optional[AIRunResponse], ai, path=["response"])
696713

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

705723
assert response.is_closed is True
@@ -713,6 +731,7 @@ def test_streaming_response_run_overload_11(self, client: Cloudflare) -> None:
713731
with client.workers.ai.with_streaming_response.run(
714732
"string",
715733
account_id="023e105f4ecef8ad9ca31a8372d0c353",
734+
image=[0, 0, 0],
716735
) as response:
717736
assert not response.is_closed
718737
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:
729748
client.workers.ai.with_raw_response.run(
730749
"string",
731750
account_id="",
751+
image=[0, 0, 0],
732752
)
733753

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

740761

@@ -1403,6 +1424,7 @@ async def test_method_run_overload_11(self, async_client: AsyncCloudflare) -> No
14031424
ai = await async_client.workers.ai.run(
14041425
"string",
14051426
account_id="023e105f4ecef8ad9ca31a8372d0c353",
1427+
image=[0, 0, 0],
14061428
)
14071429
assert_matches_type(Optional[AIRunResponse], ai, path=["response"])
14081430

@@ -1414,7 +1436,23 @@ async def test_method_run_with_all_params_overload_11(self, async_client: AsyncC
14141436
account_id="023e105f4ecef8ad9ca31a8372d0c353",
14151437
image=[0, 0, 0],
14161438
max_tokens=0,
1439+
messages=[
1440+
{
1441+
"content": "string",
1442+
"role": "string",
1443+
},
1444+
{
1445+
"content": "string",
1446+
"role": "string",
1447+
},
1448+
{
1449+
"content": "string",
1450+
"role": "string",
1451+
},
1452+
],
14171453
prompt="string",
1454+
raw=True,
1455+
temperature=0,
14181456
)
14191457
assert_matches_type(Optional[AIRunResponse], ai, path=["response"])
14201458

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

14291468
assert response.is_closed is True
@@ -1437,6 +1476,7 @@ async def test_streaming_response_run_overload_11(self, async_client: AsyncCloud
14371476
async with async_client.workers.ai.with_streaming_response.run(
14381477
"string",
14391478
account_id="023e105f4ecef8ad9ca31a8372d0c353",
1479+
image=[0, 0, 0],
14401480
) as response:
14411481
assert not response.is_closed
14421482
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)
14531493
await async_client.workers.ai.with_raw_response.run(
14541494
"string",
14551495
account_id="",
1496+
image=[0, 0, 0],
14561497
)
14571498

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

0 commit comments

Comments
 (0)