Skip to content

Commit 3677eab

Browse files
author
stlc-bot
committed
feat(api): unify timeout configuration and return partial results (#1030)
Stainless-Generated-From: 9e0c94c
1 parent 7b4539c commit 3677eab

53 files changed

Lines changed: 1388 additions & 490 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,12 @@ from context.dev import ContextDev
124124

125125
client = ContextDev()
126126

127-
response = client.parse.handle(
128-
body=b"Example data",
129-
pdf={},
127+
brand = client.brand.retrieve(
128+
domain="xxx",
129+
type="by_domain",
130+
timeout_opts={"milliseconds": 1000},
130131
)
131-
print(response.pdf)
132+
print(brand.timeout_opts)
132133
```
133134

134135
## Handling errors

‎src/context/dev/resources/ai.py‎

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def extract_product(
5050
url: str,
5151
max_age_ms: int | Omit = omit,
5252
tags: SequenceNotStr[str] | Omit = omit,
53-
timeout_ms: int | Omit = omit,
53+
timeout_opts: ai_extract_product_params.TimeoutOpts | Omit = omit,
5454
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
5555
# The extra values given here take precedence over values defined on the client or passed to this method.
5656
extra_headers: Headers | None = None,
@@ -71,9 +71,9 @@ def extract_product(
7171
7272
tags: Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.
7373
74-
timeout_ms: Optional timeout in milliseconds for the request. If the request takes longer
75-
than this value, it will be aborted with a 408 status code. Maximum allowed
76-
value is 300000ms (5 minutes).
74+
timeout_opts: Optional request deadline and behavior on timeout. For GET requests, use
75+
timeoutOpts[milliseconds]=30000&timeoutOpts[behavior]=fail or a JSON-encoded
76+
timeoutOpts object.
7777
7878
extra_headers: Send extra headers
7979
@@ -90,7 +90,7 @@ def extract_product(
9090
"url": url,
9191
"max_age_ms": max_age_ms,
9292
"tags": tags,
93-
"timeout_ms": timeout_ms,
93+
"timeout_opts": timeout_opts,
9494
},
9595
ai_extract_product_params.AIExtractProductParams,
9696
),
@@ -108,7 +108,7 @@ def extract_products(
108108
max_age_ms: int | Omit = omit,
109109
max_products: int | Omit = omit,
110110
tags: SequenceNotStr[str] | Omit = omit,
111-
timeout_ms: int | Omit = omit,
111+
timeout_opts: ai_extract_products_params.ByDomainTimeoutOpts | Omit = omit,
112112
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
113113
# The extra values given here take precedence over values defined on the client or passed to this method.
114114
extra_headers: Headers | None = None,
@@ -133,9 +133,9 @@ def extract_products(
133133
134134
tags: Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.
135135
136-
timeout_ms: Optional timeout in milliseconds for the request. If the request takes longer
137-
than this value, it will be aborted with a 408 status code. Maximum allowed
138-
value is 300000ms (5 minutes).
136+
timeout_opts: Optional request deadline and behavior on timeout. For GET requests, use
137+
timeoutOpts[milliseconds]=30000&timeoutOpts[behavior]=fail or a JSON-encoded
138+
timeoutOpts object.
139139
140140
extra_headers: Send extra headers
141141
@@ -155,7 +155,7 @@ def extract_products(
155155
max_age_ms: int | Omit = omit,
156156
max_products: int | Omit = omit,
157157
tags: SequenceNotStr[str] | Omit = omit,
158-
timeout_ms: int | Omit = omit,
158+
timeout_opts: ai_extract_products_params.ByDirectURLTimeoutOpts | Omit = omit,
159159
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
160160
# The extra values given here take precedence over values defined on the client or passed to this method.
161161
extra_headers: Headers | None = None,
@@ -181,9 +181,9 @@ def extract_products(
181181
182182
tags: Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.
183183
184-
timeout_ms: Optional timeout in milliseconds for the request. If the request takes longer
185-
than this value, it will be aborted with a 408 status code. Maximum allowed
186-
value is 300000ms (5 minutes).
184+
timeout_opts: Optional request deadline and behavior on timeout. For GET requests, use
185+
timeoutOpts[milliseconds]=30000&timeoutOpts[behavior]=fail or a JSON-encoded
186+
timeoutOpts object.
187187
188188
extra_headers: Send extra headers
189189
@@ -203,7 +203,9 @@ def extract_products(
203203
max_age_ms: int | Omit = omit,
204204
max_products: int | Omit = omit,
205205
tags: SequenceNotStr[str] | Omit = omit,
206-
timeout_ms: int | Omit = omit,
206+
timeout_opts: ai_extract_products_params.ByDomainTimeoutOpts
207+
| ai_extract_products_params.ByDirectURLTimeoutOpts
208+
| Omit = omit,
207209
direct_url: str | Omit = omit,
208210
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
209211
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -220,7 +222,7 @@ def extract_products(
220222
"max_age_ms": max_age_ms,
221223
"max_products": max_products,
222224
"tags": tags,
223-
"timeout_ms": timeout_ms,
225+
"timeout_opts": timeout_opts,
224226
"direct_url": direct_url,
225227
},
226228
ai_extract_products_params.AIExtractProductsParams,
@@ -258,7 +260,7 @@ async def extract_product(
258260
url: str,
259261
max_age_ms: int | Omit = omit,
260262
tags: SequenceNotStr[str] | Omit = omit,
261-
timeout_ms: int | Omit = omit,
263+
timeout_opts: ai_extract_product_params.TimeoutOpts | Omit = omit,
262264
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
263265
# The extra values given here take precedence over values defined on the client or passed to this method.
264266
extra_headers: Headers | None = None,
@@ -279,9 +281,9 @@ async def extract_product(
279281
280282
tags: Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.
281283
282-
timeout_ms: Optional timeout in milliseconds for the request. If the request takes longer
283-
than this value, it will be aborted with a 408 status code. Maximum allowed
284-
value is 300000ms (5 minutes).
284+
timeout_opts: Optional request deadline and behavior on timeout. For GET requests, use
285+
timeoutOpts[milliseconds]=30000&timeoutOpts[behavior]=fail or a JSON-encoded
286+
timeoutOpts object.
285287
286288
extra_headers: Send extra headers
287289
@@ -298,7 +300,7 @@ async def extract_product(
298300
"url": url,
299301
"max_age_ms": max_age_ms,
300302
"tags": tags,
301-
"timeout_ms": timeout_ms,
303+
"timeout_opts": timeout_opts,
302304
},
303305
ai_extract_product_params.AIExtractProductParams,
304306
),
@@ -316,7 +318,7 @@ async def extract_products(
316318
max_age_ms: int | Omit = omit,
317319
max_products: int | Omit = omit,
318320
tags: SequenceNotStr[str] | Omit = omit,
319-
timeout_ms: int | Omit = omit,
321+
timeout_opts: ai_extract_products_params.ByDomainTimeoutOpts | Omit = omit,
320322
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
321323
# The extra values given here take precedence over values defined on the client or passed to this method.
322324
extra_headers: Headers | None = None,
@@ -341,9 +343,9 @@ async def extract_products(
341343
342344
tags: Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.
343345
344-
timeout_ms: Optional timeout in milliseconds for the request. If the request takes longer
345-
than this value, it will be aborted with a 408 status code. Maximum allowed
346-
value is 300000ms (5 minutes).
346+
timeout_opts: Optional request deadline and behavior on timeout. For GET requests, use
347+
timeoutOpts[milliseconds]=30000&timeoutOpts[behavior]=fail or a JSON-encoded
348+
timeoutOpts object.
347349
348350
extra_headers: Send extra headers
349351
@@ -363,7 +365,7 @@ async def extract_products(
363365
max_age_ms: int | Omit = omit,
364366
max_products: int | Omit = omit,
365367
tags: SequenceNotStr[str] | Omit = omit,
366-
timeout_ms: int | Omit = omit,
368+
timeout_opts: ai_extract_products_params.ByDirectURLTimeoutOpts | Omit = omit,
367369
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
368370
# The extra values given here take precedence over values defined on the client or passed to this method.
369371
extra_headers: Headers | None = None,
@@ -389,9 +391,9 @@ async def extract_products(
389391
390392
tags: Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.
391393
392-
timeout_ms: Optional timeout in milliseconds for the request. If the request takes longer
393-
than this value, it will be aborted with a 408 status code. Maximum allowed
394-
value is 300000ms (5 minutes).
394+
timeout_opts: Optional request deadline and behavior on timeout. For GET requests, use
395+
timeoutOpts[milliseconds]=30000&timeoutOpts[behavior]=fail or a JSON-encoded
396+
timeoutOpts object.
395397
396398
extra_headers: Send extra headers
397399
@@ -411,7 +413,9 @@ async def extract_products(
411413
max_age_ms: int | Omit = omit,
412414
max_products: int | Omit = omit,
413415
tags: SequenceNotStr[str] | Omit = omit,
414-
timeout_ms: int | Omit = omit,
416+
timeout_opts: ai_extract_products_params.ByDomainTimeoutOpts
417+
| ai_extract_products_params.ByDirectURLTimeoutOpts
418+
| Omit = omit,
415419
direct_url: str | Omit = omit,
416420
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
417421
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -428,7 +432,7 @@ async def extract_products(
428432
"max_age_ms": max_age_ms,
429433
"max_products": max_products,
430434
"tags": tags,
431-
"timeout_ms": timeout_ms,
435+
"timeout_opts": timeout_opts,
432436
"direct_url": direct_url,
433437
},
434438
ai_extract_products_params.AIExtractProductsParams,

0 commit comments

Comments
 (0)