Skip to content

Commit

Permalink
feat: Add executions queries
Browse files Browse the repository at this point in the history
  • Loading branch information
whiterabbit1983 committed Dec 21, 2024
1 parent ba86224 commit 8db396f
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 139 deletions.
61 changes: 0 additions & 61 deletions agents-api/agents_api/models/execution/count_executions.py

This file was deleted.

78 changes: 0 additions & 78 deletions agents-api/agents_api/models/execution/get_execution.py

This file was deleted.

39 changes: 39 additions & 0 deletions agents-api/agents_api/queries/executions/count_executions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from typing import Any, TypeVar
from uuid import UUID

import sqlvalidator
from beartype import beartype

from ..utils import (
pg_query,
wrap_in_class,
)

ModelT = TypeVar("ModelT", bound=Any)
T = TypeVar("T")

sql_query = sqlvalidator.parse(
"""
SELECT COUNT(*) FROM executions
WHERE
developer_id = $1
AND task_id = $2
"""
)

# @rewrap_exceptions(
# {
# QueryException: partialclass(HTTPException, status_code=400),
# ValidationError: partialclass(HTTPException, status_code=400),
# TypeError: partialclass(HTTPException, status_code=400),
# }
# )
@wrap_in_class(dict, one=True)
@pg_query
@beartype
def count_executions(
*,
developer_id: UUID,
task_id: UUID,
) -> tuple[list[str], dict]:
return (sql_query.format(), [developer_id, task_id])
52 changes: 52 additions & 0 deletions agents-api/agents_api/queries/executions/get_execution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from typing import Any, TypeVar
from uuid import UUID

from beartype import beartype

import sqlvalidator
from ...autogen.openapi_model import Execution
from ..utils import (
pg_query,
wrap_in_class,
)
from .constants import OUTPUT_UNNEST_KEY

ModelT = TypeVar("ModelT", bound=Any)
T = TypeVar("T")

sql_query = sqlvalidator.parse("""
SELECT * FROM executions
WHERE
execution_id = $1
LIMIT 1
""")


# @rewrap_exceptions(
# {
# AssertionError: partialclass(HTTPException, status_code=404),
# QueryException: partialclass(HTTPException, status_code=400),
# ValidationError: partialclass(HTTPException, status_code=400),
# TypeError: partialclass(HTTPException, status_code=400),
# }
# )
@wrap_in_class(
Execution,
one=True,
transform=lambda d: {
**d,
"output": d["output"][OUTPUT_UNNEST_KEY]
if isinstance(d["output"], dict) and OUTPUT_UNNEST_KEY in d["output"]
else d["output"],
},
)
@pg_query
@beartype
def get_execution(
*,
execution_id: UUID,
) -> tuple[str, dict]:
return (
sql_query.format(),
[execution_id],
)

0 comments on commit 8db396f

Please sign in to comment.