fix: 修复CozeService初始化时get_bot_config缺少参数的问题
Some checks failed
continuous-integration/drone/push Build is failing
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:
@@ -43,13 +43,16 @@ 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
|
||||
) -> CreateSessionResponse:
|
||||
@@ -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]:
|
||||
"""获取会话"""
|
||||
|
||||
Reference in New Issue
Block a user