🐛 fix error when the history_size was set to an odd number

This commit is contained in:
FuQuan233 2025-03-01 21:57:27 +08:00
parent 7408f90b3c
commit 17564b5463

View file

@ -76,7 +76,7 @@ def pop_reasoning_content(
class GroupState: class GroupState:
def __init__(self): def __init__(self):
self.preset_name = plugin_config.default_preset self.preset_name = plugin_config.default_preset
self.history = deque(maxlen=plugin_config.history_size) self.history = deque(maxlen=plugin_config.history_size * 2)
self.queue = asyncio.Queue() self.queue = asyncio.Queue()
self.processing = False self.processing = False
self.last_active = time.time() self.last_active = time.time()
@ -247,7 +247,7 @@ async def process_messages(group_id: int):
{"role": "system", "content": systemPrompt} {"role": "system", "content": systemPrompt}
] ]
messages += list(state.history)[-plugin_config.history_size :] messages += list(state.history)[-plugin_config.history_size * 2 :]
# 没有未处理的消息说明已经被处理了,跳过 # 没有未处理的消息说明已经被处理了,跳过
if state.past_events.__len__() < 1: if state.past_events.__len__() < 1:
@ -462,7 +462,7 @@ async def load_state():
state = GroupState() state = GroupState()
state.preset_name = state_data["preset"] state.preset_name = state_data["preset"]
state.history = deque( state.history = deque(
state_data["history"], maxlen=plugin_config.history_size state_data["history"], maxlen=plugin_config.history_size * 2
) )
state.last_active = state_data["last_active"] state.last_active = state_data["last_active"]
state.group_prompt = state_data["group_prompt"] state.group_prompt = state_data["group_prompt"]