refac: default tool calling behaviour

This commit is contained in:
Timothy Jaeryang Baek 2025-04-12 17:26:35 -07:00
parent db8780fd9c
commit 881d81d87f
2 changed files with 15 additions and 31 deletions

View File

@ -235,46 +235,30 @@ async def chat_completion_tools_handler(
if isinstance(tool_result, str): if isinstance(tool_result, str):
tool = tools[tool_function_name] tool = tools[tool_function_name]
tool_id = tool.get("tool_id", "") tool_id = tool.get("tool_id", "")
tool_name = (
f"{tool_id}/{tool_function_name}"
if tool_id
else f"{tool_function_name}"
)
if tool.get("metadata", {}).get("citation", False) or tool.get( if tool.get("metadata", {}).get("citation", False) or tool.get(
"direct", False "direct", False
): ):
# Citation is enabled for this tool
sources.append( sources.append(
{ {
"source": { "source": {
"name": ( "name": (f"TOOL:{tool_name}"),
f"TOOL:" + f"{tool_id}/{tool_function_name}"
if tool_id
else f"{tool_function_name}"
),
}, },
"document": [tool_result, *tool_result_files], "document": [tool_result],
"metadata": [ "metadata": [{"source": (f"TOOL:{tool_name}")}],
{
"source": (
f"TOOL:" + f"{tool_id}/{tool_function_name}"
if tool_id
else f"{tool_function_name}"
)
}
],
} }
) )
else: else:
sources.append( # Citation is not enabled for this tool
{ body["messages"] = add_or_update_user_message(
"source": {}, f"\nTool `{tool_name}` Output: {tool_result}",
"document": [tool_result, *tool_result_files], body["messages"],
"metadata": [
{
"source": (
f"TOOL:" + f"{tool_id}/{tool_function_name}"
if tool_id
else f"{tool_function_name}"
)
}
],
}
) )
if ( if (

View File

@ -56,7 +56,7 @@ class Tools:
def __init__(self): def __init__(self):
pass pass
# Add your custom tools using pure Python code here, make sure to add type hints # Add your custom tools using pure Python code here, make sure to add type hints and descriptions
def get_user_name_and_email_and_id(self, __user__: dict = {}) -> str: def get_user_name_and_email_and_id(self, __user__: dict = {}) -> str:
""" """