From 82f8e6596ce5d99fc85d7fa8ec62d22f1b4a885a Mon Sep 17 00:00:00 2001 From: yuliang_guo Date: Mon, 2 Feb 2026 13:21:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DCozeService=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E6=97=B6get=5Fbot=5Fconfig=E7=BC=BA=E5=B0=91?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 __init__ 中对 get_bot_config() 的无参数调用 - 改为在需要时根据 session_type 动态获取 bot_config - 修复 _get_bot_id_by_type 方法使用正确的配置获取方式 --- backend/app/services/ai/coze/service.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/backend/app/services/ai/coze/service.py b/backend/app/services/ai/coze/service.py index fed4618..ed43cc1 100644 --- a/backend/app/services/ai/coze/service.py +++ b/backend/app/services/ai/coze/service.py @@ -43,12 +43,15 @@ class CozeService: def __init__(self): self.client = get_coze_client() - self.bot_config = get_bot_config() self.workspace_id = get_workspace_id() # 内存中的会话存储(生产环境应使用 Redis) self._sessions: Dict[str, CozeSession] = {} self._messages: Dict[str, List[CozeMessage]] = {} + + def _get_bot_config(self, session_type: str) -> Dict[str, Any]: + """根据会话类型获取 Bot 配置""" + return get_bot_config(session_type) async def create_session( self, request: CreateSessionRequest @@ -211,12 +214,15 @@ class CozeService: def _get_bot_id_by_type(self, session_type: SessionType) -> str: """根据会话类型获取 Bot ID""" - mapping = { - SessionType.COURSE_CHAT: self.bot_config["course_chat"], - SessionType.TRAINING: self.bot_config["training"], - SessionType.EXAM: self.bot_config["exam"], + # 将 SessionType 枚举映射到配置字符串 + type_mapping = { + SessionType.COURSE_CHAT: "course_chat", + SessionType.TRAINING: "training", + SessionType.EXAM: "training", # 考试类型使用训练 bot } - return mapping.get(session_type, self.bot_config["training"]) + config_type = type_mapping.get(session_type, "training") + bot_config = get_bot_config(config_type) + return bot_config["bot_id"] def _get_session(self, session_id: str) -> Optional[CozeSession]: """获取会话"""