Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
whiterabbit1983 committed May 22, 2024
1 parent e77381e commit c05113f
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions agents-api/agents_api/activities/summarization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

import asyncio
from uuid import UUID
from typing import Callable
from textwrap import dedent
Expand All @@ -10,6 +11,7 @@
entries_summarization_query,
)
from agents_api.common.protocol.entries import Entry
from agents_api.rec_sum import summarize_messages, get_entities, trim_messages
from ..env import summarization_model_name


Expand Down Expand Up @@ -176,3 +178,40 @@ async def summarization(session_id: str) -> None:
new_entry=new_entry,
old_entry_ids=[e.id for e in entries],
)


# TODO: rename and remove the old one
@activity.defn
async def summarization_new(session_id: str) -> None:
session_id = UUID(session_id)
entries = [row for _, row in get_toplevel_entries_query(session_id=session_id).iterrows()]

assert len(entries) > 0, "no need to summarize on empty entries list"

trimmed_messages, entities = await asyncio.gather(
trim_messages(entries),
get_entities(entries),
)

summarized = await summarize_messages(trimmed_messages)

for msg in summarized:
# response = await run_prompt(
# dialog=entries, previous_memories=[], model=summarization_model_name
# )

# TODO: set correct content
new_entry = Entry(
session_id=session_id,
source="summarizer",
role="system",
name="information",
content=msg,
timestamp=entries[-1].timestamp + 0.01,
)

entries_summarization_query(
session_id=session_id,
new_entry=new_entry,
old_entry_ids=[e.id for e in entries],
)

0 comments on commit c05113f

Please sign in to comment.