🤖 自动格式化代码 [skip ci]

This commit is contained in:
github-actions[bot]
2025-04-23 15:37:28 +00:00
parent c4499829a6
commit 1b380ff131
9 changed files with 160 additions and 134 deletions

View File

@@ -73,10 +73,7 @@ class HeartFChatting:
现在由其关联的 SubHeartflow 管理生命周期。
"""
def __init__(
self,
chat_id: str
):
def __init__(self, chat_id: str):
"""
HeartFChatting 初始化函数
@@ -195,7 +192,7 @@ class HeartFChatting:
# 检查是否满足启动条件:未激活且计时器有时间
if not self._loop_active and self._loop_timer > 0:
should_start_loop = True
self._loop_active = True # 在锁内标记为活动,防止重复启动
self._loop_active = True # 在锁内标记为活动,防止重复启动
if should_start_loop:
# 检查是否已有任务在运行(理论上不应该,因为 _loop_active=False
@@ -206,8 +203,8 @@ class HeartFChatting:
# 等待旧任务确实被取消
await asyncio.wait_for(self._loop_task, timeout=0.5)
except (asyncio.CancelledError, asyncio.TimeoutError):
pass # 忽略取消或超时错误
self._loop_task = None # 清理旧任务引用
pass # 忽略取消或超时错误
self._loop_task = None # 清理旧任务引用
logger.info(f"{log_prefix} 计时器 > 0 且循环未激活,启动主循环...")
# 创建新的循环任务
@@ -215,7 +212,7 @@ class HeartFChatting:
# 添加完成回调
self._loop_task.add_done_callback(self._handle_loop_completion)
# else:
# logger.trace(f"{log_prefix} 不需要启动循环已激活或计时器为0") # 可以取消注释以进行调试
# logger.trace(f"{log_prefix} 不需要启动循环已激活或计时器为0") # 可以取消注释以进行调试
def _handle_loop_completion(self, task: asyncio.Task):
"""当 _run_pf_loop 任务完成时执行的回调。"""

View File

@@ -69,7 +69,6 @@ class HeartFCProcessor:
subheartflow = await heartflow.create_subheartflow(chat.stream_id)
message.update_chat_stream(chat)
await heartflow.create_subheartflow(chat.stream_id)

View File

@@ -349,7 +349,7 @@ class NormalChat:
return False
# 改为实例方法, 移除 chat 参数
async def start_chat(self):
"""为此 NormalChat 实例关联的 ChatStream 启动聊天任务(如果尚未运行)。"""
if self._chat_task is None or self._chat_task.done():
@@ -358,7 +358,6 @@ class NormalChat:
task.add_done_callback(lambda t: self._handle_task_completion(t)) # 回调现在是实例方法
self._chat_task = task
# 改为实例方法, 移除 stream_id 参数
def _handle_task_completion(self, task: asyncio.Task):
"""兴趣监控任务完成时的回调函数。"""
@@ -403,4 +402,3 @@ class NormalChat:
# 确保任务状态更新,即使等待出错 (回调函数也会尝试更新)
if self._chat_task is task:
self._chat_task = None

View File

@@ -148,7 +148,9 @@ class MessageServer(BaseMessageHandler):
if self.own_app:
# 如果使用自己的 FastAPI 实例,运行 uvicorn 服务器
# 禁用 uvicorn 默认日志和访问日志
config = uvicorn.Config(self.app, host=self.host, port=self.port, loop="asyncio", log_config=None, access_log=False)
config = uvicorn.Config(
self.app, host=self.host, port=self.port, loop="asyncio", log_config=None, access_log=False
)
self.server = uvicorn.Server(config)
await self.server.serve()
else: