Skip to content

Commit

Permalink
fix(deriver and dialectic) Use latest user level user_represenation
Browse files Browse the repository at this point in the history
  • Loading branch information
VVoruganti committed Nov 14, 2024
1 parent c9da341 commit 9c99cdc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ async def get_latest_user_representation(
.where(models.App.public_id == app_id)
.where(models.User.public_id == user_id)
.where(models.Metamessage.metamessage_type == "user_representation")
.order_by(models.Metamessage.id.desc()) # get the most recent
.limit(1)
)
result = await db.execute(stmt)
Expand Down
4 changes: 2 additions & 2 deletions src/deriver/__main__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio
import argparse

import uvloop

from .queue import main

if __name__ == "__main__":
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
asyncio.run(main())
asyncio.run(main())

18 changes: 15 additions & 3 deletions src/deriver/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,26 @@ async def process_user_message(
f"Tom Inference: {tom_inference_metamessage.content}", style="orange1"
)

# Fetch the existing user representation
# Fetch the latest user representation
user_representation_stmt = (
select(models.Metamessage)
.where(models.Metamessage.message_id == ai_message.public_id)
.join(
models.Message,
models.Message.public_id == models.Metamessage.message_id,
)
.join(
models.Session,
models.Message.session_id == models.Session.public_id,
)
.join(models.User, models.User.public_id == models.Session.user_id)
.join(models.App, models.App.public_id == models.User.app_id)
.where(models.App.public_id == app_id)
.where(models.User.public_id == user_id)
.where(models.Metamessage.metamessage_type == "user_representation")
.order_by(models.Metamessage.id.desc())
.order_by(models.Metamessage.id.desc()) # get the most recent
.limit(1)
)

response = await db.execute(user_representation_stmt)
existing_representation = response.scalar_one_or_none()

Expand Down
2 changes: 1 addition & 1 deletion src/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
String,
UniqueConstraint,
)
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.dialects.postgresql import JSONB, TEXT
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy.sql import func

Expand Down

0 comments on commit 9c99cdc

Please sign in to comment.