-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(router): implement model and tool handlers
- Loading branch information
Showing
6 changed files
with
142 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
from .chat import router as chat_router | ||
from .agent import router as agent_router | ||
from .model import router as model_router | ||
from .tool import router as tool_router | ||
|
||
__all__ = ["chat_router", "agent_router"] | ||
__all__ = ["chat_router", "agent_router", "model_router", "tool_router"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from fastapi import APIRouter, Depends, status | ||
from sqlalchemy.orm import Session | ||
from typing import Union | ||
|
||
from openagent.db.models.model import Model | ||
from openagent.router.routes.models.response import ( | ||
ModelResponse, | ||
ModelListResponse, | ||
ResponseModel, | ||
) | ||
from openagent.router.error import APIExceptionResponse | ||
from openagent.db import get_db | ||
|
||
router = APIRouter(prefix="/models", tags=["models"]) | ||
|
||
|
||
@router.get( | ||
"", | ||
response_model=ResponseModel[ModelListResponse], | ||
summary="List all models", | ||
description="Get a paginated list of all models", | ||
responses={ | ||
200: {"description": "Successfully retrieved models"}, | ||
500: {"description": "Internal server error"}, | ||
}, | ||
) | ||
def list_models( | ||
page: int = 0, limit: int = 10, db: Session = Depends(get_db) | ||
) -> Union[ResponseModel[ModelListResponse], APIExceptionResponse]: | ||
try: | ||
total = db.query(Model).count() | ||
models = db.query(Model).offset(page * limit).limit(limit).all() | ||
return ResponseModel( | ||
code=status.HTTP_200_OK, | ||
data=ModelListResponse( | ||
models=[ModelResponse.model_validate(model) for model in models], | ||
total=total, | ||
), | ||
message=f"Retrieved {len(models)} models out of {total}", | ||
) | ||
except Exception as error: | ||
return APIExceptionResponse( | ||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, error=error | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from fastapi import APIRouter, Depends, status | ||
from sqlalchemy.orm import Session | ||
from typing import Union | ||
|
||
from openagent.db.models.tool import Tool | ||
from openagent.router.routes.models.response import ( | ||
ToolResponse, | ||
ToolListResponse, | ||
ResponseModel, | ||
) | ||
from openagent.router.error import APIExceptionResponse | ||
from openagent.db import get_db | ||
|
||
router = APIRouter(prefix="/tools", tags=["tools"]) | ||
|
||
|
||
@router.get( | ||
"", | ||
response_model=ResponseModel[ToolListResponse], | ||
summary="List all tools", | ||
description="Get a paginated list of all tools", | ||
responses={ | ||
200: {"description": "Successfully retrieved tools"}, | ||
500: {"description": "Internal server error"}, | ||
}, | ||
) | ||
def list_tools( | ||
page: int = 0, limit: int = 10, db: Session = Depends(get_db) | ||
) -> Union[ResponseModel[ToolListResponse], APIExceptionResponse]: | ||
try: | ||
total = db.query(Tool).count() | ||
tools = db.query(Tool).offset(page * limit).limit(limit).all() | ||
return ResponseModel( | ||
code=status.HTTP_200_OK, | ||
data=ToolListResponse( | ||
tools=[ToolResponse.model_validate(tool) for tool in tools], total=total | ||
), | ||
message=f"Retrieved {len(tools)} tools out of {total}", | ||
) | ||
except Exception as error: | ||
return APIExceptionResponse( | ||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, error=error | ||
) |
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