Search the web for a query.
(
self,
query: str,
*,
max_results: int | None = None,
include_domains: list[str] | None = None,
exclude_domains: list[str] | None = None,
)
| 92 | self.include_answer = include_answer |
| 93 | |
| 94 | def search( |
| 95 | self, |
| 96 | query: str, |
| 97 | *, |
| 98 | max_results: int | None = None, |
| 99 | include_domains: list[str] | None = None, |
| 100 | exclude_domains: list[str] | None = None, |
| 101 | ) -> WebSearchResponse: |
| 102 | """Search the web for a query.""" |
| 103 | limit = max_results or self.max_results |
| 104 | t0 = time.monotonic() |
| 105 | |
| 106 | # Tavily is the primary engine |
| 107 | if self.api_key: |
| 108 | try: |
| 109 | return self._search_tavily(query, limit, include_domains, exclude_domains, t0) |
| 110 | except Exception as exc: # noqa: BLE001 |
| 111 | logger.warning("Tavily search failed, falling back to DuckDuckGo: %s", exc) |
| 112 | |
| 113 | return self._search_duckduckgo(query, limit, t0) |
| 114 | |
| 115 | def search_multi( |
| 116 | self, |