Browse Source

feat: - 增加群聊上下文(支持多模态)-仅回复最近30分钟内的内容

zhangwl 2 weeks ago
parent
commit
516777dc29
2 changed files with 9 additions and 1 deletions
  1. 7 1
      app/db/tencent_im.py
  2. 2 0
      requirements.txt

+ 7 - 1
app/db/tencent_im.py

@@ -8,6 +8,7 @@ API文档:https://cloud.tencent.com/document/product/269/2738
 
 import httpx
 import random
+import time
 from typing import List, Optional
 from dotenv import load_dotenv
 import os
@@ -17,7 +18,7 @@ load_dotenv()
 
 # 腾讯云IM配置
 TENCENT_IM_APP_ID = os.getenv("TENCENT_IM_APP_ID")
-TENCENT_IM_ADMIN_ID = os.getenv("TENCENT_IM_ADMIN_ID", "administrator")
+TENCENT_IM_ADMIN_ID = os.getenv("TENCENT_IM_ADMIN_ID")
 TENCENT_IM_SECRET_KEY = os.getenv("TENCENT_IM_SECRET_KEY")
 
 
@@ -302,6 +303,11 @@ class TencentIMClient:
         # 按时间升序排列(最早的在前)
         formatted.sort(key=lambda x: x["timestamp"])
 
+        # 过滤最近30分钟的消息
+        current_time = int(time.time())
+        time_threshold = current_time - 1800  # 30分钟 = 1800秒
+        formatted = [msg for msg in formatted if msg["timestamp"] >= time_threshold]
+
         return formatted
 
 

+ 2 - 0
requirements.txt

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