feat:增加一个定时清理任务
This commit is contained in:
2
.env
2
.env
@@ -5,6 +5,6 @@ MODEL_BASE_URL=https://api.deepseek.com
|
||||
#模型名称
|
||||
MODEL_NAME=deepseek-chat
|
||||
#放行host地址
|
||||
DJANGO_ALLOWED_HOSTS=192.168.237.130,127.0.0.1,10.212.26.136
|
||||
DJANGO_ALLOWED_HOSTS=192.168.237.130,127.0.0.1,172.20.10.10
|
||||
#是否开启debug模式
|
||||
DJANGO_DEBUG_ENABLE=True
|
||||
@@ -1,4 +1,5 @@
|
||||
Django==5.2.1
|
||||
requests==2.32.3
|
||||
python-decouple==3.8
|
||||
gunicorn==23.0.0
|
||||
gunicorn==23.0.0
|
||||
APScheduler==3.11.0
|
||||
@@ -3,6 +3,7 @@ from datetime import datetime
|
||||
import requests, json
|
||||
from django.db.models.expressions import result
|
||||
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from .openai_client import call_openai_api
|
||||
from decouple import config
|
||||
import threading, re
|
||||
@@ -11,6 +12,10 @@ from ..tools import getinfo, params_filter
|
||||
MODEL_NAME = config('MODEL_NAME', default="")
|
||||
BASE_URL = config('MODEL_BASE_URL', default="")
|
||||
|
||||
'''
|
||||
解析时间,转化为时间戳
|
||||
'''
|
||||
|
||||
|
||||
def parse_time(time_str: str) -> int:
|
||||
try:
|
||||
@@ -21,6 +26,11 @@ def parse_time(time_str: str) -> int:
|
||||
return int(datetime.now().timestamp())
|
||||
|
||||
|
||||
'''
|
||||
判断是否为json格式
|
||||
'''
|
||||
|
||||
|
||||
def is_json(myjson):
|
||||
try:
|
||||
json_object = json.loads(myjson)
|
||||
@@ -29,6 +39,11 @@ def is_json(myjson):
|
||||
return False
|
||||
|
||||
|
||||
'''
|
||||
查询会议室信息
|
||||
'''
|
||||
|
||||
|
||||
def query_room_info(params) -> str:
|
||||
# resp = requests.get('http://127.0.0.1:8000/myapi/room/')
|
||||
"""
|
||||
@@ -102,6 +117,11 @@ def check_and_process_think(content: str) -> str:
|
||||
return filtered_text
|
||||
|
||||
|
||||
'''
|
||||
初始提示词构建
|
||||
'''
|
||||
|
||||
|
||||
def build_prompt(params):
|
||||
"""构建增强提示词"""
|
||||
# 获取可用会议室信息
|
||||
@@ -158,6 +178,10 @@ class DialogManager:
|
||||
def get_history(self, session_id: str) -> list:
|
||||
return self.dialogs.get(session_id, [])
|
||||
|
||||
def clear_history(self):
|
||||
print('开始定时执行清理历史消息')
|
||||
self.dialogs.clear()
|
||||
|
||||
def add_message(self, session_id, role, content):
|
||||
with self.lock:
|
||||
if session_id not in self.dialogs:
|
||||
@@ -208,7 +232,10 @@ class DialogManager:
|
||||
|
||||
|
||||
dialog_manager = DialogManager()
|
||||
|
||||
scheduler = BackgroundScheduler()
|
||||
# 每天凌晨1点执行任务,清理缓存中的历史消息
|
||||
scheduler.add_job(dialog_manager.clear_history, 'cron', hour=1)
|
||||
scheduler.start()
|
||||
'''
|
||||
异步添加上下文处理信息
|
||||
'''
|
||||
@@ -239,12 +266,12 @@ def process_book_room(data, params) -> str:
|
||||
'''
|
||||
|
||||
|
||||
def process_query_book_room(data, params) -> str:
|
||||
result = query_booking_info(params)
|
||||
def process_query_book_room(**kwargs) -> str:
|
||||
result = query_booking_info(params=kwargs['params'])
|
||||
book_promot = f'''
|
||||
系统调用API查询已经预订的会议室的结果如下:
|
||||
系统调用API查询当前租户下已经预订的会议室的结果如下:
|
||||
{result}
|
||||
请帮用户解析已有的会议室的结果,并根据结果给予用户相应自然语言反馈
|
||||
请帮用户解析已有的预订会议室的结果,并根据结果给予用户相应自然语言反馈
|
||||
'''
|
||||
return book_promot
|
||||
|
||||
|
||||
Reference in New Issue
Block a user