新增 Mattermost 渠道完整实现,包含适配器核心、消息处理、交互回调、命令支持、安全校验、多账号管理等功能,支持机器人消息发送、交互按钮、命令注册、投票功能以及配置动态修改等特性。
90 lines
2.7 KiB
Python
90 lines
2.7 KiB
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
|
|
|
|
@dataclass
|
|
class ModelOption:
|
|
model_id: str
|
|
display_name: str
|
|
provider: str = ""
|
|
description: str = ""
|
|
|
|
|
|
def get_default_model_options() -> list[ModelOption]:
|
|
return [
|
|
ModelOption("gpt-4o-mini", "GPT-4o Mini", "openai", "轻量快速模型"),
|
|
ModelOption("gpt-4o", "GPT-4o", "openai", "旗舰多模态模型"),
|
|
ModelOption("claude-sonnet-4-20250514", "Claude Sonnet 4", "anthropic", "高性能推理模型"),
|
|
ModelOption("deepseek-v3", "DeepSeek V3", "deepseek", "国产高性能模型"),
|
|
]
|
|
|
|
|
|
def build_model_picker_actions(
|
|
models: list[ModelOption] | None = None,
|
|
callback_id: str = "model_picker",
|
|
) -> list[dict]:
|
|
"""构建模型选择器 action 列表。"""
|
|
if models is None:
|
|
models = get_default_model_options()
|
|
|
|
actions = []
|
|
for m in models:
|
|
actions.append(
|
|
{
|
|
"id": f"model_{m.model_id}",
|
|
"name": f"选择 {m.display_name}",
|
|
"integration": {
|
|
"url": "",
|
|
"context": {
|
|
"action": "select_model",
|
|
"model_id": m.model_id,
|
|
"callback_id": callback_id,
|
|
},
|
|
},
|
|
"type": "button",
|
|
"text": f"🤖 {m.display_name}",
|
|
"style": "",
|
|
}
|
|
)
|
|
|
|
return actions
|
|
|
|
|
|
def build_model_picker_attachment(
|
|
current_model: str = "",
|
|
callback_id: str = "model_picker",
|
|
) -> dict:
|
|
"""构建模型选择器 attachment 消息。"""
|
|
models = get_default_model_options()
|
|
lines = []
|
|
for m in models:
|
|
marker = " ✅" if m.model_id == current_model else ""
|
|
lines.append(f"• **{m.display_name}** ({m.provider}) — {m.description}{marker}")
|
|
|
|
text = "当前可用模型:\n\n" + "\n".join(lines)
|
|
actions = build_model_picker_actions(models, callback_id)
|
|
|
|
return {
|
|
"fallback": "模型选择器",
|
|
"title": "🤖 模型选择",
|
|
"text": text,
|
|
"callback_id": callback_id,
|
|
"actions": actions,
|
|
}
|
|
|
|
|
|
def build_model_select_attachment(provider: str, callback_id: str = "model_select") -> dict:
|
|
"""构建指定提供商的模型选择 attachment。"""
|
|
all_models = get_default_model_options()
|
|
provider_models = [m for m in all_models if m.provider == provider]
|
|
actions = build_model_picker_actions(provider_models, callback_id)
|
|
|
|
return {
|
|
"fallback": f"选择 {provider} 模型",
|
|
"title": f"🤖 {provider} 模型",
|
|
"text": f"选择 {provider} 下的模型:",
|
|
"callback_id": callback_id,
|
|
"actions": actions,
|
|
}
|