|
9 | 9 |
|
10 | 10 | from ..types import ( |
11 | 11 | web_search_params, |
| 12 | + web_answers_params, |
12 | 13 | web_extract_params, |
13 | 14 | web_screenshot_params, |
14 | 15 | web_web_crawl_md_params, |
|
32 | 33 | ) |
33 | 34 | from .._base_client import make_request_options |
34 | 35 | from ..types.web_search_response import WebSearchResponse |
| 36 | +from ..types.web_answers_response import WebAnswersResponse |
35 | 37 | from ..types.web_extract_response import WebExtractResponse |
36 | 38 | from ..types.web_screenshot_response import WebScreenshotResponse |
37 | 39 | from ..types.web_web_crawl_md_response import WebWebCrawlMdResponse |
@@ -66,6 +68,73 @@ def with_streaming_response(self) -> WebResourceWithStreamingResponse: |
66 | 68 | """ |
67 | 69 | return WebResourceWithStreamingResponse(self) |
68 | 70 |
|
| 71 | + def answers( |
| 72 | + self, |
| 73 | + *, |
| 74 | + task: str, |
| 75 | + json_format: Dict[str, object] | Omit = omit, |
| 76 | + mode: Literal["fast", "ultra"] | Omit = omit, |
| 77 | + tags: SequenceNotStr[str] | Omit = omit, |
| 78 | + timeout_ms: int | Omit = omit, |
| 79 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 80 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 81 | + extra_headers: Headers | None = None, |
| 82 | + extra_query: Query | None = None, |
| 83 | + extra_body: Body | None = None, |
| 84 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 85 | + ) -> WebAnswersResponse: |
| 86 | + """ |
| 87 | + Researches the live web and returns a sourced answer in your requested JSON |
| 88 | + shape. Select fast for a smaller research budget at 10 credits or ultra for |
| 89 | + deeper reasoning at 100 credits. Defaults to ultra. Fast research is limited to |
| 90 | + 30 seconds and ultra to 50 seconds; timeoutMS can shorten either deadline. |
| 91 | +
|
| 92 | + Args: |
| 93 | + task: What to research and answer, in plain language. Naming a domain in the task (for |
| 94 | + example "pricing on context.dev") makes the agent read that site before it |
| 95 | + searches. |
| 96 | +
|
| 97 | + json_format: An example object with placeholder values (for example {"pricing_page_url": "", |
| 98 | + "plans": [{"name": "", "price": 0}]}). Object keys and value types are |
| 99 | + preserved; unknown values may be null. Empty arrays accept any JSON items. |
| 100 | + Defaults to {"result": ""}. Maximum 8 levels, 500 values, and 16000 characters. |
| 101 | +
|
| 102 | + mode: Research level: fast uses a smaller model and research budget for 10 credits; |
| 103 | + ultra uses deeper reasoning and research for 100 credits. Defaults to ultra. |
| 104 | + Only successful requests consume credits. |
| 105 | +
|
| 106 | + tags: Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters. |
| 107 | +
|
| 108 | + timeout_ms: Optional timeout in milliseconds for the request. If the request takes longer |
| 109 | + than this value, it will be aborted with a 408 status code. Maximum allowed |
| 110 | + value is 300000ms (5 minutes). |
| 111 | +
|
| 112 | + extra_headers: Send extra headers |
| 113 | +
|
| 114 | + extra_query: Add additional query parameters to the request |
| 115 | +
|
| 116 | + extra_body: Add additional JSON properties to the request |
| 117 | +
|
| 118 | + timeout: Override the client-level default timeout for this request, in seconds |
| 119 | + """ |
| 120 | + return self._post( |
| 121 | + "/web/answers", |
| 122 | + body=maybe_transform( |
| 123 | + { |
| 124 | + "task": task, |
| 125 | + "json_format": json_format, |
| 126 | + "mode": mode, |
| 127 | + "tags": tags, |
| 128 | + "timeout_ms": timeout_ms, |
| 129 | + }, |
| 130 | + web_answers_params.WebAnswersParams, |
| 131 | + ), |
| 132 | + options=make_request_options( |
| 133 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 134 | + ), |
| 135 | + cast_to=WebAnswersResponse, |
| 136 | + ) |
| 137 | + |
69 | 138 | def extract( |
70 | 139 | self, |
71 | 140 | *, |
@@ -2321,6 +2390,73 @@ def with_streaming_response(self) -> AsyncWebResourceWithStreamingResponse: |
2321 | 2390 | """ |
2322 | 2391 | return AsyncWebResourceWithStreamingResponse(self) |
2323 | 2392 |
|
| 2393 | + async def answers( |
| 2394 | + self, |
| 2395 | + *, |
| 2396 | + task: str, |
| 2397 | + json_format: Dict[str, object] | Omit = omit, |
| 2398 | + mode: Literal["fast", "ultra"] | Omit = omit, |
| 2399 | + tags: SequenceNotStr[str] | Omit = omit, |
| 2400 | + timeout_ms: int | Omit = omit, |
| 2401 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 2402 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 2403 | + extra_headers: Headers | None = None, |
| 2404 | + extra_query: Query | None = None, |
| 2405 | + extra_body: Body | None = None, |
| 2406 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 2407 | + ) -> WebAnswersResponse: |
| 2408 | + """ |
| 2409 | + Researches the live web and returns a sourced answer in your requested JSON |
| 2410 | + shape. Select fast for a smaller research budget at 10 credits or ultra for |
| 2411 | + deeper reasoning at 100 credits. Defaults to ultra. Fast research is limited to |
| 2412 | + 30 seconds and ultra to 50 seconds; timeoutMS can shorten either deadline. |
| 2413 | +
|
| 2414 | + Args: |
| 2415 | + task: What to research and answer, in plain language. Naming a domain in the task (for |
| 2416 | + example "pricing on context.dev") makes the agent read that site before it |
| 2417 | + searches. |
| 2418 | +
|
| 2419 | + json_format: An example object with placeholder values (for example {"pricing_page_url": "", |
| 2420 | + "plans": [{"name": "", "price": 0}]}). Object keys and value types are |
| 2421 | + preserved; unknown values may be null. Empty arrays accept any JSON items. |
| 2422 | + Defaults to {"result": ""}. Maximum 8 levels, 500 values, and 16000 characters. |
| 2423 | +
|
| 2424 | + mode: Research level: fast uses a smaller model and research budget for 10 credits; |
| 2425 | + ultra uses deeper reasoning and research for 100 credits. Defaults to ultra. |
| 2426 | + Only successful requests consume credits. |
| 2427 | +
|
| 2428 | + tags: Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters. |
| 2429 | +
|
| 2430 | + timeout_ms: Optional timeout in milliseconds for the request. If the request takes longer |
| 2431 | + than this value, it will be aborted with a 408 status code. Maximum allowed |
| 2432 | + value is 300000ms (5 minutes). |
| 2433 | +
|
| 2434 | + extra_headers: Send extra headers |
| 2435 | +
|
| 2436 | + extra_query: Add additional query parameters to the request |
| 2437 | +
|
| 2438 | + extra_body: Add additional JSON properties to the request |
| 2439 | +
|
| 2440 | + timeout: Override the client-level default timeout for this request, in seconds |
| 2441 | + """ |
| 2442 | + return await self._post( |
| 2443 | + "/web/answers", |
| 2444 | + body=await async_maybe_transform( |
| 2445 | + { |
| 2446 | + "task": task, |
| 2447 | + "json_format": json_format, |
| 2448 | + "mode": mode, |
| 2449 | + "tags": tags, |
| 2450 | + "timeout_ms": timeout_ms, |
| 2451 | + }, |
| 2452 | + web_answers_params.WebAnswersParams, |
| 2453 | + ), |
| 2454 | + options=make_request_options( |
| 2455 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 2456 | + ), |
| 2457 | + cast_to=WebAnswersResponse, |
| 2458 | + ) |
| 2459 | + |
2324 | 2460 | async def extract( |
2325 | 2461 | self, |
2326 | 2462 | *, |
@@ -4560,6 +4696,9 @@ class WebResourceWithRawResponse: |
4560 | 4696 | def __init__(self, web: WebResource) -> None: |
4561 | 4697 | self._web = web |
4562 | 4698 |
|
| 4699 | + self.answers = to_raw_response_wrapper( |
| 4700 | + web.answers, |
| 4701 | + ) |
4563 | 4702 | self.extract = to_raw_response_wrapper( |
4564 | 4703 | web.extract, |
4565 | 4704 | ) |
@@ -4599,6 +4738,9 @@ class AsyncWebResourceWithRawResponse: |
4599 | 4738 | def __init__(self, web: AsyncWebResource) -> None: |
4600 | 4739 | self._web = web |
4601 | 4740 |
|
| 4741 | + self.answers = async_to_raw_response_wrapper( |
| 4742 | + web.answers, |
| 4743 | + ) |
4602 | 4744 | self.extract = async_to_raw_response_wrapper( |
4603 | 4745 | web.extract, |
4604 | 4746 | ) |
@@ -4638,6 +4780,9 @@ class WebResourceWithStreamingResponse: |
4638 | 4780 | def __init__(self, web: WebResource) -> None: |
4639 | 4781 | self._web = web |
4640 | 4782 |
|
| 4783 | + self.answers = to_streamed_response_wrapper( |
| 4784 | + web.answers, |
| 4785 | + ) |
4641 | 4786 | self.extract = to_streamed_response_wrapper( |
4642 | 4787 | web.extract, |
4643 | 4788 | ) |
@@ -4677,6 +4822,9 @@ class AsyncWebResourceWithStreamingResponse: |
4677 | 4822 | def __init__(self, web: AsyncWebResource) -> None: |
4678 | 4823 | self._web = web |
4679 | 4824 |
|
| 4825 | + self.answers = async_to_streamed_response_wrapper( |
| 4826 | + web.answers, |
| 4827 | + ) |
4680 | 4828 | self.extract = async_to_streamed_response_wrapper( |
4681 | 4829 | web.extract, |
4682 | 4830 | ) |
|
0 commit comments