mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-19 12:24:46 +08:00
feat: fallback to error reporting
This commit is contained in:
@@ -21,26 +21,29 @@ def web_search_tool(query: str) -> str:
|
|||||||
Args:
|
Args:
|
||||||
query: The query to search for.
|
query: The query to search for.
|
||||||
"""
|
"""
|
||||||
config = get_app_config().get_tool_config("web_search")
|
try:
|
||||||
max_results = 5
|
config = get_app_config().get_tool_config("web_search")
|
||||||
if config is not None:
|
max_results = 5
|
||||||
max_results = config.model_extra.get("max_results", max_results)
|
if config is not None:
|
||||||
|
max_results = config.model_extra.get("max_results", max_results)
|
||||||
|
|
||||||
client = _get_firecrawl_client()
|
client = _get_firecrawl_client()
|
||||||
result = client.search(query, limit=max_results)
|
result = client.search(query, limit=max_results)
|
||||||
|
|
||||||
# result.web contains list of SearchResultWeb objects
|
# result.web contains list of SearchResultWeb objects
|
||||||
web_results = result.web or []
|
web_results = result.web or []
|
||||||
normalized_results = [
|
normalized_results = [
|
||||||
{
|
{
|
||||||
"title": getattr(item, "title", "") or "",
|
"title": getattr(item, "title", "") or "",
|
||||||
"url": getattr(item, "url", "") or "",
|
"url": getattr(item, "url", "") or "",
|
||||||
"snippet": getattr(item, "description", "") or "",
|
"snippet": getattr(item, "description", "") or "",
|
||||||
}
|
}
|
||||||
for item in web_results
|
for item in web_results
|
||||||
]
|
]
|
||||||
json_results = json.dumps(normalized_results, indent=2, ensure_ascii=False)
|
json_results = json.dumps(normalized_results, indent=2, ensure_ascii=False)
|
||||||
return json_results
|
return json_results
|
||||||
|
except Exception as e:
|
||||||
|
return f"Error: {str(e)}"
|
||||||
|
|
||||||
|
|
||||||
@tool("web_fetch", parse_docstring=True)
|
@tool("web_fetch", parse_docstring=True)
|
||||||
@@ -54,14 +57,17 @@ 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.
|
||||||
"""
|
"""
|
||||||
client = _get_firecrawl_client()
|
try:
|
||||||
result = client.scrape(url, formats=["markdown"])
|
client = _get_firecrawl_client()
|
||||||
|
result = client.scrape(url, formats=["markdown"])
|
||||||
|
|
||||||
markdown_content = result.markdown or ""
|
markdown_content = result.markdown or ""
|
||||||
metadata = result.metadata
|
metadata = result.metadata
|
||||||
title = metadata.title if metadata and metadata.title else "Untitled"
|
title = metadata.title if metadata and metadata.title else "Untitled"
|
||||||
|
|
||||||
if not markdown_content:
|
if not markdown_content:
|
||||||
return "Error: No content found"
|
return "Error: No content found"
|
||||||
|
except Exception as e:
|
||||||
|
return f"Error: {str(e)}"
|
||||||
|
|
||||||
return f"# {title}\n\n{markdown_content}"
|
return f"# {title}\n\n{markdown_content}"
|
||||||
|
|||||||
Reference in New Issue
Block a user