Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding static operation_id to all endpoints #406

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions ix/api/agents/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ class AgentCreateUpdate(BaseModel):
config: dict = {}


@router.post("/agents/", response_model=AgentPydantic, tags=["Agents"])
@router.post(
"/agents/",
operation_id="create_agent",
response_model=AgentPydantic,
tags=["Agents"],
)
async def create_agent(
agent: AgentCreateUpdate, user: AbstractUser = Depends(get_request_user)
):
Expand All @@ -34,7 +39,12 @@ async def create_agent(
return AgentPydantic.model_validate(agent_obj)


@router.get("/agents/{agent_id}", response_model=AgentPydantic, tags=["Agents"])
@router.get(
"/agents/{agent_id}",
operation_id="get_agent",
response_model=AgentPydantic,
tags=["Agents"],
)
async def get_agent(agent_id: str, user: AbstractUser = Depends(get_request_user)):
try:
query = Agent.objects.filter(pk=agent_id)
Expand All @@ -44,7 +54,9 @@ async def get_agent(agent_id: str, user: AbstractUser = Depends(get_request_user
return AgentPydantic.model_validate(agent)


@router.get("/agents/", response_model=AgentPage, tags=["Agents"])
@router.get(
"/agents/", operation_id="get_agents", response_model=AgentPage, tags=["Agents"]
)
async def get_agents(
search: Optional[str] = None,
chat_id: Optional[UUID] = None,
Expand All @@ -65,7 +77,12 @@ async def get_agents(
)


@router.put("/agents/{agent_id}", response_model=AgentPydantic, tags=["Agents"])
@router.put(
"/agents/{agent_id}",
operation_id="update_agent",
response_model=AgentPydantic,
tags=["Agents"],
)
async def update_agent(
agent_id: str,
agent: AgentCreateUpdate,
Expand All @@ -82,7 +99,12 @@ async def update_agent(
return agent_obj


@router.delete("/agents/{agent_id}", response_model=DeletedItem, tags=["Agents"])
@router.delete(
"/agents/{agent_id}",
operation_id="delete_agent",
response_model=DeletedItem,
tags=["Agents"],
)
async def delete_agent(agent_id: str, user: AbstractUser = Depends(get_request_user)):
try:
query = Agent.objects.filter(pk=agent_id)
Expand Down
25 changes: 21 additions & 4 deletions ix/api/artifacts/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,23 @@
__all__ = ["router"]


@router.post("/artifacts/", response_model=ArtifactPydantic, tags=["Artifacts"])
@router.post(
"/artifacts/",
operation_id="create_artifact",
response_model=ArtifactPydantic,
tags=["Artifacts"],
)
async def create_artifact(data: ArtifactCreate, user=Depends(get_request_user)):
instance = Artifact(user=user, **data.model_dump())
await instance.asave()
return ArtifactPydantic.model_validate(instance)


@router.get(
"/artifacts/{artifact_id}", response_model=ArtifactPydantic, tags=["Artifacts"]
"/artifacts/{artifact_id}",
operation_id="get_artifact",
response_model=ArtifactPydantic,
tags=["Artifacts"],
)
async def get_artifact(artifact_id: str, user=Depends(get_request_user)):
try:
Expand All @@ -38,7 +46,12 @@ async def get_artifact(artifact_id: str, user=Depends(get_request_user)):
return ArtifactPydantic.model_validate(artifact)


@router.get("/artifacts/", response_model=ArtifactPage, tags=["Artifacts"])
@router.get(
"/artifacts/",
operation_id="get_artifacts",
response_model=ArtifactPage,
tags=["Artifacts"],
)
async def get_artifacts(
chat_id: Optional[UUID] = None,
search: Optional[str] = None,
Expand All @@ -62,7 +75,10 @@ async def get_artifacts(


@router.put(
"/artifacts/{artifact_id}", response_model=ArtifactPydantic, tags=["Artifacts"]
"/artifacts/{artifact_id}",
operation_id="update_artifact",
response_model=ArtifactPydantic,
tags=["Artifacts"],
)
async def update_artifact(
artifact_id: str, data: ArtifactUpdate, user=Depends(get_request_user)
Expand All @@ -80,6 +96,7 @@ async def update_artifact(

@router.get(
"/artifacts/{artifact_id}/download",
operation_id="download_artifact",
tags=["Artifacts"],
responses={
200: {
Expand Down
35 changes: 30 additions & 5 deletions ix/api/chains/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ class DeletedItem(BaseModel):
id: UUID


@router.get("/chains/", response_model=ChainQueryPage, tags=["Chains"])
@router.get(
"/chains/",
operation_id="get_chains",
response_model=ChainQueryPage,
tags=["Chains"],
)
async def get_chains(
search: Optional[str] = None,
limit: int = 10,
Expand Down Expand Up @@ -112,15 +117,25 @@ async def create_chain_instance(**kwargs) -> Chain:
return chain


@router.post("/chains/", response_model=ChainPydantic, tags=["Chains"])
@router.post(
"/chains/",
operation_id="create_chain",
response_model=ChainPydantic,
tags=["Chains"],
)
async def create_chain(
chain: CreateChain, user: AbstractUser = Depends(get_request_user)
):
new_chain = await create_chain_instance(**chain.model_dump(), user=user)
return ChainPydantic.model_validate(new_chain)


@router.get("/chains/{chain_id}", response_model=ChainPydantic, tags=["Chains"])
@router.get(
"/chains/{chain_id}",
operation_id="get_chain",
response_model=ChainPydantic,
tags=["Chains"],
)
async def get_chain_detail(
chain_id: UUID, user: AbstractUser = Depends(get_request_user)
):
Expand Down Expand Up @@ -161,7 +176,12 @@ async def sync_chain_agent(chain: Chain, alias: str) -> None:
await Agent.objects.filter(chain=chain, is_test=False).adelete()


@router.put("/chains/{chain_id}", response_model=ChainPydantic, tags=["Chains"])
@router.put(
"/chains/{chain_id}",
operation_id="update_chain",
response_model=ChainPydantic,
tags=["Chains"],
)
async def update_chain(
chain_id: UUID, chain: UpdateChain, user: AbstractUser = Depends(get_request_user)
):
Expand Down Expand Up @@ -189,7 +209,12 @@ async def update_chain(
return response


@router.delete("/chains/{chain_id}", response_model=DeletedItem, tags=["Chains"])
@router.delete(
"/chains/{chain_id}",
operation_id="delete_chain",
response_model=DeletedItem,
tags=["Chains"],
)
async def delete_chain(chain_id: UUID, user: AbstractUser = Depends(get_request_user)):
query = Chain.filtered_owners(user)
try:
Expand Down
62 changes: 51 additions & 11 deletions ix/api/chats/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
router = APIRouter()


@router.post("/chats/", response_model=ChatPydantic, tags=["Chats"])
@router.post(
"/chats/", operation_id="create_chat", response_model=ChatPydantic, tags=["Chats"]
)
async def create_chat(chat: ChatNew, user: AbstractUser = Depends(get_request_user)):
# Check if user is authenticated
if user.is_anonymous:
Expand Down Expand Up @@ -82,7 +84,12 @@ async def create_chat(chat: ChatNew, user: AbstractUser = Depends(get_request_us
return ChatPydantic.model_validate(chat_obj)


@router.get("/chats/{chat_id}", response_model=ChatPydantic, tags=["Chats"])
@router.get(
"/chats/{chat_id}",
operation_id="get_chat",
response_model=ChatPydantic,
tags=["Chats"],
)
async def get_chat(chat_id: UUID, user: AbstractUser = Depends(get_request_user)):
query = Chat.filtered_owners(user)
try:
Expand All @@ -92,7 +99,9 @@ async def get_chat(chat_id: UUID, user: AbstractUser = Depends(get_request_user)
return ChatPydantic.model_validate(chat)


@router.get("/chats/", response_model=ChatQueryPage, tags=["Chats"])
@router.get(
"/chats/", operation_id="get_chats", response_model=ChatQueryPage, tags=["Chats"]
)
async def get_chats(
user: AbstractUser = Depends(get_request_user),
search: Optional[str] = None,
Expand All @@ -110,7 +119,12 @@ async def get_chats(
)


@router.put("/chats/{chat_id}", response_model=ChatPydantic, tags=["Chats"])
@router.put(
"/chats/{chat_id}",
operation_id="update_chat",
response_model=ChatPydantic,
tags=["Chats"],
)
async def update_chat(
chat_id: UUID, chat: ChatUpdate, user: AbstractUser = Depends(get_request_user)
):
Expand All @@ -127,7 +141,12 @@ async def update_chat(
return ChatPydantic.model_validate(chat_obj)


@router.delete("/chats/{chat_id}", response_model=DeletedItem, tags=["Chats"])
@router.delete(
"/chats/{chat_id}",
operation_id="delete_chat",
response_model=DeletedItem,
tags=["Chats"],
)
async def delete_chat(chat_id: UUID, user: AbstractUser = Depends(get_request_user)):
query = Chat.filtered_owners(user)
try:
Expand All @@ -139,7 +158,10 @@ async def delete_chat(chat_id: UUID, user: AbstractUser = Depends(get_request_us


@router.delete(
"/chats/{chat_id}/agents/{agent_id}", response_model=ChatAgentAction, tags=["Chats"]
"/chats/{chat_id}/agents/{agent_id}",
operation_id="remove_agent",
response_model=ChatAgentAction,
tags=["Chats"],
)
async def remove_agent(
chat_id: UUID, agent_id: UUID, user: AbstractUser = Depends(get_request_user)
Expand All @@ -156,7 +178,10 @@ async def remove_agent(


@router.put(
"/chats/{chat_id}/agents/{agent_id}", response_model=ChatAgentAction, tags=["Chats"]
"/chats/{chat_id}/agents/{agent_id}",
operation_id="add_agent",
response_model=ChatAgentAction,
tags=["Chats"],
)
async def add_agent(
chat_id: UUID, agent_id: UUID, user: AbstractUser = Depends(get_request_user)
Expand All @@ -178,7 +203,12 @@ async def add_agent(
raise HTTPException(status_code=404, detail="Agent does not exist.")


@router.get("/chats/{chat_id}/graph", response_model=ChatGraph, tags=["Chats"])
@router.get(
"/chats/{chat_id}/graph",
operation_id="get_chat_graph",
response_model=ChatGraph,
tags=["Chats"],
)
async def get_chat_graph(chat_id: str, user: AbstractUser = Depends(get_request_user)):
"""Chat and related objects

Expand Down Expand Up @@ -225,7 +255,10 @@ def get_artifacts(user_input):


@router.get(
"/chats/{chat_id}/messages", response_model=ChatMessageQueryPage, tags=["Chats"]
"/chats/{chat_id}/messages",
operation_id="get_messages",
response_model=ChatMessageQueryPage,
tags=["Chats"],
)
async def get_messages(
chat_id,
Expand All @@ -248,7 +281,12 @@ async def get_messages(
)


@router.post("/chats/{chat_id}/messages", response_model=ChatMessage, tags=["Chats"])
@router.post(
"/chats/{chat_id}/messages",
operation_id="send_message",
response_model=ChatMessage,
tags=["Chats"],
)
async def send_message(
chat_id: str, chat_input: ChatInput, user: AbstractUser = Depends(get_request_user)
):
Expand Down Expand Up @@ -314,7 +352,9 @@ async def send_message(
return ChatMessage.model_validate(message)


@router.post("/chats/{chat_id}/messages/clear", tags=["Chats"])
@router.post(
"/chats/{chat_id}/messages/clear", operation_id="clear_messages", tags=["Chats"]
)
async def clear_messages(chat_id: str, user: AbstractUser = Depends(get_request_user)):
try:
chat = await Chat.filtered_owners(user).aget(pk=chat_id)
Expand Down
29 changes: 24 additions & 5 deletions ix/api/components/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
router = APIRouter()


@router.get("/node_types/", response_model=NodeTypePage, tags=["Components"])
@router.get(
"/node_types/",
operation_id="get_node_types",
response_model=NodeTypePage,
tags=["Components"],
)
async def get_node_types(
search: Optional[str] = None,
class_path: Optional[str] = None,
Expand Down Expand Up @@ -51,7 +56,10 @@ class NodeTypeDetail(NodeTypePydantic):


@router.get(
"/node_types/{node_type_id}", response_model=NodeTypeDetail, tags=["Components"]
"/node_types/{node_type_id}",
operation_id="get_node_type",
response_model=NodeTypeDetail,
tags=["Components"],
)
async def get_node_type_detail(
node_type_id: UUID, user: AbstractUser = Depends(get_request_user)
Expand All @@ -65,7 +73,12 @@ async def get_node_type_detail(
return NodeTypeDetail.from_orm(node_type)


@router.post("/node_types/", response_model=NodeTypePydantic, tags=["Components"])
@router.post(
"/node_types/",
operation_id="create_node_type",
response_model=NodeTypePydantic,
tags=["Components"],
)
async def create_node_type(
node_type: NodeTypePydantic, user: AbstractUser = Depends(get_request_user)
):
Expand All @@ -77,7 +90,10 @@ async def create_node_type(


@router.put(
"/node_types/{node_type_id}", response_model=NodeTypePydantic, tags=["Components"]
"/node_types/{node_type_id}",
operation_id="update_node_type",
response_model=NodeTypePydantic,
tags=["Components"],
)
async def update_node_type(
node_type_id: UUID,
Expand All @@ -98,7 +114,10 @@ async def update_node_type(


@router.delete(
"/node_types/{node_type_id}", response_model=DeletedItem, tags=["Components"]
"/node_types/{node_type_id}",
operation_id="delete_node_type",
response_model=DeletedItem,
tags=["Components"],
)
async def delete_node_type(
node_type_id: UUID, user: AbstractUser = Depends(get_request_user)
Expand Down
Loading