加入了新的模型,使用更强的模型玩
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import pymysql
|
||||
from datetime import datetime, timedelta
|
||||
import redis
|
||||
|
||||
# 配置数据库连接
|
||||
db_config = {
|
||||
@@ -9,6 +10,9 @@ db_config = {
|
||||
'database': 'message_archive'
|
||||
}
|
||||
|
||||
# 连接到Redis
|
||||
r = redis.Redis(host='192.168.2.32', port=6379, db=0)
|
||||
|
||||
|
||||
def archive_message(group_id, timestamp_str, sender, content, message_type, attachment_url=None):
|
||||
# 连接到数据库
|
||||
@@ -41,13 +45,21 @@ def get_messages(group_id, all_contacts: dict):
|
||||
connection = pymysql.connect(**db_config)
|
||||
|
||||
try:
|
||||
with connection.cursor() as cursor:
|
||||
# 获取redis 中的上次总结时间,本次从上次开始算,弱没有,则从8小时之前开始计算
|
||||
# 生成Redis key
|
||||
key = f"{group_id}:summary_time"
|
||||
last_summary_time = r.get(key)
|
||||
if last_summary_time is None:
|
||||
# 获取当前时间并计算8小时前的时间
|
||||
current_time = datetime.now()
|
||||
eight_hours_ago = current_time - timedelta(hours=8)
|
||||
|
||||
# 转换为数据库中存储的时间格式 (假设timestamp是DATETIME类型)
|
||||
eight_hours_ago_str = eight_hours_ago.strftime('%Y-%m-%d %H:%M:%S')
|
||||
last_summary_time = eight_hours_ago.strftime('%Y-%m-%d %H:%M:%S')
|
||||
current_date = current_time.strftime('%Y-%m-%d %H:%M:%S')
|
||||
r.set(key, current_date)
|
||||
|
||||
with connection.cursor() as cursor:
|
||||
|
||||
# 执行查询,获取最近8小时的消息
|
||||
query = """
|
||||
@@ -55,7 +67,7 @@ def get_messages(group_id, all_contacts: dict):
|
||||
FROM messages
|
||||
WHERE timestamp >= %s AND message_type =1 and group_id = %s
|
||||
"""
|
||||
cursor.execute(query, (eight_hours_ago_str, group_id))
|
||||
cursor.execute(query, (last_summary_time, group_id))
|
||||
|
||||
# 提取结果并组成带逗号的字符串
|
||||
result = []
|
||||
|
||||
Reference in New Issue
Block a user