mirror of
https://github.com/open-webui/open-webui
synced 2024-11-28 15:05:07 +00:00
refac
This commit is contained in:
parent
c4946d42e0
commit
fe747382c1
@ -283,7 +283,7 @@ def get_filter_function_ids(model):
|
|||||||
return filter_ids
|
return filter_ids
|
||||||
|
|
||||||
|
|
||||||
def get_tool_call_payload(messages, task_model_id, content):
|
def get_tools_function_calling_payload(messages, task_model_id, content):
|
||||||
user_message = get_last_user_message(messages)
|
user_message = get_last_user_message(messages)
|
||||||
history = "\n".join(
|
history = "\n".join(
|
||||||
f"{message['role'].upper()}: \"\"\"{message['content']}\"\"\""
|
f"{message['role'].upper()}: \"\"\"{message['content']}\"\"\""
|
||||||
@ -486,9 +486,9 @@ async def chat_completion_tools_handler(
|
|||||||
|
|
||||||
specs = [tool["spec"] for tool in tools.values()]
|
specs = [tool["spec"] for tool in tools.values()]
|
||||||
tools_specs = json.dumps(specs)
|
tools_specs = json.dumps(specs)
|
||||||
template = app.state.config.TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE
|
|
||||||
content = tool_calling_generation_template(template, tools_specs)
|
content = tool_calling_generation_template(app.state.config.TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE, tools_specs)
|
||||||
payload = get_tool_call_payload(body["messages"], task_model_id, content)
|
payload = get_tools_function_calling_payload(body["messages"], task_model_id, content)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
payload = filter_pipeline(payload, user)
|
payload = filter_pipeline(payload, user)
|
||||||
@ -500,6 +500,8 @@ async def chat_completion_tools_handler(
|
|||||||
log.debug(f"{response=}")
|
log.debug(f"{response=}")
|
||||||
content = await get_content_from_response(response)
|
content = await get_content_from_response(response)
|
||||||
log.debug(f"{content=}")
|
log.debug(f"{content=}")
|
||||||
|
|
||||||
|
|
||||||
if content is None:
|
if content is None:
|
||||||
return body, {}
|
return body, {}
|
||||||
|
|
||||||
@ -510,7 +512,7 @@ async def chat_completion_tools_handler(
|
|||||||
|
|
||||||
tool_params = result.get("parameters", {})
|
tool_params = result.get("parameters", {})
|
||||||
toolkit_id = tools[tool_name]["toolkit_id"]
|
toolkit_id = tools[tool_name]["toolkit_id"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tool_output = await tools[tool_name]["callable"](**tool_params)
|
tool_output = await tools[tool_name]["callable"](**tool_params)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user