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]: """获取会话"""