Skip to content

Commit

Permalink
fix(agents-api): Fix metadata_filter logic
Browse files Browse the repository at this point in the history
Signed-off-by: Diwank Singh Tomer <[email protected]>
  • Loading branch information
creatorrr committed Oct 5, 2024
1 parent 28f66b7 commit 1f501bd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 4 additions & 2 deletions agents-api/agents_api/dependencies/query_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def create_filter_extractor(prefix: str = "filter") -> Callable[[Request], Filte
Callable[[Request], FilterModel]: The dependency function.
"""

# Add a dot to the prefix to allow for nested filters
prefix += "."

def extract_filters(request: Request) -> FilterModel:
"""
Extracts query parameters that start with the specified prefix and returns them as a dictionary.
Expand All @@ -42,10 +45,9 @@ def extract_filters(request: Request) -> FilterModel:
Returns:
FilterModel: A FilterModel instance containing the filter parameters.
"""
nonlocal prefix
prefix += "."

filters: dict[str, Any] = {}

for key, value in request.query_params.items():
if key.startswith(prefix):
filter_key = key[len(prefix) :]
Expand Down
4 changes: 2 additions & 2 deletions agents-api/agents_api/models/docs/list_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def list_docs(
created_at,
metadata,
}},
snippets[id, snippet_data]
snippets[id, snippet_data],
{metadata_filter_str}
:limit $limit
:offset $offset
Expand All @@ -112,6 +113,5 @@ def list_docs(
"owner_type": owner_type,
"limit": limit,
"offset": offset,
"metadata_filter": metadata_filter_str,
},
)
2 changes: 1 addition & 1 deletion agents-api/agents_api/routers/agents/list_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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, Depends(create_filter_extractor("metadata_filter"))
],
limit: int = 100,
offset: int = 0,
Expand Down
12 changes: 5 additions & 7 deletions agents-api/agents_api/routers/docs/list_docs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import json
from json import JSONDecodeError
from typing import Annotated, Literal
from uuid import UUID

from fastapi import Depends, HTTPException, status
from fastapi import Depends

from ...autogen.openapi_model import Doc, ListResponse
from ...dependencies.developer_id import get_developer_id
Expand All @@ -15,10 +13,10 @@
@router.get("/users/{user_id}/docs", tags=["docs"])
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"))
FilterModel, Depends(create_filter_extractor("metadata_filter"))
],
user_id: UUID,
limit: int = 100,
offset: int = 0,
sort_by: Literal["created_at", "updated_at"] = "created_at",
Expand All @@ -43,10 +41,10 @@ async def list_user_docs(
@router.get("/agents/{agent_id}/docs", tags=["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"))
FilterModel, Depends(create_filter_extractor("metadata_filter"))
],
agent_id: UUID,
limit: int = 100,
offset: int = 0,
sort_by: Literal["created_at", "updated_at"] = "created_at",
Expand Down

0 comments on commit 1f501bd

Please sign in to comment.