Fix bridging and refactor
This commit is contained in:
@@ -14,7 +14,7 @@ from core.models import Chat, Manipulation, PersonIdentifier, ChatSession, Messa
|
||||
import aiohttp
|
||||
from django.utils import timezone
|
||||
from django.conf import settings
|
||||
from core.lib.bot import NewSignalBot
|
||||
from core.clients.signal import NewSignalBot
|
||||
from redis import asyncio as aioredis
|
||||
|
||||
SIGNAL_URL = "signal:8080"
|
||||
@@ -102,6 +102,7 @@ class HandleMessage(Command):
|
||||
manips = await sync_to_async(list)(
|
||||
Manipulation.objects.filter(enabled=True)
|
||||
)
|
||||
processed_people = set()
|
||||
for manip in manips:
|
||||
try:
|
||||
person_identifier = await sync_to_async(PersonIdentifier.objects.get)(
|
||||
@@ -110,6 +111,10 @@ class HandleMessage(Command):
|
||||
service="signal",
|
||||
person__in=manip.group.people.all(),
|
||||
)
|
||||
# Check if we've already processed this person
|
||||
if person_identifier.person.id in processed_people:
|
||||
log.warning(f"Skipping duplicate message storage for {person_identifier.person.name}")
|
||||
continue # Skip to next manipulation
|
||||
if not manip.group.people.filter(id=person_identifier.person.id).exists():
|
||||
log.error(f"{manip.name}: Identifier {identifier_uuid} found, but person {person_identifier.person} is not in manip group. Skipping.")
|
||||
continue # Exit early if the person is not in the group
|
||||
@@ -121,6 +126,8 @@ class HandleMessage(Command):
|
||||
chat_session = await history.get_chat_session(manip.user, person_identifier)
|
||||
|
||||
# Store incoming or outgoing messages
|
||||
log.info(f"Processing history store message {text}")
|
||||
processed_people.add(person_identifier.person.id)
|
||||
await history.store_message(
|
||||
session=chat_session,
|
||||
sender=source_uuid,
|
||||
@@ -148,8 +155,7 @@ class HandleMessage(Command):
|
||||
|
||||
log.info("Running context prompt")
|
||||
result = await ai.run_prompt(prompt, manip.ai)
|
||||
# Store bot's AI response with a +1s timestamp
|
||||
if manip.mode == "active":
|
||||
# Store bot's AI response with a +1s timestamp if manip.mode == "active":
|
||||
await history.store_own_message(
|
||||
session=chat_session,
|
||||
text=result,
|
||||
|
||||
Reference in New Issue
Block a user