Browse Source

feat: - 优化

zhangwl 2 weeks ago
parent
commit
e503cf47c4
3 changed files with 13 additions and 10 deletions
  1. 9 8
      app/db/tencent_im.py
  2. 2 0
      app/routers/chat_tools.py
  3. 2 2
      requirements.txt

+ 9 - 8
app/db/tencent_im.py

@@ -25,10 +25,10 @@ TENCENT_IM_SECRET_KEY = os.getenv("TENCENT_IM_SECRET_KEY")
 class TencentIMClient:
 class TencentIMClient:
     """腾讯云IM API客户端"""
     """腾讯云IM API客户端"""
 
 
-    def __init__(self, app_id: str = None, admin_id: str = None, secret_key: str = None):
-        self.app_id = app_id or TENCENT_IM_APP_ID
-        self.admin_id = admin_id or TENCENT_IM_ADMIN_ID
-        self.secret_key = secret_key or TENCENT_IM_SECRET_KEY
+    def __init__(self):
+        self.app_id =  TENCENT_IM_APP_ID
+        self.admin_id =  TENCENT_IM_ADMIN_ID
+        self.secret_key =  TENCENT_IM_SECRET_KEY
 
 
         if not all([self.app_id, self.admin_id, self.secret_key]):
         if not all([self.app_id, self.admin_id, self.secret_key]):
             print("警告:腾讯云IM配置不完整,请检查环境变量")
             print("警告:腾讯云IM配置不完整,请检查环境变量")
@@ -300,14 +300,15 @@ class TencentIMClient:
                     "msg_seq": msg.get("MsgSeq", 0),
                     "msg_seq": msg.get("MsgSeq", 0),
                 })
                 })
 
 
-        # 按时间升序排列(最早的在前)
-        formatted.sort(key=lambda x: x["timestamp"])
-
         # 过滤最近30分钟的消息
         # 过滤最近30分钟的消息
         current_time = int(time.time())
         current_time = int(time.time())
-        time_threshold = current_time - 1800  # 30分钟 = 1800秒
+        time_threshold = current_time - 7200  # 30分钟 = 1800秒
         formatted = [msg for msg in formatted if msg["timestamp"] >= time_threshold]
         formatted = [msg for msg in formatted if msg["timestamp"] >= time_threshold]
 
 
+        # 按时间升序排列(最早的在前)
+        formatted.sort(key=lambda x: x["timestamp"])
+
+
         return formatted
         return formatted
 
 
 
 

+ 2 - 0
app/routers/chat_tools.py

@@ -674,6 +674,8 @@ async def entrepreneur_chat(request: RoleBasedChatRequest):
         if knowledge_id:
         if knowledge_id:
             tools += get_knowledge_search_tools(knowledge_id)
             tools += get_knowledge_search_tools(knowledge_id)
 
 
+        print("----最终的提示词----")
+        print(api_messages)
         # 调用 AI 客户端
         # 调用 AI 客户端
         response = client.responses.create(
         response = client.responses.create(
             model=Config.MODEL_NAME,
             model=Config.MODEL_NAME,

+ 2 - 2
requirements.txt

@@ -14,5 +14,5 @@ openai==2.30.0
 tls-sig-api-v2==1.1
 tls-sig-api-v2==1.1
 python-multipart==0.0.32
 python-multipart==0.0.32
 websockets>=12.0
 websockets>=12.0
-llama-index-core==0.14.25
-Jinja2==3.1.6
+#llama-index-core==0.14.25
+#Jinja2==3.1.6