Improve realistic message delays
This commit is contained in:
@@ -156,13 +156,13 @@ class HandleMessage(Command):
|
||||
custom_author="USER" if is_from_bot else None
|
||||
)
|
||||
|
||||
# Manage truncation & summarization
|
||||
await truncate_and_summarize(chat_session, manip.ai)
|
||||
|
||||
# Use chat session summary for context
|
||||
log.info("Fetching stored messages")
|
||||
stored_messages = await sync_to_async(list)(
|
||||
Message.objects.filter(session=chat_session).order_by("ts")
|
||||
Message.objects.filter(session=chat_session, user=chat_session.user).order_by("ts")
|
||||
)
|
||||
log.info("Fetched stored messages")
|
||||
|
||||
# recent_chat_history = "\n".join(
|
||||
# f"[{msg.ts}] {msg.text}" for msg in reversed(stored_messages)
|
||||
# )
|
||||
@@ -178,8 +178,10 @@ class HandleMessage(Command):
|
||||
now = timezone.now()
|
||||
chat_session.identifier.person.last_interaction = now
|
||||
chat_session.last_interaction = now
|
||||
log.info("Updating time")
|
||||
await sync_to_async(chat_session.identifier.person.save)()
|
||||
await sync_to_async(chat_session)()
|
||||
await sync_to_async(chat_session.save)()
|
||||
log.info("Updated time")
|
||||
reply = True # ✅ Bot replies
|
||||
|
||||
# 🔵 CASE 2: Incoming message (Someone else messages the bot)
|
||||
@@ -188,7 +190,7 @@ class HandleMessage(Command):
|
||||
chat_session.identifier.person.last_interaction = now
|
||||
chat_session.last_interaction = now
|
||||
await sync_to_async(chat_session.identifier.person.save)()
|
||||
await sync_to_async(chat_session)()
|
||||
await sync_to_async(chat_session.save)()
|
||||
reply = True # ✅ Bot replies
|
||||
|
||||
# 🔴 CASE 3: Outgoing message (Bot messages someone else)
|
||||
@@ -203,17 +205,18 @@ class HandleMessage(Command):
|
||||
if reply:
|
||||
if manip.send_enabled:
|
||||
prompt = gen_prompt(msg, person_identifier.person, manip, chat_history)
|
||||
log.info("Running context prompt")
|
||||
result = await run_context_prompt(c, prompt, manip.ai)
|
||||
# Store bot's AI response with a +1s timestamp
|
||||
await sync_to_async(Message.objects.create)(
|
||||
user=chat_session.user,
|
||||
session=chat_session,
|
||||
custom_author="BOT",
|
||||
text=result,
|
||||
ts=ts + 1,
|
||||
)
|
||||
await natural_send_message(c, result)
|
||||
log.info("Storing generated message")
|
||||
|
||||
log.info("Stored generated message")
|
||||
await natural_send_message(chat_session, ts, c, result)
|
||||
log.info("Sent message")
|
||||
#await c.send(result)
|
||||
|
||||
# Manage truncation & summarization
|
||||
await truncate_and_summarize(chat_session, manip.ai)
|
||||
# END FOR
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user