Spaces:
Running
Running
File size: 1,556 Bytes
ceb70c7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#
# 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 |