mirror of
https://github.com/open-webui/open-webui
synced 2024-11-07 00:59:52 +00:00
refac
This commit is contained in:
parent
536b40890a
commit
0ae6ca608c
@ -72,7 +72,7 @@ from utils.utils import (
|
||||
from utils.task import (
|
||||
title_generation_template,
|
||||
search_query_generation_template,
|
||||
tool_calling_generation_template,
|
||||
tools_function_calling_generation_template,
|
||||
)
|
||||
from utils.misc import (
|
||||
get_last_user_message,
|
||||
@ -466,11 +466,12 @@ async def chat_completion_tools_handler(
|
||||
specs = [tool["spec"] for tool in tools.values()]
|
||||
tools_specs = json.dumps(specs)
|
||||
|
||||
content = tool_calling_generation_template(
|
||||
tools_function_calling_prompt = tools_function_calling_generation_template(
|
||||
app.state.config.TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE, tools_specs
|
||||
)
|
||||
log.info(f"{tools_function_calling_prompt=}")
|
||||
payload = get_tools_function_calling_payload(
|
||||
body["messages"], task_model_id, content
|
||||
body["messages"], task_model_id, tools_function_calling_prompt
|
||||
)
|
||||
|
||||
try:
|
||||
@ -496,14 +497,18 @@ async def chat_completion_tools_handler(
|
||||
tool_function_params = result.get("parameters", {})
|
||||
|
||||
try:
|
||||
tool_output = await tools[tool_function_name]["callable"](**tool_function_params)
|
||||
tool_output = await tools[tool_function_name]["callable"](
|
||||
**tool_function_params
|
||||
)
|
||||
except Exception as e:
|
||||
tool_output = str(e)
|
||||
|
||||
if tools[tool_function_name]["citation"]:
|
||||
citations.append(
|
||||
{
|
||||
"source": {"name": f"TOOL:{tools[tool_function_name]['toolkit_id']}/{tool_function_name}"},
|
||||
"source": {
|
||||
"name": f"TOOL:{tools[tool_function_name]['toolkit_id']}/{tool_function_name}"
|
||||
},
|
||||
"document": [tool_output],
|
||||
"metadata": [{"source": tool_function_name}],
|
||||
}
|
||||
|
@ -121,6 +121,6 @@ def search_query_generation_template(
|
||||
return template
|
||||
|
||||
|
||||
def tool_calling_generation_template(template: str, tools_specs: str) -> str:
|
||||
def tools_function_calling_generation_template(template: str, tools_specs: str) -> str:
|
||||
template = template.replace("{{TOOLS}}", tools_specs)
|
||||
return template
|
||||
|
Loading…
Reference in New Issue
Block a user