Skip to content

Commit 3fc9944

Browse files
feat(api): api update
1 parent b9374f5 commit 3fc9944

5 files changed

Lines changed: 75 additions & 5 deletions

File tree

‎.stats.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 21
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev%2Fcontext.dev-86caee6743259bcab1e72868d17acdfc8a515d51b6d9b1e9a1dca49cdd3bd8da.yml
3-
openapi_spec_hash: c0855025a8590139f57db43dd3e1bad1
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev%2Fcontext.dev-955fa0d672331fb3f8b40547895bfdd1e490add254ca13db769289d3bef2ed44.yml
3+
openapi_spec_hash: 32eca3166fb8f369c9241faf4cee3077
44
config_hash: 682b89b02a20f5d1c13e2c91ecbcf5ce

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ def web_scrape_html(
209209
self,
210210
*,
211211
url: str,
212+
max_age_ms: int | Omit = omit,
212213
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
213214
# The extra values given here take precedence over values defined on the client or passed to this method.
214215
extra_headers: Headers | None = None,
@@ -222,6 +223,10 @@ def web_scrape_html(
222223
Args:
223224
url: Full URL to scrape (must include http:// or https:// protocol)
224225
226+
max_age_ms: Return a cached result if a prior scrape for the same parameters exists and is
227+
younger than this many milliseconds. Defaults to 1 day (86400000 ms) when
228+
omitted. Set to 0 to always scrape fresh.
229+
225230
extra_headers: Send extra headers
226231
227232
extra_query: Add additional query parameters to the request
@@ -237,7 +242,13 @@ def web_scrape_html(
237242
extra_query=extra_query,
238243
extra_body=extra_body,
239244
timeout=timeout,
240-
query=maybe_transform({"url": url}, web_web_scrape_html_params.WebWebScrapeHTMLParams),
245+
query=maybe_transform(
246+
{
247+
"url": url,
248+
"max_age_ms": max_age_ms,
249+
},
250+
web_web_scrape_html_params.WebWebScrapeHTMLParams,
251+
),
241252
),
242253
cast_to=WebWebScrapeHTMLResponse,
243254
)
@@ -288,6 +299,7 @@ def web_scrape_md(
288299
url: str,
289300
include_images: bool | Omit = omit,
290301
include_links: bool | Omit = omit,
302+
max_age_ms: int | Omit = omit,
291303
shorten_base64_images: bool | Omit = omit,
292304
use_main_content_only: bool | Omit = omit,
293305
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -309,6 +321,10 @@ def web_scrape_md(
309321
310322
include_links: Preserve hyperlinks in Markdown output
311323
324+
max_age_ms: Return a cached result if a prior scrape for the same parameters exists and is
325+
younger than this many milliseconds. Defaults to 1 day (86400000 ms) when
326+
omitted. Set to 0 to always scrape fresh.
327+
312328
shorten_base64_images: Shorten base64-encoded image data in the Markdown output
313329
314330
use_main_content_only: Extract only the main content of the page, excluding headers, footers, sidebars,
@@ -334,6 +350,7 @@ def web_scrape_md(
334350
"url": url,
335351
"include_images": include_images,
336352
"include_links": include_links,
353+
"max_age_ms": max_age_ms,
337354
"shorten_base64_images": shorten_base64_images,
338355
"use_main_content_only": use_main_content_only,
339356
},
@@ -568,6 +585,7 @@ async def web_scrape_html(
568585
self,
569586
*,
570587
url: str,
588+
max_age_ms: int | Omit = omit,
571589
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
572590
# The extra values given here take precedence over values defined on the client or passed to this method.
573591
extra_headers: Headers | None = None,
@@ -581,6 +599,10 @@ async def web_scrape_html(
581599
Args:
582600
url: Full URL to scrape (must include http:// or https:// protocol)
583601
602+
max_age_ms: Return a cached result if a prior scrape for the same parameters exists and is
603+
younger than this many milliseconds. Defaults to 1 day (86400000 ms) when
604+
omitted. Set to 0 to always scrape fresh.
605+
584606
extra_headers: Send extra headers
585607
586608
extra_query: Add additional query parameters to the request
@@ -596,7 +618,13 @@ async def web_scrape_html(
596618
extra_query=extra_query,
597619
extra_body=extra_body,
598620
timeout=timeout,
599-
query=await async_maybe_transform({"url": url}, web_web_scrape_html_params.WebWebScrapeHTMLParams),
621+
query=await async_maybe_transform(
622+
{
623+
"url": url,
624+
"max_age_ms": max_age_ms,
625+
},
626+
web_web_scrape_html_params.WebWebScrapeHTMLParams,
627+
),
600628
),
601629
cast_to=WebWebScrapeHTMLResponse,
602630
)
@@ -647,6 +675,7 @@ async def web_scrape_md(
647675
url: str,
648676
include_images: bool | Omit = omit,
649677
include_links: bool | Omit = omit,
678+
max_age_ms: int | Omit = omit,
650679
shorten_base64_images: bool | Omit = omit,
651680
use_main_content_only: bool | Omit = omit,
652681
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -668,6 +697,10 @@ async def web_scrape_md(
668697
669698
include_links: Preserve hyperlinks in Markdown output
670699
700+
max_age_ms: Return a cached result if a prior scrape for the same parameters exists and is
701+
younger than this many milliseconds. Defaults to 1 day (86400000 ms) when
702+
omitted. Set to 0 to always scrape fresh.
703+
671704
shorten_base64_images: Shorten base64-encoded image data in the Markdown output
672705
673706
use_main_content_only: Extract only the main content of the page, excluding headers, footers, sidebars,
@@ -693,6 +726,7 @@ async def web_scrape_md(
693726
"url": url,
694727
"include_images": include_images,
695728
"include_links": include_links,
729+
"max_age_ms": max_age_ms,
696730
"shorten_base64_images": shorten_base64_images,
697731
"use_main_content_only": use_main_content_only,
698732
},

‎src/context/dev/types/web_web_scrape_html_params.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@
22

33
from __future__ import annotations
44

5-
from typing_extensions import Required, TypedDict
5+
from typing_extensions import Required, Annotated, TypedDict
6+
7+
from .._utils import PropertyInfo
68

79
__all__ = ["WebWebScrapeHTMLParams"]
810

911

1012
class WebWebScrapeHTMLParams(TypedDict, total=False):
1113
url: Required[str]
1214
"""Full URL to scrape (must include http:// or https:// protocol)"""
15+
16+
max_age_ms: Annotated[int, PropertyInfo(alias="maxAgeMs")]
17+
"""
18+
Return a cached result if a prior scrape for the same parameters exists and is
19+
younger than this many milliseconds. Defaults to 1 day (86400000 ms) when
20+
omitted. Set to 0 to always scrape fresh.
21+
"""

‎src/context/dev/types/web_web_scrape_md_params.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ class WebWebScrapeMdParams(TypedDict, total=False):
2222
include_links: Annotated[bool, PropertyInfo(alias="includeLinks")]
2323
"""Preserve hyperlinks in Markdown output"""
2424

25+
max_age_ms: Annotated[int, PropertyInfo(alias="maxAgeMs")]
26+
"""
27+
Return a cached result if a prior scrape for the same parameters exists and is
28+
younger than this many milliseconds. Defaults to 1 day (86400000 ms) when
29+
omitted. Set to 0 to always scrape fresh.
30+
"""
31+
2532
shorten_base64_images: Annotated[bool, PropertyInfo(alias="shortenBase64Images")]
2633
"""Shorten base64-encoded image data in the Markdown output"""
2734

‎tests/api_resources/test_web.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ def test_method_web_scrape_html(self, client: ContextDev) -> None:
122122
)
123123
assert_matches_type(WebWebScrapeHTMLResponse, web, path=["response"])
124124

125+
@pytest.mark.skip(reason="Mock server tests are disabled")
126+
@parametrize
127+
def test_method_web_scrape_html_with_all_params(self, client: ContextDev) -> None:
128+
web = client.web.web_scrape_html(
129+
url="https://example.com",
130+
max_age_ms=0,
131+
)
132+
assert_matches_type(WebWebScrapeHTMLResponse, web, path=["response"])
133+
125134
@pytest.mark.skip(reason="Mock server tests are disabled")
126135
@parametrize
127136
def test_raw_response_web_scrape_html(self, client: ContextDev) -> None:
@@ -197,6 +206,7 @@ def test_method_web_scrape_md_with_all_params(self, client: ContextDev) -> None:
197206
url="https://example.com",
198207
include_images=True,
199208
include_links=True,
209+
max_age_ms=0,
200210
shorten_base64_images=True,
201211
use_main_content_only=True,
202212
)
@@ -375,6 +385,15 @@ async def test_method_web_scrape_html(self, async_client: AsyncContextDev) -> No
375385
)
376386
assert_matches_type(WebWebScrapeHTMLResponse, web, path=["response"])
377387

388+
@pytest.mark.skip(reason="Mock server tests are disabled")
389+
@parametrize
390+
async def test_method_web_scrape_html_with_all_params(self, async_client: AsyncContextDev) -> None:
391+
web = await async_client.web.web_scrape_html(
392+
url="https://example.com",
393+
max_age_ms=0,
394+
)
395+
assert_matches_type(WebWebScrapeHTMLResponse, web, path=["response"])
396+
378397
@pytest.mark.skip(reason="Mock server tests are disabled")
379398
@parametrize
380399
async def test_raw_response_web_scrape_html(self, async_client: AsyncContextDev) -> None:
@@ -450,6 +469,7 @@ async def test_method_web_scrape_md_with_all_params(self, async_client: AsyncCon
450469
url="https://example.com",
451470
include_images=True,
452471
include_links=True,
472+
max_age_ms=0,
453473
shorten_base64_images=True,
454474
use_main_content_only=True,
455475
)

0 commit comments

Comments
 (0)