diff --git a/backend/main.py b/backend/main.py index 3915f8244b..6c75164dcb 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, - 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}], } diff --git a/backend/utils/task.py b/backend/utils/task.py index 37c174d3d8..1b2276c9c5 100644 --- a/backend/utils/task.py +++ b/backend/utils/task.py @@ -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