mirror of
https://github.com/open-webui/open-webui
synced 2025-05-29 17:52:48 +00:00
refac: default tool calling behaviour
This commit is contained in:
parent
db8780fd9c
commit
881d81d87f
@ -235,46 +235,30 @@ async def chat_completion_tools_handler(
|
||||
if isinstance(tool_result, str):
|
||||
tool = tools[tool_function_name]
|
||||
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(
|
||||
"direct", False
|
||||
):
|
||||
|
||||
# Citation is enabled for this tool
|
||||
sources.append(
|
||||
{
|
||||
"source": {
|
||||
"name": (
|
||||
f"TOOL:" + f"{tool_id}/{tool_function_name}"
|
||||
if tool_id
|
||||
else f"{tool_function_name}"
|
||||
),
|
||||
"name": (f"TOOL:{tool_name}"),
|
||||
},
|
||||
"document": [tool_result, *tool_result_files],
|
||||
"metadata": [
|
||||
{
|
||||
"source": (
|
||||
f"TOOL:" + f"{tool_id}/{tool_function_name}"
|
||||
if tool_id
|
||||
else f"{tool_function_name}"
|
||||
)
|
||||
}
|
||||
],
|
||||
"document": [tool_result],
|
||||
"metadata": [{"source": (f"TOOL:{tool_name}")}],
|
||||
}
|
||||
)
|
||||
else:
|
||||
sources.append(
|
||||
{
|
||||
"source": {},
|
||||
"document": [tool_result, *tool_result_files],
|
||||
"metadata": [
|
||||
{
|
||||
"source": (
|
||||
f"TOOL:" + f"{tool_id}/{tool_function_name}"
|
||||
if tool_id
|
||||
else f"{tool_function_name}"
|
||||
)
|
||||
}
|
||||
],
|
||||
}
|
||||
# Citation is not enabled for this tool
|
||||
body["messages"] = add_or_update_user_message(
|
||||
f"\nTool `{tool_name}` Output: {tool_result}",
|
||||
body["messages"],
|
||||
)
|
||||
|
||||
if (
|
||||
|
@ -56,7 +56,7 @@ class Tools:
|
||||
def __init__(self):
|
||||
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:
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user