[docs]classJinaSearchAPIWrapper(BaseModel):"""Wrapper around the Jina search engine."""base_url:str="https://s.jina.ai/""""The base URL for the Jina search engine."""
[docs]defrun(self,query:str)->str:"""Query the Jina search engine and return the results as a JSON string. Args: query: The query to search for. Returns: The results as a JSON string. """web_search_results=self._search_request(query=query)final_results=[{"title":item.get("title"),"link":item.get("url"),"snippet":item.get("description"),"content":item.get("content"),}foriteminweb_search_results]returnjson.dumps(final_results)
[docs]defdownload_documents(self,query:str)->List[Document]:"""Query the Jina search engine and return the results as a list of Documents. Args: query: The query to search for. Returns: The results as a list of Documents. """results=self._search_request(query)return[Document(page_content=item.get("content"),# type: ignore[arg-type]metadata={"title":item.get("title"),"link":item.get("url"),"description":item.get("description"),},)foriteminresults]