fix: 修复CozeService初始化时get_bot_config缺少参数的问题
Some checks failed
continuous-integration/drone/push Build is failing

- 移除 __init__ 中对 get_bot_config() 的无参数调用
- 改为在需要时根据 session_type 动态获取 bot_config
- 修复 _get_bot_id_by_type 方法使用正确的配置获取方式
This commit is contained in:
yuliang_guo
2026-02-02 13:21:00 +08:00
parent 5156cbf4d2
commit 82f8e6596c

View File

@@ -43,12 +43,15 @@ class CozeService:
def __init__(self): def __init__(self):
self.client = get_coze_client() self.client = get_coze_client()
self.bot_config = get_bot_config()
self.workspace_id = get_workspace_id() self.workspace_id = get_workspace_id()
# 内存中的会话存储(生产环境应使用 Redis # 内存中的会话存储(生产环境应使用 Redis
self._sessions: Dict[str, CozeSession] = {} self._sessions: Dict[str, CozeSession] = {}
self._messages: Dict[str, List[CozeMessage]] = {} 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( async def create_session(
self, request: CreateSessionRequest self, request: CreateSessionRequest
@@ -211,12 +214,15 @@ class CozeService:
def _get_bot_id_by_type(self, session_type: SessionType) -> str: def _get_bot_id_by_type(self, session_type: SessionType) -> str:
"""根据会话类型获取 Bot ID""" """根据会话类型获取 Bot ID"""
mapping = { # 将 SessionType 枚举映射到配置字符串
SessionType.COURSE_CHAT: self.bot_config["course_chat"], type_mapping = {
SessionType.TRAINING: self.bot_config["training"], SessionType.COURSE_CHAT: "course_chat",
SessionType.EXAM: self.bot_config["exam"], 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]: def _get_session(self, session_id: str) -> Optional[CozeSession]:
"""获取会话""" """获取会话"""