Skip to content

Commit

Permalink
feat: Create new and update existing routes
Browse files Browse the repository at this point in the history
  • Loading branch information
whiterabbit1983 committed Jul 31, 2024
1 parent 88e7131 commit fca04b8
Show file tree
Hide file tree
Showing 8 changed files with 334 additions and 48 deletions.
27 changes: 15 additions & 12 deletions agents-api/agents_api/routers/agents/create_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
from pydantic import UUID4
from starlette.status import HTTP_201_CREATED

from ...autogen.openapi_model import CreateAgentRequest, ResourceCreatedResponse
from ...autogen.openapi_model import (
CreateAgentRequest,
ResourceCreatedResponse,
)
from ...dependencies.developer_id import get_developer_id
from ...models.agent.create_agent import create_agent as create_agent_query
from .router import router
Expand All @@ -18,17 +21,17 @@ async def create_agent(
) -> ResourceCreatedResponse:
new_agent_id = uuid4()

resp = create_agent_query(
developer_id=x_developer_id,
agent_id=new_agent_id,
name=request.name,
about=request.about,
instructions=request.instructions or [],
model=request.model,
default_settings=request.default_settings or {},
metadata=request.metadata or {},
_, resp = next(
create_agent_query(
developer_id=x_developer_id,
agent_id=new_agent_id,
name=request.name,
about=request.about,
instructions=request.instructions or [],
model=request.model,
default_settings=request.default_settings or {},
metadata=request.metadata or {},
).iterrows()
)

resp.iterrows()

return ResourceCreatedResponse(id=new_agent_id, created_at=resp["created_at"])
35 changes: 35 additions & 0 deletions agents-api/agents_api/routers/agents/create_agent_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from typing import Annotated
from uuid import UUID, uuid4

from fastapi import Depends
from pydantic import UUID4
from starlette.status import HTTP_201_CREATED

from ...autogen.openapi_model import (
CreateAgentRequest,
CreateOrUpdateAgentRequest,
CreateToolRequest,
ResourceCreatedResponse,
)
from ...dependencies.developer_id import get_developer_id
from ...models.tools.create_tools import create_tools as create_tools_query
from .router import router


@router.post("/agents/{agent_id}/tools", status_code=HTTP_201_CREATED, tags=["agents"])
async def create_agent_tools(
agent_id: UUID,
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
data: list[CreateToolRequest],
ignore_existing: bool = False,
) -> ResourceCreatedResponse:
_, resp = next(
create_tools_query(
developer_id=x_developer_id,
agent_id=agent_id,
data=data,
ignore_existing=ignore_existing,
).iterrows()
)

return ResourceCreatedResponse(id=resp["tool_id"], created_at=resp["created_at"])
33 changes: 33 additions & 0 deletions agents-api/agents_api/routers/agents/create_or_update_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from typing import Annotated
from uuid import UUID

from fastapi import Depends
from pydantic import UUID4
from starlette.status import HTTP_201_CREATED

from ...autogen.openapi_model import (
CreateOrUpdateAgentRequest,
ResourceCreatedResponse,
)
from ...dependencies.developer_id import get_developer_id
from ...models.agent.create_or_update_agent import (
create_or_update_agent as create_or_update_agent_query,
)
from .router import router


@router.post("/agents/{agent_id}", status_code=HTTP_201_CREATED, tags=["agents"])
async def create_or_update_agent(
agent_id: UUID,
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
data: CreateOrUpdateAgentRequest,
) -> ResourceCreatedResponse:
_, resp = next(
create_or_update_agent_query(
developer_id=x_developer_id,
agent_id=agent_id,
data=data,
).iterrows()
)

return ResourceCreatedResponse(id=agent_id, created_at=resp["created_at"])
28 changes: 28 additions & 0 deletions agents-api/agents_api/routers/agents/delete_agent_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from typing import Annotated
from uuid import UUID

from fastapi import Depends
from pydantic import UUID4

from ...autogen.openapi_model import ResourceDeletedResponse
from ...common.utils.datetime import utcnow
from ...dependencies.developer_id import get_developer_id
from ...models.tools.delete_tools import delete_tool as delete_tool_query
from .router import router


@router.delete("/agents/{agent_id}/tools/{tool_id}", tags=["agents"])
async def delete_agent_tools(
agent_id: UUID,
tool_id: UUID,
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
) -> ResourceDeletedResponse:
_, resp = next(
delete_tool_query(
developer_id=x_developer_id,
agent_id=agent_id,
tool_id=tool_id,
).iterrows()
)

return ResourceDeletedResponse(id=resp["tool_id"], deleted_at=utcnow())
31 changes: 31 additions & 0 deletions agents-api/agents_api/routers/agents/list_agent_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from typing import Annotated, Literal
from uuid import UUID

from fastapi import Depends
from pydantic import UUID4

from ...dependencies.developer_id import get_developer_id
from ...models.tools.list_tools import list_tools as list_tools_query
from .router import router


@router.get("/agents/{agent_id}/tools", tags=["agents"])
async def list_agent_tools(
agent_id: UUID,
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
limit: int = 100,
offset: int = 0,
sort_by: Literal["created_at", "updated_at"] = "created_at",
direction: Literal["asc", "desc"] = "desc",
) -> list[tuple[str, dict]]:
return [
row
for _, row in list_tools_query(
developer_id=x_developer_id,
agent_id=agent_id,
limit=limit,
offset=offset,
sort_by=sort_by,
direction=direction,
).iterrows()
]
32 changes: 32 additions & 0 deletions agents-api/agents_api/routers/agents/patch_agent_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from typing import Annotated
from uuid import UUID

from fastapi import Depends
from pydantic import UUID4

from ...autogen.openapi_model import (
PatchToolRequest,
ResourceUpdatedResponse,
)
from ...dependencies.developer_id import get_developer_id
from ...models.tools.patch_tool import patch_tool as patch_tool_query
from .router import router


@router.patch("/agents/{agent_id}/tools/{tool_id}", tags=["agents"])
async def patch_agent_tools(
agent_id: UUID,
tool_id: UUID,
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
patch_tool: PatchToolRequest,
) -> ResourceUpdatedResponse:
_, resp = next(
patch_tool_query(
developer_id=x_developer_id,
agent_id=agent_id,
tool_id=tool_id,
patch_tool=patch_tool,
).iterrows()
)

return ResourceUpdatedResponse(id=resp["tool_id"], updated_at=resp["updated_at"])
32 changes: 32 additions & 0 deletions agents-api/agents_api/routers/agents/update_agent_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from typing import Annotated
from uuid import UUID

from fastapi import Depends
from pydantic import UUID4

from ...autogen.openapi_model import (
ResourceUpdatedResponse,
UpdateToolRequest,
)
from ...dependencies.developer_id import get_developer_id
from ...models.tools.update_tool import update_tool as update_tool_query
from .router import router


@router.put("/agents/{agent_id}/tools/{tool_id}", tags=["agents"])
async def update_agent_tools(
agent_id: UUID,
tool_id: UUID,
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
data: UpdateToolRequest,
) -> ResourceUpdatedResponse:
_, resp = next(
update_tool_query(
developer_id=x_developer_id,
agent_id=agent_id,
tool_id=tool_id,
data=data,
).iterrows()
)

return ResourceUpdatedResponse(id=resp["tool_id"], updated_at=resp["updated_at"])
Loading

0 comments on commit fca04b8

Please sign in to comment.