mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-01 09:49:03 -05:00
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).
|
||||
"""
|
||||
_EXPECTS_LIST = {"search_web", "query_knowledge_files"}
|
||||
_EXPECTS_DICT = {"view_knowledge_file"}
|
||||
|
||||
try:
|
||||
try:
|
||||
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:
|
||||
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":
|
||||
# Parse JSON array: [{"title": "...", "link": "...", "snippet": "..."}]
|
||||
results = tool_result
|
||||
|
||||
Reference in New Issue
Block a user