From 790bdcf9fcd64c0d033b263647d6e619384a9e41 Mon Sep 17 00:00:00 2001 From: Michael Poluektov Date: Sun, 11 Aug 2024 14:56:16 +0100 Subject: [PATCH] rename tool calling helpers to use 'tool' instead of 'function' --- backend/main.py | 12 ++++++------ backend/utils/task.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/main.py b/backend/main.py index 14d5a604a..c992f175f 100644 --- a/backend/main.py +++ b/backend/main.py @@ -72,7 +72,7 @@ from utils.utils import ( from utils.task import ( title_generation_template, search_query_generation_template, - tools_function_calling_generation_template, + tool_calling_generation_template, ) from utils.misc import ( get_last_user_message, @@ -322,7 +322,7 @@ async def call_tool_from_completion( return None -def get_function_calling_payload(messages, task_model_id, content): +def get_tool_calling_payload(messages, task_model_id, content): user_message = get_last_user_message(messages) history = "\n".join( f"{message['role'].upper()}: \"\"\"{message['content']}\"\"\"" @@ -342,7 +342,7 @@ def get_function_calling_payload(messages, task_model_id, content): } -async def get_function_call_response( +async def get_tool_call_response( messages, files, tool_id, template, task_model_id, user, extra_params ) -> tuple[Optional[str], Optional[dict], bool]: tool = Tools.get_tool_by_id(tool_id) @@ -350,8 +350,8 @@ async def get_function_call_response( return None, None, False tools_specs = json.dumps(tool.specs, indent=2) - content = tools_function_calling_generation_template(template, tools_specs) - payload = get_function_calling_payload(messages, task_model_id, content) + content = tool_calling_generation_template(template, tools_specs) + payload = get_tool_calling_payload(messages, task_model_id, content) try: payload = filter_pipeline(payload, user) @@ -502,7 +502,7 @@ async def chat_completion_tools_handler(body, user, extra_params): for tool_id in body["tool_ids"]: print(tool_id) try: - response, citation, file_handler = await get_function_call_response( + response, citation, file_handler = await get_tool_call_response( messages=body["messages"], files=body.get("files", []), tool_id=tool_id, diff --git a/backend/utils/task.py b/backend/utils/task.py index 1b2276c9c..37c174d3d 100644 --- a/backend/utils/task.py +++ b/backend/utils/task.py @@ -121,6 +121,6 @@ def search_query_generation_template( return template -def tools_function_calling_generation_template(template: str, tools_specs: str) -> str: +def tool_calling_generation_template(template: str, tools_specs: str) -> str: template = template.replace("{{TOOLS}}", tools_specs) return template