|
@@ -1,7 +1,7 @@
|
|
#! /usr/bin/env python
|
|
#! /usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
# -*- coding: utf-8 -*-
|
|
# vim:fenc=utf-8
|
|
# vim:fenc=utf-8
|
|
-
|
|
|
|
|
|
+import re
|
|
import sys
|
|
import sys
|
|
import time
|
|
import time
|
|
import random
|
|
import random
|
|
@@ -178,8 +178,8 @@ class AgentService:
|
|
"""处理LLM响应"""
|
|
"""处理LLM响应"""
|
|
chat_config = agent.build_chat_configuration(user_message, self.chat_service_type)
|
|
chat_config = agent.build_chat_configuration(user_message, self.chat_service_type)
|
|
logger.debug(chat_config)
|
|
logger.debug(chat_config)
|
|
- # FIXME(zhoutian): 临时处理去除头尾的空格
|
|
|
|
- chat_response = self._call_chat_api(chat_config).strip()
|
|
|
|
|
|
+ chat_response = self._call_chat_api(chat_config)
|
|
|
|
+ chat_response = self.sanitize_response(chat_response)
|
|
|
|
|
|
if response := agent.generate_response(chat_response):
|
|
if response := agent.generate_response(chat_response):
|
|
logger.warning(f"staff[{agent.staff_id}] user[{user_id}]: response: {response}")
|
|
logger.warning(f"staff[{agent.staff_id}] user[{user_id}]: response: {response}")
|
|
@@ -217,6 +217,13 @@ class AgentService:
|
|
raise Exception('Unsupported chat service type: {}'.format(self.chat_service_type))
|
|
raise Exception('Unsupported chat service type: {}'.format(self.chat_service_type))
|
|
return response
|
|
return response
|
|
|
|
|
|
|
|
+ @staticmethod
|
|
|
|
+ def sanitize_response(response: str):
|
|
|
|
+ pattern = r'\[?\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\]?'
|
|
|
|
+ response = re.sub(pattern, '', response)
|
|
|
|
+ response = response.strip()
|
|
|
|
+ return response
|
|
|
|
+
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
config = configs.get()
|
|
config = configs.get()
|
|
logging_service.setup_root_logger()
|
|
logging_service.setup_root_logger()
|