mirror of https://github.com/Mai-with-u/MaiBot.git
清理过期的记录
parent
1c4b2839c7
commit
2a1e785a66
|
|
@ -51,8 +51,15 @@ class ToolHistoryManager:
|
||||||
|
|
||||||
def _clean_expired_records(self):
|
def _clean_expired_records(self):
|
||||||
"""清理已过期的记录"""
|
"""清理已过期的记录"""
|
||||||
|
original_count = len(self._history)
|
||||||
self._history = [record for record in self._history if record.get("ttl_count", 0) < record.get("ttl", 5)]
|
self._history = [record for record in self._history if record.get("ttl_count", 0) < record.get("ttl", 5)]
|
||||||
|
cleaned_count = original_count - len(self._history)
|
||||||
|
|
||||||
|
if cleaned_count > 0:
|
||||||
|
logger.info(f"清理了 {cleaned_count} 条过期的工具历史记录,剩余 {len(self._history)} 条")
|
||||||
self._save_history()
|
self._save_history()
|
||||||
|
else:
|
||||||
|
logger.debug("没有需要清理的过期工具历史记录")
|
||||||
|
|
||||||
def record_tool_call(self,
|
def record_tool_call(self,
|
||||||
tool_name: str,
|
tool_name: str,
|
||||||
|
|
@ -77,6 +84,9 @@ class ToolHistoryManager:
|
||||||
if not global_config.tool.history.enable_history or ttl <= 0:
|
if not global_config.tool.history.enable_history or ttl <= 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# 先清理过期记录
|
||||||
|
self._clean_expired_records()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 创建记录
|
# 创建记录
|
||||||
record = {
|
record = {
|
||||||
|
|
@ -190,6 +200,8 @@ class ToolHistoryManager:
|
||||||
Returns:
|
Returns:
|
||||||
符合条件的历史记录列表
|
符合条件的历史记录列表
|
||||||
"""
|
"""
|
||||||
|
# 先清理过期记录
|
||||||
|
self._clean_expired_records()
|
||||||
def _parse_time(time_str: Optional[Union[datetime, str]]) -> Optional[datetime]:
|
def _parse_time(time_str: Optional[Union[datetime, str]]) -> Optional[datetime]:
|
||||||
if isinstance(time_str, datetime):
|
if isinstance(time_str, datetime):
|
||||||
return time_str
|
return time_str
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue