fix (util): Fix save summary metamessages
This commit is contained in:
parent
7d832c0a77
commit
93ece49f96
|
|
@ -1129,6 +1129,9 @@ async def create_user_protected_collection(
|
|||
name=DEF_PROTECTED_COLLECTION_NAME,
|
||||
)
|
||||
try:
|
||||
# This will raise ResourceNotFoundException if user not found
|
||||
await get_user(db, app_id=app_id, user_id=user_id)
|
||||
|
||||
db.add(honcho_collection)
|
||||
await db.commit()
|
||||
except IntegrityError:
|
||||
|
|
|
|||
|
|
@ -51,7 +51,11 @@ async def process_item(db: AsyncSession, payload: dict):
|
|||
await process_ai_message(*processing_args)
|
||||
logger.debug(f"Finished processing message: {payload['message_id']}")
|
||||
await summarize_if_needed(
|
||||
db, payload["session_id"], payload["user_id"], payload["message_id"]
|
||||
db,
|
||||
payload["app_id"],
|
||||
payload["session_id"],
|
||||
payload["user_id"],
|
||||
payload["message_id"],
|
||||
)
|
||||
return
|
||||
|
||||
|
|
@ -147,7 +151,7 @@ async def process_user_message(
|
|||
|
||||
|
||||
async def summarize_if_needed(
|
||||
db: AsyncSession, session_id: str, user_id: str, message_id: str
|
||||
db: AsyncSession, app_id: str, session_id: str, user_id: str, message_id: str
|
||||
):
|
||||
summary_start = os.times()[4]
|
||||
logger.debug("Checking if summaries should be created")
|
||||
|
|
@ -193,6 +197,7 @@ async def summarize_if_needed(
|
|||
# Save the long summary as a metamessage and capture the returned object
|
||||
latest_long_summary = await history.save_summary_metamessage(
|
||||
db=db,
|
||||
app_id=app_id,
|
||||
user_id=user_id,
|
||||
session_id=session_id,
|
||||
message_id=message_id,
|
||||
|
|
@ -225,6 +230,7 @@ async def summarize_if_needed(
|
|||
# Save the short summary as a metamessage
|
||||
await history.save_summary_metamessage(
|
||||
db=db,
|
||||
app_id=app_id,
|
||||
user_id=user_id,
|
||||
session_id=session_id,
|
||||
message_id=message_id,
|
||||
|
|
|
|||
|
|
@ -220,6 +220,7 @@ Provide a {"comprehensive" if summary_type == SummaryType.LONG else "concise"} s
|
|||
|
||||
async def save_summary_metamessage(
|
||||
db: AsyncSession,
|
||||
app_id: str,
|
||||
user_id: str,
|
||||
session_id: str,
|
||||
message_id: str,
|
||||
|
|
@ -247,6 +248,7 @@ async def save_summary_metamessage(
|
|||
|
||||
# Create and save the metamessage
|
||||
metamessage = models.Metamessage(
|
||||
app_id=app_id,
|
||||
user_id=user_id,
|
||||
session_id=session_id,
|
||||
message_id=message_id,
|
||||
|
|
@ -389,4 +391,3 @@ def format_messages(messages: list[models.Message]) -> str:
|
|||
return "\n".join(
|
||||
[f"{'user' if msg.is_user else 'assistant'}: {msg.content}" for msg in messages]
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue