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

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

Merged
merged 20 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
20 changes: 20 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,26 @@ 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
"""
embedding_model: Annotated[
str | None, Field(json_schema_extra={"readOnly": True})
] = None
"""
Embedding model used 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
59 changes: 29 additions & 30 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 CreateAgentRequest, ResourceCreatedResponse
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(
ResourceCreatedResponse,
one=True,
Expand Down Expand Up @@ -115,7 +114,7 @@ async def create_agent(

# Set default values
data.metadata = data.metadata or {}
data.canonical_name = data.canonical_name or generate_canonical_name(data.name)
data.canonical_name = data.canonical_name or generate_canonical_name()

params = [
developer_id,
Expand Down
39 changes: 29 additions & 10 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 @@ -52,15 +56,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 Expand Up @@ -98,7 +117,7 @@ async def create_or_update_agent(

# Set default values
data.metadata = data.metadata or {}
data.canonical_name = data.canonical_name or generate_canonical_name(data.name)
data.canonical_name = data.canonical_name or generate_canonical_name()

params = [
developer_id,
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(
creatorrr marked this conversation as resolved.
Show resolved Hide resolved
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