refac
This commit is contained in:
@@ -173,6 +173,9 @@ def get_citation_source_from_tool_result(
|
|||||||
|
|
||||||
Returns a list of sources (usually one, but query_knowledge_files may return multiple).
|
Returns a list of sources (usually one, but query_knowledge_files may return multiple).
|
||||||
"""
|
"""
|
||||||
|
_EXPECTS_LIST = {"search_web", "query_knowledge_files"}
|
||||||
|
_EXPECTS_DICT = {"view_knowledge_file"}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
tool_result = json.loads(tool_result)
|
tool_result = json.loads(tool_result)
|
||||||
@@ -181,6 +184,12 @@ def get_citation_source_from_tool_result(
|
|||||||
if isinstance(tool_result, dict) and "error" in tool_result:
|
if isinstance(tool_result, dict) and "error" in tool_result:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
# Validate tool_result type based on what the branch expects
|
||||||
|
if tool_name in _EXPECTS_LIST and not isinstance(tool_result, list):
|
||||||
|
return []
|
||||||
|
elif tool_name in _EXPECTS_DICT and not isinstance(tool_result, dict):
|
||||||
|
return []
|
||||||
|
|
||||||
if tool_name == "search_web":
|
if tool_name == "search_web":
|
||||||
# Parse JSON array: [{"title": "...", "link": "...", "snippet": "..."}]
|
# Parse JSON array: [{"title": "...", "link": "...", "snippet": "..."}]
|
||||||
results = tool_result
|
results = tool_result
|
||||||
|
|||||||
Reference in New Issue
Block a user