From 3f998148ceb8113181f727feef429f538c645ff1 Mon Sep 17 00:00:00 2001 From: Charles Packer Date: Tue, 12 Mar 2024 02:56:50 -0700 Subject: [PATCH] feat: add (dummy) create tool route (#1139) --- memgpt/server/rest_api/tools/index.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/memgpt/server/rest_api/tools/index.py b/memgpt/server/rest_api/tools/index.py index 8d08e6a3..a45781ef 100644 --- a/memgpt/server/rest_api/tools/index.py +++ b/memgpt/server/rest_api/tools/index.py @@ -1,6 +1,6 @@ import uuid from functools import partial -from typing import List +from typing import List, Optional, Literal from fastapi import APIRouter, Depends, Body from pydantic import BaseModel, Field @@ -17,6 +17,17 @@ class ListToolsResponse(BaseModel): tools: List[ToolModel] = Field(..., description="List of tools (functions).") +class CreateToolRequest(BaseModel): + name: str = Field(..., description="The name of the function.") + source_code: str = Field(..., description="The source code of the function.") + source_type: Optional[Literal["python"]] = Field(None, description="The type of the source code.") + tags: Optional[List[str]] = Field(None, description="Metadata tags.") + + +class CreateToolResponse(BaseModel): + tool: ToolModel = Field(..., description="Information about the newly created tool.") + + def setup_tools_index_router(server: SyncServer, interface: QueuingInterface, password: str): get_current_user_with_server = partial(partial(get_current_user, server), password) @@ -32,4 +43,18 @@ def setup_tools_index_router(server: SyncServer, interface: QueuingInterface, pa tools = server.ms.list_tools(user_id=user_id) return ListToolsResponse(tools=tools) + @router.post("/tools", tags=["tools"], response_model=ListToolsResponse) + async def create_tool( + request: CreateToolRequest = Body(...), + user_id: uuid.UUID = Depends(get_current_user_with_server), + ): + """ + Create a new tool (dummy route) + """ + return ToolModel( + name="dummy_tool", + json_schema={}, + tags=[], + ) + return router