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

fix: Merge agent and user metadata #204

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 17 additions & 3 deletions agents-api/agents_api/models/agent/patch_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def patch_agent_query(
"""
# Construct the query for updating agent information in the database.
# Agent update query
metadata = update_data.pop("metadata", {})
agent_update_cols, agent_update_vals = cozo_process_mutate_data(
{
**{k: v for k, v in update_data.items() if v is not None},
creatorrr marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -38,10 +39,18 @@ def patch_agent_query(
agent_update_query = f"""
{{
# update the agent
?[{agent_update_cols}] <- $agent_update_vals
input[{agent_update_cols}] <- $agent_update_vals

?[{agent_update_cols}, metadata] :=
input[{agent_update_cols}],
*agents {{
agent_id: to_uuid($agent_id),
metadata: md,
}},
metadata = concat(md, $metadata)
creatorrr marked this conversation as resolved.
Show resolved Hide resolved

:update agents {{
{agent_update_cols}
{agent_update_cols}, metadata,
}}
:returning
}}
Expand Down Expand Up @@ -78,5 +87,10 @@ def patch_agent_query(

return client.run(
combined_query,
{"agent_update_vals": agent_update_vals, "settings_vals": settings_vals},
{
"agent_update_vals": agent_update_vals,
"settings_vals": settings_vals,
"metadata": metadata,
"agent_id": str(agent_id),
},
)
22 changes: 19 additions & 3 deletions agents-api/agents_api/models/user/patch_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

def patch_user_query(developer_id: UUID, user_id: UUID, **update_data) -> pd.DataFrame:
# Prepare data for mutation by filtering out None values and adding system-generated fields.
metadata = update_data.pop("metadata", {})
user_update_cols, user_update_vals = cozo_process_mutate_data(
{
**{k: v for k, v in update_data.items() if v is not None},
creatorrr marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -36,12 +37,27 @@ def patch_user_query(developer_id: UUID, user_id: UUID, **update_data) -> pd.Dat
# Construct the datalog query for updating user information.
query = f"""
# update the user
?[{user_update_cols}] <- $user_update_vals
input[{user_update_cols}] <- $user_update_vals

?[{user_update_cols}, metadata] :=
input[{user_update_cols}],
*users {{
user_id: to_uuid($user_id),
metadata: md,
}},
metadata = concat(md, $metadata)
creatorrr marked this conversation as resolved.
Show resolved Hide resolved

:update users {{
{user_update_cols}
{user_update_cols}, metadata
}}
:returning
"""

return client.run(query, {"user_update_vals": user_update_vals})
return client.run(
query,
{
"user_update_vals": user_update_vals,
"metadata": metadata,
"user_id": str(user_id),
},
)
Loading