|
7 | 7 | import httpx |
8 | 8 |
|
9 | 9 | from ..types import ( |
| 10 | + web_search_params, |
10 | 11 | web_screenshot_params, |
11 | 12 | web_web_crawl_md_params, |
12 | 13 | web_extract_fonts_params, |
|
16 | 17 | web_extract_styleguide_params, |
17 | 18 | web_web_scrape_sitemap_params, |
18 | 19 | ) |
19 | | -from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given |
| 20 | +from .._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given |
20 | 21 | from .._utils import maybe_transform, async_maybe_transform |
21 | 22 | from .._compat import cached_property |
22 | 23 | from .._resource import SyncAPIResource, AsyncAPIResource |
|
27 | 28 | async_to_streamed_response_wrapper, |
28 | 29 | ) |
29 | 30 | from .._base_client import make_request_options |
| 31 | +from ..types.web_search_response import WebSearchResponse |
30 | 32 | from ..types.web_screenshot_response import WebScreenshotResponse |
31 | 33 | from ..types.web_web_crawl_md_response import WebWebCrawlMdResponse |
32 | 34 | from ..types.web_extract_fonts_response import WebExtractFontsResponse |
@@ -266,6 +268,73 @@ def screenshot( |
266 | 268 | cast_to=WebScreenshotResponse, |
267 | 269 | ) |
268 | 270 |
|
| 271 | + def search( |
| 272 | + self, |
| 273 | + *, |
| 274 | + query: str, |
| 275 | + exclude_domains: SequenceNotStr[str] | Omit = omit, |
| 276 | + freshness: Literal["last_24_hours", "last_week", "last_month", "last_year"] | Omit = omit, |
| 277 | + include_domains: SequenceNotStr[str] | Omit = omit, |
| 278 | + markdown_options: web_search_params.MarkdownOptions | Omit = omit, |
| 279 | + query_fanout: bool | Omit = omit, |
| 280 | + timeout_ms: int | Omit = omit, |
| 281 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 282 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 283 | + extra_headers: Headers | None = None, |
| 284 | + extra_query: Query | None = None, |
| 285 | + extra_body: Body | None = None, |
| 286 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 287 | + ) -> WebSearchResponse: |
| 288 | + """ |
| 289 | + Search the web and optionally scrape each result to Markdown in one round-trip. |
| 290 | +
|
| 291 | + Args: |
| 292 | + query: Natural-language search query. |
| 293 | +
|
| 294 | + exclude_domains: Blocklist — drop results from these domains. Example: ["pinterest.com", |
| 295 | + "reddit.com"]. |
| 296 | +
|
| 297 | + freshness: Restrict results to content published within this window. |
| 298 | +
|
| 299 | + include_domains: Allowlist — only return results from these domains. Example: ["arxiv.org", |
| 300 | + "github.com"]. |
| 301 | +
|
| 302 | + markdown_options: Inline Markdown scraping for each result. Set `enabled: true` to activate. |
| 303 | +
|
| 304 | + query_fanout: Expand the query into multiple parallel variants for broader recall. |
| 305 | +
|
| 306 | + timeout_ms: Optional timeout in milliseconds for the request. If the request takes longer |
| 307 | + than this value, it will be aborted with a 408 status code. Maximum allowed |
| 308 | + value is 300000ms (5 minutes). |
| 309 | +
|
| 310 | + extra_headers: Send extra headers |
| 311 | +
|
| 312 | + extra_query: Add additional query parameters to the request |
| 313 | +
|
| 314 | + extra_body: Add additional JSON properties to the request |
| 315 | +
|
| 316 | + timeout: Override the client-level default timeout for this request, in seconds |
| 317 | + """ |
| 318 | + return self._post( |
| 319 | + "/web/search", |
| 320 | + body=maybe_transform( |
| 321 | + { |
| 322 | + "query": query, |
| 323 | + "exclude_domains": exclude_domains, |
| 324 | + "freshness": freshness, |
| 325 | + "include_domains": include_domains, |
| 326 | + "markdown_options": markdown_options, |
| 327 | + "query_fanout": query_fanout, |
| 328 | + "timeout_ms": timeout_ms, |
| 329 | + }, |
| 330 | + web_search_params.WebSearchParams, |
| 331 | + ), |
| 332 | + options=make_request_options( |
| 333 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 334 | + ), |
| 335 | + cast_to=WebSearchResponse, |
| 336 | + ) |
| 337 | + |
269 | 338 | def web_crawl_md( |
270 | 339 | self, |
271 | 340 | *, |
@@ -882,6 +951,73 @@ async def screenshot( |
882 | 951 | cast_to=WebScreenshotResponse, |
883 | 952 | ) |
884 | 953 |
|
| 954 | + async def search( |
| 955 | + self, |
| 956 | + *, |
| 957 | + query: str, |
| 958 | + exclude_domains: SequenceNotStr[str] | Omit = omit, |
| 959 | + freshness: Literal["last_24_hours", "last_week", "last_month", "last_year"] | Omit = omit, |
| 960 | + include_domains: SequenceNotStr[str] | Omit = omit, |
| 961 | + markdown_options: web_search_params.MarkdownOptions | Omit = omit, |
| 962 | + query_fanout: bool | Omit = omit, |
| 963 | + timeout_ms: int | Omit = omit, |
| 964 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 965 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 966 | + extra_headers: Headers | None = None, |
| 967 | + extra_query: Query | None = None, |
| 968 | + extra_body: Body | None = None, |
| 969 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 970 | + ) -> WebSearchResponse: |
| 971 | + """ |
| 972 | + Search the web and optionally scrape each result to Markdown in one round-trip. |
| 973 | +
|
| 974 | + Args: |
| 975 | + query: Natural-language search query. |
| 976 | +
|
| 977 | + exclude_domains: Blocklist — drop results from these domains. Example: ["pinterest.com", |
| 978 | + "reddit.com"]. |
| 979 | +
|
| 980 | + freshness: Restrict results to content published within this window. |
| 981 | +
|
| 982 | + include_domains: Allowlist — only return results from these domains. Example: ["arxiv.org", |
| 983 | + "github.com"]. |
| 984 | +
|
| 985 | + markdown_options: Inline Markdown scraping for each result. Set `enabled: true` to activate. |
| 986 | +
|
| 987 | + query_fanout: Expand the query into multiple parallel variants for broader recall. |
| 988 | +
|
| 989 | + timeout_ms: Optional timeout in milliseconds for the request. If the request takes longer |
| 990 | + than this value, it will be aborted with a 408 status code. Maximum allowed |
| 991 | + value is 300000ms (5 minutes). |
| 992 | +
|
| 993 | + extra_headers: Send extra headers |
| 994 | +
|
| 995 | + extra_query: Add additional query parameters to the request |
| 996 | +
|
| 997 | + extra_body: Add additional JSON properties to the request |
| 998 | +
|
| 999 | + timeout: Override the client-level default timeout for this request, in seconds |
| 1000 | + """ |
| 1001 | + return await self._post( |
| 1002 | + "/web/search", |
| 1003 | + body=await async_maybe_transform( |
| 1004 | + { |
| 1005 | + "query": query, |
| 1006 | + "exclude_domains": exclude_domains, |
| 1007 | + "freshness": freshness, |
| 1008 | + "include_domains": include_domains, |
| 1009 | + "markdown_options": markdown_options, |
| 1010 | + "query_fanout": query_fanout, |
| 1011 | + "timeout_ms": timeout_ms, |
| 1012 | + }, |
| 1013 | + web_search_params.WebSearchParams, |
| 1014 | + ), |
| 1015 | + options=make_request_options( |
| 1016 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 1017 | + ), |
| 1018 | + cast_to=WebSearchResponse, |
| 1019 | + ) |
| 1020 | + |
885 | 1021 | async def web_crawl_md( |
886 | 1022 | self, |
887 | 1023 | *, |
@@ -1284,6 +1420,9 @@ def __init__(self, web: WebResource) -> None: |
1284 | 1420 | self.screenshot = to_raw_response_wrapper( |
1285 | 1421 | web.screenshot, |
1286 | 1422 | ) |
| 1423 | + self.search = to_raw_response_wrapper( |
| 1424 | + web.search, |
| 1425 | + ) |
1287 | 1426 | self.web_crawl_md = to_raw_response_wrapper( |
1288 | 1427 | web.web_crawl_md, |
1289 | 1428 | ) |
@@ -1314,6 +1453,9 @@ def __init__(self, web: AsyncWebResource) -> None: |
1314 | 1453 | self.screenshot = async_to_raw_response_wrapper( |
1315 | 1454 | web.screenshot, |
1316 | 1455 | ) |
| 1456 | + self.search = async_to_raw_response_wrapper( |
| 1457 | + web.search, |
| 1458 | + ) |
1317 | 1459 | self.web_crawl_md = async_to_raw_response_wrapper( |
1318 | 1460 | web.web_crawl_md, |
1319 | 1461 | ) |
@@ -1344,6 +1486,9 @@ def __init__(self, web: WebResource) -> None: |
1344 | 1486 | self.screenshot = to_streamed_response_wrapper( |
1345 | 1487 | web.screenshot, |
1346 | 1488 | ) |
| 1489 | + self.search = to_streamed_response_wrapper( |
| 1490 | + web.search, |
| 1491 | + ) |
1347 | 1492 | self.web_crawl_md = to_streamed_response_wrapper( |
1348 | 1493 | web.web_crawl_md, |
1349 | 1494 | ) |
@@ -1374,6 +1519,9 @@ def __init__(self, web: AsyncWebResource) -> None: |
1374 | 1519 | self.screenshot = async_to_streamed_response_wrapper( |
1375 | 1520 | web.screenshot, |
1376 | 1521 | ) |
| 1522 | + self.search = async_to_streamed_response_wrapper( |
| 1523 | + web.search, |
| 1524 | + ) |
1377 | 1525 | self.web_crawl_md = async_to_streamed_response_wrapper( |
1378 | 1526 | web.web_crawl_md, |
1379 | 1527 | ) |
|
0 commit comments