searchgpt / src /processor /reasoning /tool_reasoning.py
hadadrjt's picture
SearchGPT: Enhance. #2
ceb70c7
#
# SPDX-FileCopyrightText: Hadad <hadad@linuxmail.org>
# SPDX-License-Identifier: Apache-2.0
#
from config import REASONING_STEPS, REASONING_DEFAULT
def tool_reasoning(tool_name, tool_arguments, stage, error=None, result=None):
if tool_name == "web_search":
query = tool_arguments.get("query", "") if tool_arguments else ""
engine = tool_arguments.get("engine", "google") if tool_arguments else "google"
template = REASONING_STEPS.get("web_search", {}).get(stage)
if template:
if stage == "completed":
preview = result[:300] + "..." if result and len(result) > 300 else result
return template.format(query=query, engine=engine, preview=preview)
elif stage == "error":
return template.format(query=query, engine=engine, error=error)
else:
return template.format(query=query, engine=engine)
elif tool_name == "read_url":
url = tool_arguments.get("url", "") if tool_arguments else ""
template = REASONING_STEPS.get("read_url", {}).get(stage)
if template:
if stage == "completed":
preview = result[:300] + "..." if result and len(result) > 300 else result
return template.format(url=url, preview=preview)
elif stage == "error":
return template.format(url=url, error=error)
else:
return template.format(url=url)
return REASONING_DEFAULT