Explorar el Código

Update push_service: add record to database

StrayWarrior hace 3 semanas
padre
commit
6c294263cc
Se han modificado 1 ficheros con 8 adiciones y 0 borrados
  1. 8 0
      pqai_agent/push_service.py

+ 8 - 0
pqai_agent/push_service.py

@@ -14,6 +14,7 @@ from rocketmq import ClientConfiguration, Credentials, SimpleConsumer, FilterExp
 from pqai_agent import configs
 from pqai_agent.agents.message_push_agent import MessagePushAgent, DummyMessagePushAgent
 from pqai_agent.configs import apollo_config
+from pqai_agent.data_models.agent_push_record import AgentPushRecord
 from pqai_agent.logging_service import logger
 from pqai_agent.message import MessageType
 
@@ -152,6 +153,13 @@ class PushTaskWorkerPool:
                     recent_dialogue, content, enable_random=True)
             response = agent.generate_response(content)
             if response:
+                with self.agent_service.AgentDBSession() as session:
+                    msg_list = [{'type': MessageType.TEXT.value, 'content': response}]
+                    record = AgentPushRecord(staff_id=staff_id, user_id=user_id,
+                                             content=json.dumps(msg_list, ensure_ascii=False),
+                                             timestamp=int(datetime.now().timestamp()))
+                    session.add(record)
+                    session.commit()
                 self.agent_service.send_response(staff_id, user_id, response, message_type, skip_check=True)
             else:
                 logger.debug(f"staff[{staff_id}], user[{user_id}]: generate empty response")