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

wip(agents-api): Add Doc sql queries #979

Draft
wants to merge 11 commits into
base: f/switch-to-pg
Choose a base branch
from
24 changes: 24 additions & 0 deletions agents-api/agents_api/autogen/Docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@ class Doc(BaseModel):
"""
Embeddings for the document
"""
modality: Annotated[str | None, Field(json_schema_extra={"readOnly": True})] = None
"""
Modality of the document
"""
language: Annotated[str | None, Field(json_schema_extra={"readOnly": True})] = None
"""
Language of the document
"""
index: Annotated[int | None, Field(json_schema_extra={"readOnly": True})] = None
"""
Index of the document
"""
embedding_model: Annotated[
str | None, Field(json_schema_extra={"readOnly": True})
] = None
"""
Embedding model to use for the document
"""
embedding_dimensions: Annotated[
int | None, Field(json_schema_extra={"readOnly": True})
] = None
"""
Dimensions of the embedding model
"""


class DocOwner(BaseModel):
Expand Down
57 changes: 28 additions & 29 deletions agents-api/agents_api/queries/agents/create_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@

from uuid import UUID

import asyncpg
from beartype import beartype
from fastapi import HTTPException
from sqlglot import parse_one
from uuid_extensions import uuid7

from ...autogen.openapi_model import Agent, CreateAgentRequest
from ...metrics.counters import increase_counter
from ..utils import (
generate_canonical_name,
partialclass,
pg_query,
rewrap_exceptions,
wrap_in_class,
)

Expand Down Expand Up @@ -45,35 +49,30 @@
""").sql(pretty=True)


# @rewrap_exceptions(
# {
# psycopg_errors.ForeignKeyViolation: partialclass(
# HTTPException,
# status_code=404,
# detail="The specified developer does not exist.",
# ),
# psycopg_errors.UniqueViolation: partialclass(
# HTTPException,
# status_code=409,
# detail="An agent with this canonical name already exists for this developer.",
# ),
# psycopg_errors.CheckViolation: partialclass(
# HTTPException,
# status_code=400,
# detail="The provided data violates one or more constraints. Please check the input values.",
# ),
# ValidationError: partialclass(
# HTTPException,
# status_code=400,
# detail="Input validation failed. Please check the provided data.",
# ),
# TypeError: partialclass(
# HTTPException,
# status_code=400,
# detail="A type mismatch occurred. Please review the input.",
# ),
# }
# )
@rewrap_exceptions(
{
asyncpg.exceptions.ForeignKeyViolationError: partialclass(
HTTPException,
status_code=404,
detail="The specified developer does not exist.",
),
asyncpg.exceptions.UniqueViolationError: partialclass(
HTTPException,
status_code=409,
detail="An agent with this canonical name already exists for this developer.",
),
asyncpg.exceptions.CheckViolationError: partialclass(
HTTPException,
status_code=400,
detail="The provided data violates one or more constraints. Please check the input values.",
),
asyncpg.exceptions.DataError: partialclass(
HTTPException,
status_code=400,
detail="Invalid data provided. Please check the input values.",
),
}
)
@wrap_in_class(
Agent,
one=True,
Expand Down
37 changes: 28 additions & 9 deletions agents-api/agents_api/queries/agents/create_or_update_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@

from uuid import UUID

import asyncpg
from beartype import beartype
from fastapi import HTTPException
from sqlglot import parse_one

from ...autogen.openapi_model import Agent, CreateOrUpdateAgentRequest
from ...metrics.counters import increase_counter
from ..utils import (
generate_canonical_name,
partialclass,
pg_query,
rewrap_exceptions,
wrap_in_class,
)

Expand Down Expand Up @@ -44,15 +48,30 @@
""").sql(pretty=True)


