diff --git a/astrbot/core/core_lifecycle.py b/astrbot/core/core_lifecycle.py index 3655e55ee..ddb285cc9 100644 --- a/astrbot/core/core_lifecycle.py +++ b/astrbot/core/core_lifecycle.py @@ -92,6 +92,8 @@ class AstrBotCoreLifecycle: self.event_queue.closed = True for task in self.curr_tasks: task.cancel() + + await self.provider_manager.terminate() for task in self.curr_tasks: try: diff --git a/astrbot/core/provider/manager.py b/astrbot/core/provider/manager.py index 20ac8a0d0..ea90470db 100644 --- a/astrbot/core/provider/manager.py +++ b/astrbot/core/provider/manager.py @@ -65,4 +65,9 @@ class ProviderManager(): logger.warning("未启用任何大模型提供商适配器。") def get_insts(self): - return self.provider_insts \ No newline at end of file + return self.provider_insts + + async def terminate(self): + for provider_inst in self.provider_insts: + if hasattr(provider_inst, "terminate"): + await provider_inst.terminate() \ No newline at end of file diff --git a/astrbot/core/provider/sources/dify_source.py b/astrbot/core/provider/sources/dify_source.py index 64755c968..4ee1897e6 100644 --- a/astrbot/core/provider/sources/dify_source.py +++ b/astrbot/core/provider/sources/dify_source.py @@ -127,3 +127,6 @@ class ProviderDify(Provider): async def get_human_readable_context(self, session_id, page, page_size): raise Exception("暂不支持获得 Dify 的历史消息记录。") + + async def terminate(self): + await self.api_client.close() \ No newline at end of file