feat: external tool server support frontend

This commit is contained in:
Timothy Jaeryang Baek
2025-03-27 01:38:35 -07:00
parent 3514a6c5ed
commit d9b6d78d5c
9 changed files with 536 additions and 18 deletions

View File

@@ -215,6 +215,7 @@ async def chat_completion_tools_handler(
"id": str(uuid4()),
"tool": tool,
"params": tool_function_params,
"server": tool.get("server", {}),
"session_id": metadata.get("session_id", None),
},
}
@@ -787,10 +788,10 @@ async def process_chat_payload(request, form_data, user, metadata, model):
# Server side tools
tool_ids = metadata.get("tool_ids", None)
# Client side tools
tool_specs = form_data.get("tool_specs", None)
tool_servers = form_data.get("tool_servers", None)
log.debug(f"{tool_ids=}")
log.debug(f"{tool_specs=}")
log.debug(f"{tool_servers=}")
tools_dict = {}
@@ -808,14 +809,16 @@ async def process_chat_payload(request, form_data, user, metadata, model):
)
log.info(f"{tools_dict=}")
if tool_specs:
for tool in tool_specs:
callable = tool.pop("callable", None)
tools_dict[tool["name"]] = {
"direct": True,
"callable": callable,
"spec": tool,
}
if tool_servers:
for tool_server in tool_servers:
tool_specs = tool_server.pop("specs", [])
for tool in tool_specs:
tools_dict[tool["name"]] = {
"spec": tool,
"direct": True,
"server": tool_server,
}
if tools_dict:
if metadata.get("function_calling") == "native":
@@ -1823,6 +1826,7 @@ async def process_chat_response(
"id": str(uuid4()),
"tool": tool,
"params": tool_function_params,
"server": tool.get("server", {}),
"session_id": metadata.get(
"session_id", None
),

View File

@@ -91,10 +91,11 @@ def get_tools(
# TODO: This needs to be a pydantic model
tool_dict = {
"toolkit_id": tool_id,
"callable": callable,
"spec": spec,
"callable": callable,
"toolkit_id": tool_id,
"pydantic_model": function_to_pydantic_model(callable),
# Misc info
"file_handler": hasattr(module, "file_handler") and module.file_handler,
"citation": hasattr(module, "citation") and module.citation,
}