# @rewrap_exceptions(
# {
# psycopg_errors.ForeignKeyViolation: partialclass(
# HTTPException,
# status_code=404,
# detail="The specified developer does not exist.",
# )
# }
# )
@rewrap_exceptions(
{
asyncpg.exceptions.ForeignKeyViolationError: partialclass(
HTTPException,
status_code=404,
detail="The specified developer does not exist.",
),
asyncpg.exceptions.UniqueViolationError: partialclass(
HTTPException,
status_code=409,
detail="An agent with this canonical name already exists for this developer.",
),
asyncpg.exceptions.CheckViolationError: partialclass(
HTTPException,
status_code=400,
detail="The provided data violates one or more constraints. Please check the input values.",
),
asyncpg.exceptions.DataError: partialclass(
HTTPException,
status_code=400,
detail="Invalid data provided. Please check the input values.",
),
}
)
@wrap_in_class(
Agent,
one=True,
Expand Down
39 changes: 28 additions & 11 deletions agents-api/agents_api/queries/agents/delete_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@

from uuid import UUID

import asyncpg
from beartype import beartype
from fastapi import HTTPException
from sqlglot import parse_one

from ...autogen.openapi_model import ResourceDeletedResponse
from ...common.utils.datetime import utcnow
from ..utils import (
partialclass,
pg_query,
rewrap_exceptions,
wrap_in_class,
)

Expand Down Expand Up @@ -59,17 +63,30 @@
""").sql(pretty=True)


# @rewrap_exceptions(
# @rewrap_exceptions(
# {
# psycopg_errors.ForeignKeyViolation: partialclass(
# HTTPException,
# status_code=404,
# detail="The specified developer does not exist.",
# )
# }
# # TODO: Add more exceptions
# )
@rewrap_exceptions(
{
asyncpg.exceptions.ForeignKeyViolationError: partialclass(
HTTPException,
status_code=404,
detail="The specified developer does not exist.",
),
asyncpg.exceptions.UniqueViolationError: partialclass(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The asyncpg.exceptions.UniqueViolationError should not be handled here as it is not relevant to delete operations. Consider removing this exception handling.

HTTPException,
status_code=409,
detail="An agent with this canonical name already exists for this developer.",
),
asyncpg.exceptions.CheckViolationError: partialclass(
HTTPException,
status_code=400,
detail="The provided data violates one or more constraints. Please check the input values.",
),
asyncpg.exceptions.DataError: partialclass(
HTTPException,
status_code=400,
detail="Invalid data provided. Please check the input values.",
),
}
)
@wrap_in_class(
ResourceDeletedResponse,
one=True,
Expand Down
28 changes: 18 additions & 10 deletions agents-api/agents_api/queries/agents/get_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@

from uuid import UUID

import asyncpg
from beartype import beartype
from fastapi import HTTPException
from sqlglot import parse_one

from ...autogen.openapi_model import Agent
from ..utils import (
partialclass,
pg_query,
rewrap_exceptions,
wrap_in_class,
)

Expand All @@ -35,16 +39,20 @@
""").sql(pretty=True)


# @rewrap_exceptions(
# {
# psycopg_errors.ForeignKeyViolation: partialclass(
# HTTPException,
# status_code=404,
# detail="The specified developer does not exist.",
# )
# }
# # TODO: Add more exceptions
# )
@rewrap_exceptions(
{
asyncpg.exceptions.ForeignKeyViolationError: partialclass(
HTTPException,
status_code=404,
detail="The specified developer does not exist.",
),
asyncpg.exceptions.DataError: partialclass(
HTTPException,
status_code=400,
detail="Invalid data provided. Please check the input values.",
),
}
)
@wrap_in_class(Agent, one=True, transform=lambda d: {"id": d["agent_id"], **d})
@pg_query
@beartype
Expand Down
27 changes: 17 additions & 10 deletions agents-api/agents_api/queries/agents/list_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
from typing import Any, Literal
from uuid import UUID

import asyncpg
from beartype import beartype
from fastapi import HTTPException

from ...autogen.openapi_model import Agent
from ..utils import (
partialclass,
pg_query,
rewrap_exceptions,
wrap_in_class,
)

Expand Down Expand Up @@ -40,16 +43,20 @@
"""


# @rewrap_exceptions(
# {
# psycopg_errors.ForeignKeyViolation: partialclass(
# HTTPException,
# status_code=404,
# detail="The specified developer does not exist.",
# )
# }
# # TODO: Add more exceptions
# )
@rewrap_exceptions(
{
asyncpg.exceptions.ForeignKeyViolationError: partialclass(
HTTPException,
status_code=404,
detail="The specified developer does not exist.",
),
asyncpg.exceptions.DataError: partialclass(
HTTPException,
status_code=400,
detail="Invalid data provided. Please check the input values.",
),
}
)
@wrap_in_class(Agent, transform=lambda d: {"id": d["agent_id"], **d})
@pg_query
@beartype
Expand Down
38 changes: 28 additions & 10 deletions agents-api/agents_api/queries/agents/patch_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@

from uuid import UUID

import asyncpg
from beartype import beartype
from fastapi import HTTPException
from sqlglot import parse_one

from ...autogen.openapi_model import PatchAgentRequest, ResourceUpdatedResponse
from ...metrics.counters import increase_counter
from ..utils import (
partialclass,
pg_query,
rewrap_exceptions,
wrap_in_class,
)

Expand Down Expand Up @@ -44,16 +48,30 @@
""").sql(pretty=True)


# @rewrap_exceptions(
# {
# psycopg_errors.ForeignKeyViolation: partialclass(
# HTTPException,
# status_code=404,
# detail="The specified developer does not exist.",
# )
# }
# # TODO: Add more exceptions
# )
@rewrap_exceptions(
{
asyncpg.exceptions.ForeignKeyViolationError: partialclass(
HTTPException,
status_code=404,
detail="The specified developer does not exist.",
),
asyncpg.exceptions.UniqueViolationError: partialclass(
HTTPException,
status_code=409,
detail="An agent with this canonical name already exists for this developer.",
),
asyncpg.exceptions.CheckViolationError: partialclass(
HTTPException,
status_code=400,
detail="The provided data violates one or more constraints. Please check the input values.",
),
asyncpg.exceptions.DataError: partialclass(
HTTPException,
status_code=400,
detail="Invalid data provided. Please check the input values.",
),
}
)
@wrap_in_class(
ResourceUpdatedResponse,
one=True,
Expand Down
Loading
Loading