File size: 604 Bytes
a6e3889
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""Tavily web search wrapper."""
from tavily import TavilyClient
import config


def search(query: str, max_results: int = 5) -> str:
    """Search the web and return a formatted markdown string."""
    client = TavilyClient(api_key=config.TAVILY_API_KEY)
    resp   = client.search(query, max_results=max_results)

    lines = [f"**Query:** {query}\n"]
    for r in resp.get("results", []):
        lines.append(f"### {r.get('title', 'No title')}")
        lines.append(f"URL: {r.get('url', '')}")
        lines.append(r.get("content", "").strip())
        lines.append("")

    return "\n".join(lines)