-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(agents-api): Fix the settings class in session data
Signed-off-by: Diwank Tomer <[email protected]>
- Loading branch information
Diwank Tomer
committed
Jul 30, 2024
1 parent
9fd1a49
commit ae2a544
Showing
3 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
agents-api/agents_api/models/execution/get_execution_transition.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from uuid import UUID, uuid4 | ||
|
||
from beartype import beartype | ||
from fastapi import HTTPException | ||
from pycozo.client import QueryException | ||
from pydantic import ValidationError | ||
|
||
from ...autogen.openapi_model import CreateTransitionRequest, Transition | ||
from ...common.utils.cozo import cozo_process_mutate_data | ||
from ..utils import ( | ||
cozo_query, | ||
partialclass, | ||
rewrap_exceptions, | ||
verify_developer_id_query, | ||
verify_developer_owns_resource_query, | ||
wrap_in_class, | ||
) | ||
|
||
|
||
@rewrap_exceptions( | ||
{ | ||
QueryException: partialclass(HTTPException, status_code=400), | ||
ValidationError: partialclass(HTTPException, status_code=400), | ||
TypeError: partialclass(HTTPException, status_code=400), | ||
} | ||
) | ||
@wrap_in_class(Transition, transform=lambda d: {"id": d["transition_id"], **d}) | ||
@cozo_query | ||
@beartype | ||
def create_execution_transition( | ||
*, | ||
developer_id: UUID, | ||
execution_id: UUID, | ||
transition_id: UUID | None = None, | ||
data: CreateTransitionRequest, | ||
task_token: str | None = None, | ||
) -> tuple[str, dict]: | ||
transition_id = transition_id or uuid4() | ||
|
||
data.metadata = data.metadata or {} | ||
data.execution_id = execution_id | ||
|
||
transition_data = data.model_dump(exclude_unset=True) | ||
columns, values = cozo_process_mutate_data( | ||
{ | ||
**transition_data, | ||
"task_token": task_token, | ||
"transition_id": str(transition_id), | ||
"execution_id": str(execution_id), | ||
} | ||
) | ||
|
||
insert_query = f""" | ||
?[{columns}] <- $values | ||
:insert transitions {{ | ||
{columns} | ||
}} | ||
:returning | ||
""" | ||
|
||
queries = [ | ||
verify_developer_id_query(developer_id), | ||
verify_developer_owns_resource_query( | ||
developer_id, | ||
"executions", | ||
execution_id=execution_id, | ||
parents=[("agents", "agent_id"), ("tasks", "task_id")], | ||
), | ||
insert_query, | ||
] | ||
|
||
query = "}\n\n{\n".join(queries) | ||
query = f"{{ {query} }}" | ||
|
||
return (query, {"values": values}) |
77 changes: 77 additions & 0 deletions
77
agents-api/agents_api/models/execution/update_execution_transition.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from uuid import UUID, uuid4 | ||
|
||
from beartype import beartype | ||
from fastapi import HTTPException | ||
from pycozo.client import QueryException | ||
from pydantic import ValidationError | ||
|
||
from ...autogen.openapi_model import CreateTransitionRequest, Transition | ||
from ...common.utils.cozo import cozo_process_mutate_data | ||
from ..utils import ( | ||
cozo_query, | ||
partialclass, | ||
rewrap_exceptions, | ||
verify_developer_id_query, | ||
verify_developer_owns_resource_query, | ||
wrap_in_class, | ||
) | ||
|
||
|
||
@rewrap_exceptions( | ||
{ | ||
QueryException: partialclass(HTTPException, status_code=400), | ||
ValidationError: partialclass(HTTPException, status_code=400), | ||
TypeError: partialclass(HTTPException, status_code=400), | ||
} | ||
) | ||
@wrap_in_class(Transition, transform=lambda d: {"id": d["transition_id"], **d}) | ||
@cozo_query | ||
@beartype | ||
def create_execution_transition( | ||
*, | ||
developer_id: UUID, | ||
execution_id: UUID, | ||
transition_id: UUID | None = None, | ||
data: CreateTransitionRequest, | ||
task_token: str | None = None, | ||
) -> tuple[str, dict]: | ||
transition_id = transition_id or uuid4() | ||
|
||
data.metadata = data.metadata or {} | ||
data.execution_id = execution_id | ||
|
||
transition_data = data.model_dump(exclude_unset=True) | ||
columns, values = cozo_process_mutate_data( | ||
{ | ||
**transition_data, | ||
"task_token": task_token, | ||
"transition_id": str(transition_id), | ||
"execution_id": str(execution_id), | ||
} | ||
) | ||
|
||
insert_query = f""" | ||
?[{columns}] <- $values | ||
:insert transitions {{ | ||
{columns} | ||
}} | ||
:returning | ||
""" | ||
|
||
queries = [ | ||
verify_developer_id_query(developer_id), | ||
verify_developer_owns_resource_query( | ||
developer_id, | ||
"executions", | ||
execution_id=execution_id, | ||
parents=[("agents", "agent_id"), ("tasks", "task_id")], | ||
), | ||
insert_query, | ||
] | ||
|
||
query = "}\n\n{\n".join(queries) | ||
query = f"{{ {query} }}" | ||
|
||
return (query, {"values": values}) |