Skip to content

Commit 1ebc67e

Browse files
feat(api): manual updates
1 parent e9362a9 commit 1ebc67e

8 files changed

Lines changed: 499 additions & 6 deletions

File tree

‎.stats.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 23
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-841485e0c95c9b59f227e6af45c74a87b58ef6a2a1de3c13f8d32b6531ed02bb.yml
1+
configured_endpoints: 24
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-cc8ca2c80e73bdcff491c96d9289c9e88d831215375ef83632cc51f8e8e06183.yml
33
openapi_spec_hash: bf55dce481efcf2f24bc9ff59c2e3f61
4-
config_hash: 993819587f2f738bb857f351f32a9e7f
4+
config_hash: cf2c7f48b329e0a61612b30cd2755ad1

‎README.md‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,17 @@ from context.dev import ContextDev
130130

131131
client = ContextDev()
132132

133-
response = client.web.screenshot(
134-
viewport={},
133+
response = client.web.extract(
134+
schema={
135+
"type": "bar",
136+
"properties": "bar",
137+
"required": "bar",
138+
"additionalProperties": "bar",
139+
},
140+
url="https://example.com",
141+
pdf={},
135142
)
136-
print(response.viewport)
143+
print(response.pdf)
137144
```
138145

139146
## Handling errors

‎api.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Types:
44

55
```python
66
from context.dev.types import (
7+
WebExtractResponse,
78
WebExtractFontsResponse,
89
WebExtractStyleguideResponse,
910
WebScreenshotResponse,
@@ -18,6 +19,7 @@ from context.dev.types import (
1819

1920
Methods:
2021

22+
- <code title="post /web/extract">client.web.<a href="./src/context/dev/resources/web.py">extract</a>(\*\*<a href="src/context/dev/types/web_extract_params.py">params</a>) -> <a href="./src/context/dev/types/web_extract_response.py">WebExtractResponse</a></code>
2123
- <code title="get /web/fonts">client.web.<a href="./src/context/dev/resources/web.py">extract_fonts</a>(\*\*<a href="src/context/dev/types/web_extract_fonts_params.py">params</a>) -> <a href="./src/context/dev/types/web_extract_fonts_response.py">WebExtractFontsResponse</a></code>
2224
- <code title="get /web/styleguide">client.web.<a href="./src/context/dev/resources/web.py">extract_styleguide</a>(\*\*<a href="src/context/dev/types/web_extract_styleguide_params.py">params</a>) -> <a href="./src/context/dev/types/web_extract_styleguide_response.py">WebExtractStyleguideResponse</a></code>
2325
- <code title="get /web/screenshot">client.web.<a href="./src/context/dev/resources/web.py">screenshot</a>(\*\*<a href="src/context/dev/types/web_screenshot_params.py">params</a>) -> <a href="./src/context/dev/types/web_screenshot_response.py">WebScreenshotResponse</a></code>

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

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
from __future__ import annotations
44

5+
from typing import Dict
56
from typing_extensions import Literal
67

78
import httpx
89

910
from ..types import (
1011
web_search_params,
12+
web_extract_params,
1113
web_screenshot_params,
1214
web_web_crawl_md_params,
1315
web_extract_fonts_params,
@@ -29,6 +31,7 @@
2931
)
3032
from .._base_client import make_request_options
3133
from ..types.web_search_response import WebSearchResponse
34+
from ..types.web_extract_response import WebExtractResponse
3235
from ..types.web_screenshot_response import WebScreenshotResponse
3336
from ..types.web_web_crawl_md_response import WebWebCrawlMdResponse
3437
from ..types.web_extract_fonts_response import WebExtractFontsResponse
@@ -61,6 +64,99 @@ def with_streaming_response(self) -> WebResourceWithStreamingResponse:
6164
"""
6265
return WebResourceWithStreamingResponse(self)
6366

67+
def extract(
68+
self,
69+
*,
70+
schema: Dict[str, object],
71+
url: str,
72+
fact_check: bool | Omit = omit,
73+
follow_subdomains: bool | Omit = omit,
74+
include_frames: bool | Omit = omit,
75+
instructions: str | Omit = omit,
76+
max_age_ms: int | Omit = omit,
77+
pdf: web_extract_params.Pdf | Omit = omit,
78+
stop_after_ms: int | Omit = omit,
79+
timeout_ms: int | Omit = omit,
80+
wait_for_ms: int | Omit = omit,
81+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
82+
# The extra values given here take precedence over values defined on the client or passed to this method.
83+
extra_headers: Headers | None = None,
84+
extra_query: Query | None = None,
85+
extra_body: Body | None = None,
86+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
87+
) -> WebExtractResponse:
88+
"""
89+
Crawl a website, convert pages to Markdown using the scrape cache, and extract
90+
structured data into the provided JSON Schema. The schema must describe the
91+
response data object. This endpoint does not accept targeted page-type
92+
selection.
93+
94+
Args:
95+
schema: JSON Schema for the returned data object. TypeScript Zod users can pass a JSON
96+
Schema generated from a Zod object; Python users can pass the equivalent JSON
97+
Schema object.
98+
99+
url: The starting website URL to crawl and extract from. Must include http:// or
100+
https://.
101+
102+
fact_check: When true (default), every returned value must be grounded in facts stated on
103+
the page; fields that cannot be supported by the page are returned as
104+
null/empty. When false, the model may make reasonable inferences and derivations
105+
from the page content (e.g. ideal customer, competitor analysis,
106+
recommendations) while keeping verifiable specifics (names, quotes, URLs, dates,
107+
metrics) faithful to the source.
108+
109+
follow_subdomains: When true, follow links on subdomains of the starting URL's domain.
110+
111+
include_frames: When true, iframe contents are included in Markdown before extraction.
112+
113+
instructions: Optional extraction guidance, such as which facts to prioritize or how to
114+
interpret fields in the schema.
115+
116+
max_age_ms: Return cached scrape results if a prior scrape for the same parameters is
117+
younger than this many milliseconds.
118+
119+
stop_after_ms: Soft time budget for the crawl in milliseconds.
120+
121+
timeout_ms: Optional timeout in milliseconds for the request. If the request takes longer
122+
than this value, it will be aborted with a 408 status code. Maximum allowed
123+
value is 300000ms (5 minutes).
124+
125+
wait_for_ms: Optional browser wait time in milliseconds after initial page load for each
126+
crawled page.
127+
128+
extra_headers: Send extra headers
129+
130+
extra_query: Add additional query parameters to the request
131+
132+
extra_body: Add additional JSON properties to the request
133+
134+
timeout: Override the client-level default timeout for this request, in seconds
135+
"""
136+
return self._post(
137+
"/web/extract",
138+
body=maybe_transform(
139+
{
140+
"schema": schema,
141+
"url": url,
142+
"fact_check": fact_check,
143+
"follow_subdomains": follow_subdomains,
144+
"include_frames": include_frames,
145+
"instructions": instructions,
146+
"max_age_ms": max_age_ms,
147+
"pdf": pdf,
148+
"stop_after_ms": stop_after_ms,
149+
"timeout_ms": timeout_ms,
150+
"wait_for_ms": wait_for_ms,
151+
},
152+
web_extract_params.WebExtractParams,
153+
),
154+
options=make_request_options(
155+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
156+
),
157+
cast_to=WebExtractResponse,
158+
)
159+
64160
def extract_fonts(
65161
self,
66162
*,
@@ -758,6 +854,99 @@ def with_streaming_response(self) -> AsyncWebResourceWithStreamingResponse:
758854
"""
759855
return AsyncWebResourceWithStreamingResponse(self)
760856

857+
async def extract(
858+
self,
859+
*,
860+
schema: Dict[str, object],
861+
url: str,
862+
fact_check: bool | Omit = omit,
863+
follow_subdomains: bool | Omit = omit,
864+
include_frames: bool | Omit = omit,
865+
instructions: str | Omit = omit,
866+
max_age_ms: int | Omit = omit,
867+
pdf: web_extract_params.Pdf | Omit = omit,
868+
stop_after_ms: int | Omit = omit,
869+
timeout_ms: int | Omit = omit,
870+
wait_for_ms: int | Omit = omit,
871+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
872+
# The extra values given here take precedence over values defined on the client or passed to this method.
873+
extra_headers: Headers | None = None,
874+
extra_query: Query | None = None,
875+
extra_body: Body | None = None,
876+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
877+
) -> WebExtractResponse:
878+
"""
879+
Crawl a website, convert pages to Markdown using the scrape cache, and extract
880+
structured data into the provided JSON Schema. The schema must describe the
881+
response data object. This endpoint does not accept targeted page-type
882+
selection.
883+
884+
Args:
885+
schema: JSON Schema for the returned data object. TypeScript Zod users can pass a JSON
886+
Schema generated from a Zod object; Python users can pass the equivalent JSON
887+
Schema object.
888+
889+
url: The starting website URL to crawl and extract from. Must include http:// or
890+
https://.
891+
892+
fact_check: When true (default), every returned value must be grounded in facts stated on
893+
the page; fields that cannot be supported by the page are returned as
894+
null/empty. When false, the model may make reasonable inferences and derivations
895+
from the page content (e.g. ideal customer, competitor analysis,
896+
recommendations) while keeping verifiable specifics (names, quotes, URLs, dates,
897+
metrics) faithful to the source.
898+
899+
follow_subdomains: When true, follow links on subdomains of the starting URL's domain.
900+
901+
include_frames: When true, iframe contents are included in Markdown before extraction.
902+
903+
instructions: Optional extraction guidance, such as which facts to prioritize or how to
904+
interpret fields in the schema.
905+
906+
max_age_ms: Return cached scrape results if a prior scrape for the same parameters is
907+
younger than this many milliseconds.
908+
909+
stop_after_ms: Soft time budget for the crawl in milliseconds.
910+
911+
timeout_ms: Optional timeout in milliseconds for the request. If the request takes longer
912+
than this value, it will be aborted with a 408 status code. Maximum allowed
913+
value is 300000ms (5 minutes).
914+
915+
wait_for_ms: Optional browser wait time in milliseconds after initial page load for each
916+
crawled page.
917+
918+
extra_headers: Send extra headers
919+
920+
extra_query: Add additional query parameters to the request
921+
922+
extra_body: Add additional JSON properties to the request
923+
924+
timeout: Override the client-level default timeout for this request, in seconds
925+
"""
926+
return await self._post(
927+
"/web/extract",
928+
body=await async_maybe_transform(
929+
{
930+
"schema": schema,
931+
"url": url,
932+
"fact_check": fact_check,
933+
"follow_subdomains": follow_subdomains,
934+
"include_frames": include_frames,
935+
"instructions": instructions,
936+
"max_age_ms": max_age_ms,
937+
"pdf": pdf,
938+
"stop_after_ms": stop_after_ms,
939+
"timeout_ms": timeout_ms,
940+
"wait_for_ms": wait_for_ms,
941+
},
942+
web_extract_params.WebExtractParams,
943+
),
944+
options=make_request_options(
945+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
946+
),
947+
cast_to=WebExtractResponse,
948+
)
949+
761950
async def extract_fonts(
762951
self,
763952
*,
@@ -1439,6 +1628,9 @@ class WebResourceWithRawResponse:
14391628
def __init__(self, web: WebResource) -> None:
14401629
self._web = web
14411630

1631+
self.extract = to_raw_response_wrapper(
1632+
web.extract,
1633+
)
14421634
self.extract_fonts = to_raw_response_wrapper(
14431635
web.extract_fonts,
14441636
)
@@ -1472,6 +1664,9 @@ class AsyncWebResourceWithRawResponse:
14721664
def __init__(self, web: AsyncWebResource) -> None:
14731665
self._web = web
14741666

1667+
self.extract = async_to_raw_response_wrapper(
1668+
web.extract,
1669+
)
14751670
self.extract_fonts = async_to_raw_response_wrapper(
14761671
web.extract_fonts,
14771672
)
@@ -1505,6 +1700,9 @@ class WebResourceWithStreamingResponse:
15051700
def __init__(self, web: WebResource) -> None:
15061701
self._web = web
15071702

1703+
self.extract = to_streamed_response_wrapper(
1704+
web.extract,
1705+
)
15081706
self.extract_fonts = to_streamed_response_wrapper(
15091707
web.extract_fonts,
15101708
)
@@ -1538,6 +1736,9 @@ class AsyncWebResourceWithStreamingResponse:
15381736
def __init__(self, web: AsyncWebResource) -> None:
15391737
self._web = web
15401738

1739+
self.extract = async_to_streamed_response_wrapper(
1740+
web.extract,
1741+
)
15411742
self.extract_fonts = async_to_streamed_response_wrapper(
15421743
web.extract_fonts,
15431744
)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
from .web_search_params import WebSearchParams as WebSearchParams
66
from .ai_ai_query_params import AIAIQueryParams as AIAIQueryParams
7+
from .web_extract_params import WebExtractParams as WebExtractParams
78
from .web_search_response import WebSearchResponse as WebSearchResponse
89
from .ai_ai_query_response import AIAIQueryResponse as AIAIQueryResponse
10+
from .web_extract_response import WebExtractResponse as WebExtractResponse
911
from .brand_retrieve_params import BrandRetrieveParams as BrandRetrieveParams
1012
from .web_screenshot_params import WebScreenshotParams as WebScreenshotParams
1113
from .brand_retrieve_response import BrandRetrieveResponse as BrandRetrieveResponse

0 commit comments

Comments
 (0)