-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Diwank Tomer <[email protected]>
- Loading branch information
Diwank Tomer
committed
Aug 5, 2024
1 parent
160c76f
commit c9c9a06
Showing
17 changed files
with
288 additions
and
127 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
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,6 @@ | ||
# ruff: noqa: F401 | ||
from .create_doc import create_agent_doc, create_user_doc | ||
from .delete_doc import delete_doc | ||
from .get_doc import get_doc | ||
from .list_docs import list_agent_docs, list_user_docs | ||
from .router import 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from typing import Annotated | ||
|
||
from fastapi import Depends | ||
from pydantic import UUID4 | ||
from starlette.status import HTTP_201_CREATED | ||
|
||
from ...autogen.openapi_model import CreateDocRequest, ResourceCreatedResponse | ||
from ...dependencies.developer_id import get_developer_id | ||
from ...models.docs.create_doc import create_doc as create_doc_query | ||
from .router import router | ||
|
||
|
||
@router.post("/users/{user_id}/docs", status_code=HTTP_201_CREATED, tags=["docs"]) | ||
async def create_user_doc( | ||
user_id: UUID4, | ||
data: CreateDocRequest, | ||
x_developer_id: Annotated[UUID4, Depends(get_developer_id)], | ||
) -> ResourceCreatedResponse: | ||
doc = create_doc_query( | ||
developer_id=x_developer_id, | ||
owner_type="user", | ||
owner_id=user_id, | ||
data=data, | ||
) | ||
|
||
return ResourceCreatedResponse(id=doc.id, created_at=doc.created_at) | ||
|
||
|
||
@router.post("/agents/{agent_id}/docs", status_code=HTTP_201_CREATED, tags=["docs"]) | ||
async def create_agent_doc( | ||
agent_id: UUID4, | ||
data: CreateDocRequest, | ||
x_developer_id: Annotated[UUID4, Depends(get_developer_id)], | ||
) -> ResourceCreatedResponse: | ||
doc = create_doc_query( | ||
developer_id=x_developer_id, | ||
owner_type="agent", | ||
owner_id=agent_id, | ||
data=data, | ||
) | ||
|
||
return ResourceCreatedResponse(id=doc.id, created_at=doc.created_at) |
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,17 @@ | ||
from typing import Annotated | ||
|
||
from fastapi import Depends | ||
from pydantic import UUID4 | ||
from starlette.status import HTTP_202_ACCEPTED | ||
|
||
from ...autogen.openapi_model import ResourceDeletedResponse | ||
from ...dependencies.developer_id import get_developer_id | ||
from ...models.docs.delete_doc import delete_doc as delete_doc_query | ||
from .router import router | ||
|
||
|
||
@router.delete("/docs/{doc_id}", status_code=HTTP_202_ACCEPTED, tags=["docs"]) | ||
async def delete_doc( | ||
doc_id: UUID4, x_developer_id: Annotated[UUID4, Depends(get_developer_id)] | ||
) -> ResourceDeletedResponse: | ||
return delete_doc_query(developer_id=x_developer_id, doc_id=doc_id) |
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,17 @@ | ||
from typing import Annotated | ||
|
||
from fastapi import Depends | ||
from pydantic import UUID4 | ||
|
||
from ...autogen.openapi_model import Doc | ||
from ...dependencies.developer_id import get_developer_id | ||
from ...models.docs.get_doc import get_doc as get_doc_query | ||
from .router import router | ||
|
||
|
||
@router.get("/docs/{doc_id}", tags=["docs"]) | ||
async def get_doc( | ||
x_developer_id: Annotated[UUID4, Depends(get_developer_id)], | ||
doc_id: UUID4, | ||
) -> Doc: | ||
return get_doc_query(developer_id=x_developer_id, doc_id=doc_id) |
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,75 @@ | ||
import json | ||
from json import JSONDecodeError | ||
from typing import Annotated, Literal | ||
|
||
from fastapi import Depends, HTTPException, status | ||
from pydantic import UUID4 | ||
|
||
from ...autogen.openapi_model import Doc, ListResponse | ||
from ...dependencies.developer_id import get_developer_id | ||
from ...models.docs.list_docs import list_docs as list_docs_query | ||
from .router import router | ||
|
||
|
||
@router.get("/users/{user_id}/docs", tags=["docs"]) | ||
async def list_user_docs( | ||
x_developer_id: Annotated[UUID4, Depends(get_developer_id)], | ||
user_id: UUID4, | ||
limit: int = 100, | ||
offset: int = 0, | ||
sort_by: Literal["created_at", "updated_at"] = "created_at", | ||
direction: Literal["asc", "desc"] = "desc", | ||
metadata_filter: str = "{}", | ||
) -> ListResponse[Doc]: | ||
try: | ||
metadata_filter = json.loads(metadata_filter) | ||
except JSONDecodeError: | ||
raise HTTPException( | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
detail="metadata_filter is not a valid JSON", | ||
) | ||
|
||
docs = list_docs_query( | ||
developer_id=x_developer_id, | ||
owner_type="user", | ||
owner_id=user_id, | ||
limit=limit, | ||
offset=offset, | ||
sort_by=sort_by, | ||
direction=direction, | ||
metadata_filter=metadata_filter, | ||
) | ||
|
||
return ListResponse[Doc](items=docs) | ||
|
||
|
||
@router.get("/agents/{agent_id}/docs", tags=["docs"]) | ||
async def list_agent_docs( | ||
x_developer_id: Annotated[UUID4, Depends(get_developer_id)], | ||
agent_id: UUID4, | ||
limit: int = 100, | ||
offset: int = 0, | ||
sort_by: Literal["created_at", "updated_at"] = "created_at", | ||
direction: Literal["asc", "desc"] = "desc", | ||
metadata_filter: str = "{}", | ||
) -> ListResponse[Doc]: | ||
try: | ||
metadata_filter = json.loads(metadata_filter) | ||
except JSONDecodeError: | ||
raise HTTPException( | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
detail="metadata_filter is not a valid JSON", | ||
) | ||
|
||
docs = list_docs_query( | ||
developer_id=x_developer_id, | ||
owner_type="agent", | ||
owner_id=agent_id, | ||
limit=limit, | ||
offset=offset, | ||
sort_by=sort_by, | ||
direction=direction, | ||
metadata_filter=metadata_filter, | ||
) | ||
|
||
return ListResponse[Doc](items=docs) |
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,3 @@ | ||
from fastapi import APIRouter | ||
|
||
router = APIRouter() |
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
16 changes: 16 additions & 0 deletions
16
agents-api/agents_api/routers/sessions/get_session_history.py
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,16 @@ | ||
from typing import Annotated | ||
|
||
from fastapi import Depends | ||
from pydantic import UUID4 | ||
|
||
from ...autogen.openapi_model import Session | ||
from ...dependencies.developer_id import get_developer_id | ||
from ...models.entry.get_history import get_history as get_history_query | ||
from .router import router | ||
|
||
|
||
@router.get("/sessions/{session_id}/history", tags=["sessions"]) | ||
async def get_session_history( | ||
session_id: UUID4, x_developer_id: Annotated[UUID4, Depends(get_developer_id)] | ||
) -> Session: | ||
return get_history_query(developer_id=x_developer_id, session_id=session_id) |
Oops, something went wrong.