Skip to content

Commit

Permalink
refactor: Lint agents-api (CI)
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorrr authored and github-actions[bot] committed Oct 4, 2024
1 parent 9decd1f commit c3afa8f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion agents-api/agents_api/dependencies/query_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def convert_value(value: str) -> Any:
continue
return value


def create_filter_extractor(prefix: str = "filter") -> Callable[[Request], FilterModel]:
"""
Creates a dependency function to extract filter parameters with a given prefix.
Expand Down Expand Up @@ -47,7 +48,7 @@ def extract_filters(request: Request) -> FilterModel:
filters: dict[str, Any] = {}
for key, value in request.query_params.items():
if key.startswith(prefix):
filter_key = key[len(prefix):]
filter_key = key[len(prefix) :]
filters[filter_key] = convert_value(value)

return FilterModel(**filters)
Expand Down
4 changes: 1 addition & 3 deletions agents-api/agents_api/routers/agents/list_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ async def list_agents(
# Example:
# > ?metadata_filter.name=John&metadata_filter.age=30
metadata_filter: Annotated[
FilterModel | None,
Depends(create_filter_extractor("metadata_filter"))
FilterModel | None, Depends(create_filter_extractor("metadata_filter"))
],
limit: int = 100,
offset: int = 0,
sort_by: Literal["created_at", "updated_at"] = "created_at",
direction: Literal["asc", "desc"] = "desc",
) -> ListResponse[Agent]:

agents = list_agents_query(
developer_id=x_developer_id,
limit=limit,
Expand Down
8 changes: 6 additions & 2 deletions agents-api/agents_api/routers/docs/list_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
async def list_user_docs(
x_developer_id: Annotated[UUID, Depends(get_developer_id)],
user_id: UUID,
metadata_filter: Annotated[FilterModel | None, Depends(create_filter_extractor("metadata_filter"))],
metadata_filter: Annotated[
FilterModel | None, Depends(create_filter_extractor("metadata_filter"))
],
limit: int = 100,
offset: int = 0,
sort_by: Literal["created_at", "updated_at"] = "created_at",
Expand All @@ -40,7 +42,9 @@ async def list_user_docs(
async def list_agent_docs(
x_developer_id: Annotated[UUID, Depends(get_developer_id)],
agent_id: UUID,
metadata_filter: Annotated[FilterModel | None, Depends(create_filter_extractor("metadata_filter"))],
metadata_filter: Annotated[
FilterModel | None, Depends(create_filter_extractor("metadata_filter"))
],
limit: int = 100,
offset: int = 0,
sort_by: Literal["created_at", "updated_at"] = "created_at",
Expand Down
4 changes: 3 additions & 1 deletion agents-api/agents_api/routers/sessions/list_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
@router.get("/sessions", tags=["sessions"])
async def list_sessions(
x_developer_id: Annotated[UUID, Depends(get_developer_id)],
metadata_filter: Annotated[FilterModel | None, Depends(create_filter_extractor("metadata_filter"))],
metadata_filter: Annotated[
FilterModel | None, Depends(create_filter_extractor("metadata_filter"))
],
limit: int = 100,
offset: int = 0,
sort_by: Literal["created_at", "updated_at"] = "created_at",
Expand Down

0 comments on commit c3afa8f

Please sign in to comment.