-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
GET
REST API route for listing tools (#1100)
- Loading branch information
Showing
5 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import uuid | ||
from functools import partial | ||
from typing import List | ||
|
||
from fastapi import APIRouter, Depends, Body | ||
from pydantic import BaseModel, Field | ||
|
||
from memgpt.models.pydantic_models import ToolModel | ||
from memgpt.server.rest_api.auth_token import get_current_user | ||
from memgpt.server.rest_api.interface import QueuingInterface | ||
from memgpt.server.server import SyncServer | ||
|
||
router = APIRouter() | ||
|
||
|
||
class ListToolsResponse(BaseModel): | ||
tools: List[ToolModel] = Field(..., description="List of tools (functions).") | ||
|
||
|
||
def setup_tools_index_router(server: SyncServer, interface: QueuingInterface, password: str): | ||
get_current_user_with_server = partial(partial(get_current_user, server), password) | ||
|
||
@router.get("/tools", tags=["tools"], response_model=ListToolsResponse) | ||
async def list_tools( | ||
user_id: uuid.UUID = Depends(get_current_user_with_server), | ||
): | ||
""" | ||
Get a list of all tools available to agents created by a user | ||
""" | ||
# Clear the interface | ||
interface.clear() | ||
tools = server.ms.list_tools(user_id=user_id) | ||
return ListToolsResponse(tools=tools) | ||
|
||
return router |