File size: 894 Bytes
20d3dd7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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