feat: use expire dict

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
This commit is contained in:
yihong0618
2024-06-14 18:55:20 +08:00
parent bc3ecdb9f8
commit 785b75e994
13 changed files with 127 additions and 37 deletions

View File

@ -1,8 +1,8 @@
from os import environ
import time
from telebot import TeleBot
from telebot.types import Message
from expiringdict import ExpiringDict
from . import *
@ -22,8 +22,10 @@ if DIFY_API_KEY:
client = ChatClient(api_key=DIFY_API_KEY)
# Global history cache
dify_player_dict = {}
dify_player_c = {} # History cache is supported by dify cloud conversation_id.
dify_player_dict = ExpiringDict(max_len=1000, max_age_seconds=300)
dify_player_c = ExpiringDict(
max_len=1000, max_age_seconds=300
) # History cache is supported by dify cloud conversation_id.
def dify_handler(message: Message, bot: TeleBot) -> None: