feat(asyncify): migrate retrieve tool (#2228)
This commit is contained in:
@@ -59,7 +59,7 @@ def count_tools(
|
||||
|
||||
|
||||
@router.get("/{tool_id}", response_model=Tool, operation_id="retrieve_tool")
|
||||
def retrieve_tool(
|
||||
async def retrieve_tool(
|
||||
tool_id: str,
|
||||
server: SyncServer = Depends(get_letta_server),
|
||||
actor_id: Optional[str] = Header(None, alias="user_id"), # Extract user_id from header, default to None if not present
|
||||
@@ -67,8 +67,8 @@ def retrieve_tool(
|
||||
"""
|
||||
Get a tool by ID
|
||||
"""
|
||||
actor = server.user_manager.get_user_or_default(user_id=actor_id)
|
||||
tool = server.tool_manager.get_tool_by_id(tool_id=tool_id, actor=actor)
|
||||
actor = await server.user_manager.get_actor_or_default_async(actor_id=actor_id)
|
||||
tool = await server.tool_manager.get_tool_by_id_async(tool_id=tool_id, actor=actor)
|
||||
if tool is None:
|
||||
# return 404 error
|
||||
raise HTTPException(status_code=404, detail=f"Tool with id {tool_id} not found.")
|
||||
|
||||
@@ -105,6 +105,15 @@ class ToolManager:
|
||||
# Convert the SQLAlchemy Tool object to PydanticTool
|
||||
return tool.to_pydantic()
|
||||
|
||||
@enforce_types
|
||||
async def get_tool_by_id_async(self, tool_id: str, actor: PydanticUser) -> PydanticTool:
|
||||
"""Fetch a tool by its ID."""
|
||||
async with db_registry.async_session() as session:
|
||||
# Retrieve tool by id using the Tool model's read method
|
||||
tool = await ToolModel.read_async(db_session=session, identifier=tool_id, actor=actor)
|
||||
# Convert the SQLAlchemy Tool object to PydanticTool
|
||||
return tool.to_pydantic()
|
||||
|
||||
@enforce_types
|
||||
def get_tool_by_name(self, tool_name: str, actor: PydanticUser) -> Optional[PydanticTool]:
|
||||
"""Retrieve a tool by its name and a user. We derive the organization from the user, and retrieve that tool."""
|
||||
|
||||
Reference in New Issue
Block a user