mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-26 23:34:47 +08:00
fix: support loading tavily ak from config.yaml
This commit is contained in:
@@ -5,7 +5,13 @@ from tavily import TavilyClient
|
|||||||
|
|
||||||
from src.config import get_app_config
|
from src.config import get_app_config
|
||||||
|
|
||||||
tavily_client = TavilyClient()
|
|
||||||
|
def _get_tavily_client() -> TavilyClient:
|
||||||
|
config = get_app_config().get_tool_config("web_search")
|
||||||
|
api_key = None
|
||||||
|
if config is not None and "api_key" in config.model_extra:
|
||||||
|
api_key = config.model_extra.get("api_key")
|
||||||
|
return TavilyClient(api_key=api_key)
|
||||||
|
|
||||||
|
|
||||||
@tool("web_search", parse_docstring=True)
|
@tool("web_search", parse_docstring=True)
|
||||||
@@ -19,7 +25,9 @@ def web_search_tool(query: str) -> str:
|
|||||||
max_results = 5
|
max_results = 5
|
||||||
if config is not None and "max_results" in config.model_extra:
|
if config is not None and "max_results" in config.model_extra:
|
||||||
max_results = config.model_extra.get("max_results")
|
max_results = config.model_extra.get("max_results")
|
||||||
res = tavily_client.search(query, max_results=max_results)
|
|
||||||
|
client = _get_tavily_client()
|
||||||
|
res = client.search(query, max_results=max_results)
|
||||||
normalized_results = [
|
normalized_results = [
|
||||||
{
|
{
|
||||||
"title": result["title"],
|
"title": result["title"],
|
||||||
@@ -43,7 +51,8 @@ def web_fetch_tool(url: str) -> str:
|
|||||||
Args:
|
Args:
|
||||||
url: The URL to fetch the contents of.
|
url: The URL to fetch the contents of.
|
||||||
"""
|
"""
|
||||||
res = tavily_client.extract([url])
|
client = _get_tavily_client()
|
||||||
|
res = client.extract([url])
|
||||||
if "failed_results" in res and len(res["failed_results"]) > 0:
|
if "failed_results" in res and len(res["failed_results"]) > 0:
|
||||||
return f"Error: {res['failed_results'][0]['error']}"
|
return f"Error: {res['failed_results'][0]['error']}"
|
||||||
elif "results" in res and len(res["results"]) > 0:
|
elif "results" in res and len(res["results"]) > 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user