Skip to content

Commit

Permalink
feat: add (dummy) create tool route (#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacker authored Mar 12, 2024
1 parent efa12cf commit f5478a4
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion memgpt/server/rest_api/tools/index.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

Expand All @@ -32,4 +43,18 @@ async def list_all_tools(
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

0 comments on commit f5478a4

Please sign in to comment.