Spaces:
Sleeping
Sleeping
| from typing import List | |
| from tavily import TavilyClient | |
| def gather_research(tavily_client: TavilyClient, queries: List[str], num_results: int) -> List[dict]: | |
| """ | |
| Gathers research from Tavily for a list of queries. | |
| """ | |
| research_with_sources = [] | |
| print(f"-> Gathering research for {len(queries)} queries (max {num_results} results each)...") | |
| for query in queries: | |
| try: | |
| response = tavily_client.search(query=query, search_depth="advanced", max_results=num_results, include_raw_content=True) | |
| for result in response['results']: | |
| if result.get('content') and result.get('url'): | |
| research_with_sources.append({"content": result['content'], "source": result['url']}) | |
| except Exception as e: | |
| print(f"Tavily search failed for '{query}': {e}") | |
| return research_with_sources | |