From dd517e3eb7ffd66cf738efa3b37b91757055d19c Mon Sep 17 00:00:00 2001 From: Dmitry Paramonov Date: Thu, 19 Sep 2024 15:08:52 +0300 Subject: [PATCH] fix: Add missing fields for entry --- agents-api/agents_api/activities/summarization.py | 8 +++++++- agents-api/agents_api/routers/sessions/chat.py | 2 +- agents-api/agents_api/routers/tasks/update_execution.py | 1 - 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/agents-api/agents_api/activities/summarization.py b/agents-api/agents_api/activities/summarization.py index 00a19fbe3..9c703858d 100644 --- a/agents-api/agents_api/activities/summarization.py +++ b/agents-api/agents_api/activities/summarization.py @@ -2,12 +2,13 @@ import asyncio -from uuid import UUID +from uuid import UUID, uuid4 from beartype import beartype from temporalio import activity from agents_api.autogen.openapi_model import Entry +from agents_api.common.utils.datetime import utcnow from agents_api.env import summarization_model_name from agents_api.models.entry.entries_summarization import ( entries_summarization_query, @@ -38,13 +39,18 @@ async def summarization(session_id: str) -> None: ) trimmed_messages = await trim_messages(summarized, model=summarization_model_name) ts_delta = (entries[1]["timestamp"] - entries[0]["timestamp"]) / 2 + # TODO: set tokenizer, double check token_count calculation new_entities_entry = Entry( + id=uuid4(), session_id=session_id, source="summarizer", role="system", name="entities", content=entities["content"], timestamp=entries[0]["timestamp"] + ts_delta, + token_count=sum([len(c) // 3.5 for c in entities["content"]]), + created_at=utcnow(), + tokenizer="", ) entries_summarization_query( diff --git a/agents-api/agents_api/routers/sessions/chat.py b/agents-api/agents_api/routers/sessions/chat.py index 1e222ae58..ebb7bfb8b 100644 --- a/agents-api/agents_api/routers/sessions/chat.py +++ b/agents-api/agents_api/routers/sessions/chat.py @@ -86,7 +86,7 @@ async def chat( new_messages = await render_template(new_raw_messages, variables=env) else: new_messages = new_raw_messages - + for m in past_messages: with suppress(KeyError): del m["created_at"] diff --git a/agents-api/agents_api/routers/tasks/update_execution.py b/agents-api/agents_api/routers/tasks/update_execution.py index 7b60d8bdf..08d41f6f2 100644 --- a/agents-api/agents_api/routers/tasks/update_execution.py +++ b/agents-api/agents_api/routers/tasks/update_execution.py @@ -35,7 +35,6 @@ async def update_execution( await wf_handle.cancel() case ResumeExecutionRequest(): - token_data = get_paused_execution_token( developer_id=x_developer_id, execution_id=execution_id )