|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import TYPE_CHECKING, List, Union, Dict, Optional |
| 4 | +from ...types.sensitive_word_check import SensitiveWordCheckRequest |
| 5 | +from ...core import NOT_GIVEN, Body, Headers, NotGiven, BaseAPI, maybe_transform, StreamResponse, deepcopy_minimal |
| 6 | + |
| 7 | +import httpx |
| 8 | + |
| 9 | +from ...core import ( |
| 10 | + make_request_options, |
| 11 | +) |
| 12 | +import logging |
| 13 | + |
| 14 | +from ...types.web_search import web_search_create_params |
| 15 | +from ...types.web_search.web_search_resp import WebSearchResp |
| 16 | + |
| 17 | +logger = logging.getLogger(__name__) |
| 18 | + |
| 19 | +if TYPE_CHECKING: |
| 20 | + from ..._client import ZhipuAI |
| 21 | + |
| 22 | +__all__ = ["WebSearchApi"] |
| 23 | + |
| 24 | + |
| 25 | +class WebSearchApi(BaseAPI): |
| 26 | + def __init__(self, client: "ZhipuAI") -> None: |
| 27 | + super().__init__(client) |
| 28 | + |
| 29 | + def web_search( |
| 30 | + self, |
| 31 | + *, |
| 32 | + request_id: Optional[str] | NotGiven = NOT_GIVEN, |
| 33 | + search_engine: Optional[str] | NotGiven = NOT_GIVEN, |
| 34 | + search_query: Optional[str] | NotGiven = NOT_GIVEN, |
| 35 | + user_id: Optional[str] | NotGiven = NOT_GIVEN, |
| 36 | + sensitive_word_check: Optional[SensitiveWordCheckRequest] | NotGiven = NOT_GIVEN, |
| 37 | + extra_headers: Headers | None = None, |
| 38 | + extra_body: Body | None = None, |
| 39 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 40 | + ) -> WebSearchResp: |
| 41 | + |
| 42 | + body = deepcopy_minimal( |
| 43 | + { |
| 44 | + "request_id": request_id, |
| 45 | + "search_engine": search_engine, |
| 46 | + "search_query": search_query, |
| 47 | + "user_id": user_id, |
| 48 | + "sensitive_word_check": sensitive_word_check |
| 49 | + }) |
| 50 | + return self._post( |
| 51 | + "/web_search", |
| 52 | + body= maybe_transform(body, web_search_create_params.WebSearchCreatParams), |
| 53 | + options=make_request_options( |
| 54 | + extra_headers=extra_headers, extra_body=extra_body, timeout=timeout |
| 55 | + ), |
| 56 | + cast_type=WebSearchResp |
| 57 | + ) |
0 commit comments