feat(market): 技能/MCP 分类改为面向用户的业务场景(人群->场景),AI验证期按场景归类

This commit is contained in:
QihuAI Design committed 2026-07-17 14:55:21 +08:00
1 parent 6f3fb400a4
commit 9bcf15099f
4 files changed
+136 -38

No files matched your search

+51 -11
View File
@@ -18,7 +18,7 @@ from ..models import (
) )
from ..auth import get_current_user, get_current_user_id, get_current_user_id_optional from ..auth import get_current_user, get_current_user_id, get_current_user_id_optional
from ..middleware.log_service import LogService from ..middleware.log_service import LogService
from ..capability_registry import CAPABILITY_TYPES, resolve_auto_model as _resolve_auto_model from ..capability_registry import resolve_auto_model as _resolve_auto_model
from app.api.admin.mcp_admin import _test_mcp_server, parse_mcp_config from app.api.admin.mcp_admin import _test_mcp_server, parse_mcp_config
router = APIRouter() router = APIRouter()
@@ -207,9 +207,48 @@ def verify_agent_connectivity(platform: str, endpoint: str, api_key: str) -> dic
return {"ok": False, "verified": False, "detail": f"地址不可达:{_short_err(e)}"} return {"ok": False, "verified": False, "detail": f"地址不可达:{_short_err(e)}"}
# ===== 能力分类(AI 自动归类,任何失败都返回 None,不阻断导入) ===== # ===== 业务场景分类(面向用户的技能/MCP 分类,与后端模型路由的 capability_registry 解耦) =====
def _classify_capability(name: str, description: Optional[str], content: Optional[str], db: Session) -> Optional[str]: # 注意:MarketApp.capability 列在此存放「业务场景 id」(见 MARKET_SCENES),不再是 text/vision 等模型能力。
"""用平台文本模型把应用归类到 11 种能力之一;失败返回 None(不阻断导入)。""" MARKET_SCENES: list = [
# 自由职业者
{"id": "freelance_content", "label": "内容创作/自媒体", "color": "#F59E0B", "group": "freelance"},
{"id": "freelance_client", "label": "客户沟通/提案", "color": "#F97316", "group": "freelance"},
{"id": "freelance_finance", "label": "报价合同/记账", "color": "#FBBF24", "group": "freelance"},
# 上班从业者
{"id": "office_doc", "label": "文档/会议纪要", "color": "#3B82F6", "group": "office"},
{"id": "office_data", "label": "数据/报表分析", "color": "#6366F1", "group": "office"},
{"id": "office_email", "label": "邮件/协作", "color": "#0EA5E9", "group": "office"},
{"id": "office_pm", "label": "项目/周报", "color": "#8B5CF6", "group": "office"},
# 育人教育者
{"id": "edu_prepare", "label": "备课/课件", "color": "#10B981", "group": "educator"},
{"id": "edu_grade", "label": "作业批改/测评", "color": "#14B8A6", "group": "educator"},
{"id": "edu_tutor", "label": "学情辅导/答疑", "color": "#22C55E", "group": "educator"},
{"id": "edu_home", "label": "家校沟通", "color": "#84CC16", "group": "educator"},
# 电商创业
{"id": "biz_product", "label": "商品/营销文案", "color": "#EC4899", "group": "commerce"},
{"id": "biz_service", "label": "客服/转化", "color": "#F43F5E", "group": "commerce"},
{"id": "biz_ops", "label": "运营/投放", "color": "#D946EF", "group": "commerce"},
# 通用提效
{"id": "general_write", "label": "通用写作", "color": "#64748B", "group": "general"},
{"id": "general_research", "label": "资料/调研", "color": "#06B6D4", "group": "general"},
{"id": "general_agent", "label": "智能体/自动化", "color": "#A855F7", "group": "general"},
]
SCENE_GROUPS: list = [
{"id": "freelance", "label": "自由职业者"},
{"id": "office", "label": "上班从业者"},
{"id": "educator", "label": "育人教育者"},
{"id": "commerce", "label": "电商创业"},
{"id": "general", "label": "通用提效"},
]
_VALID_SCENE_IDS = {s["id"] for s in MARKET_SCENES}
def _scene_label(scene_id):
return next((s["label"] for s in MARKET_SCENES if s["id"] == scene_id), None)
def _classify_scene(name: str, description: Optional[str], content: Optional[str], db: Session) -> Optional[str]:
"""用平台文本模型把应用归类到面向用户的业务场景之一;失败返回 None(不阻断导入)。"""
try: try:
text_model = _resolve_auto_model("text", db) text_model = _resolve_auto_model("text", db)
if not text_model: if not text_model:
@@ -225,9 +264,10 @@ def _classify_capability(name: str, description: Optional[str], content: Optiona
) )
if not api_url: if not api_url:
return None return None
options = "、".join(f"{c['id']}({c['label']})" for c in CAPABILITY_TYPES) options = "、".join(f"{s['id']}({s['label']})" for s in MARKET_SCENES)
sys_prompt = ( sys_prompt = (
"你是应用市场的能力分类器。根据应用名称、描述与内容,把它精确归类到下列能力之一:" "你是 AI 应用市场的『业务场景分类器』。请站在使用者视角,根据应用名称、描述与内容,"
"判断它最常被哪一类【人群 / 岗位 / 业务场景】的用户使用,并归类到下列场景之一:"
f"{options}。\n只返回一个 JSON 对象:{{\"capability\": \"<id>\"}},不要任何额外解释或 Markdown。" f"{options}。\n只返回一个 JSON 对象:{{\"capability\": \"<id>\"}},不要任何额外解释或 Markdown。"
) )
user_text = f"名称:{name}\n描述:{description or ''}\n内容摘要:{(content or '')[:2000]}" user_text = f"名称:{name}\n描述:{description or ''}\n内容摘要:{(content or '')[:2000]}"
@@ -247,7 +287,7 @@ def _classify_capability(name: str, description: Optional[str], content: Optiona
data = r.json() data = r.json()
text_out = data.get("choices", [{}])[0].get("message", {}).get("content", "") text_out = data.get("choices", [{}])[0].get("message", {}).get("content", "")
m = re.search(r'"capability"\s*:\s*"([a-z_]+)"', text_out) m = re.search(r'"capability"\s*:\s*"([a-z_]+)"', text_out)
if m and m.group(1) in {c["id"] for c in CAPABILITY_TYPES}: if m and m.group(1) in _VALID_SCENE_IDS:
return m.group(1) return m.group(1)
return None return None
except Exception: except Exception:
@@ -283,9 +323,9 @@ def detect_capability(
db: Session = Depends(get_db), db: Session = Depends(get_db),
current_user: User = Depends(get_current_user), current_user: User = Depends(get_current_user),
): ):
"""导入前 AI 验证阶段:根据名称/描述/内容识别能力分类,供前台预填并允许用户修改。""" """导入前 AI 验证阶段:根据名称/描述/内容识别业务场景分类,供前台预填并允许用户修改。"""
cap = _classify_capability(req.name, req.description, req.skill_content, db) cap = _classify_scene(req.name, req.description, req.skill_content, db)
label = next((c["label"] for c in CAPABILITY_TYPES if c["id"] == cap), None) label = _scene_label(cap)
return {"code": 0, "data": {"capability": cap, "label": label}, "message": "ok"} return {"code": 0, "data": {"capability": cap, "label": label}, "message": "ok"}
@@ -528,7 +568,7 @@ def upload_app(
) )
# 能力分类:前端显式指定优先;否则导入阶段由 AI 自动归类;都不行则留空(不阻断导入) # 能力分类:前端显式指定优先;否则导入阶段由 AI 自动归类;都不行则留空(不阻断导入)
_classify_content = req.skill_content or req.download_url or "" _classify_content = req.skill_content or req.download_url or ""
app.capability = req.capability or _classify_capability(req.name, req.description, _classify_content, db) or None app.capability = req.capability or _classify_scene(req.name, req.description, _classify_content, db) or None
db.add(app) db.add(app)
db.commit() db.commit()
db.refresh(app) db.refresh(app)
+16
View File
@@ -1744,10 +1744,26 @@
.capability-filter { .capability-filter {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
align-items: center;
gap: var(--space-xs); gap: var(--space-xs);
padding: var(--space-sm) 0 0; padding: var(--space-sm) 0 0;
} }
.cap-group-label {
display: inline-flex;
align-items: center;
margin-left: var(--space-sm);
padding: 0 4px;
font-size: 11px;
font-weight: 700;
color: var(--color-text-tertiary);
letter-spacing: 0.02em;
}
.cap-group-label:first-of-type {
margin-left: 0;
}
.cap-chip { .cap-chip {
padding: 4px 12px; padding: 4px 12px;
font-size: var(--text-xs); font-size: var(--text-xs);
+55 -27
View File
@@ -182,30 +182,53 @@ const typeIcons: Record<AppType, React.ReactNode> = {
mcp: <McpIcon />, mcp: <McpIcon />,
}; };
// ===== 能力分类(与后端 11 种能力保持一致) ===== // ===== 业务场景分类(面向用户的技能/MCP 分类,与后端模型路由能力解耦) =====
const CAPABILITIES: { id: string; label: string; color: string }[] = [ // 两级:人群大类(SCENE_GROUPS) -> 业务场景(SCENES)。id 与后端 MARKET_SCENES 保持一致。
{ id: 'text', label: '文本对话', color: '#5B5FED' }, const SCENES: { id: string; label: string; color: string; group: string }[] = [
{ id: 'thinking', label: '推理思考', color: '#8B5CF6' }, // 自由职业者
{ id: 'vision', label: '视觉理解', color: '#219B5E' }, { id: 'freelance_content', label: '内容创作/自媒体', color: '#F59E0B', group: 'freelance' },
{ id: 'tool', label: '工具调用', color: '#3B82F6' }, { id: 'freelance_client', label: '客户沟通/提案', color: '#F97316', group: 'freelance' },
{ id: 'image', label: '图像生成', color: '#D9383A' }, { id: 'freelance_finance', label: '报价合同/记账', color: '#FBBF24', group: 'freelance' },
{ id: 'audio', label: '语音合成', color: '#E8922C' }, // 上班从业者
{ id: 'asr', label: '语音识别', color: '#0EA5E9' }, { id: 'office_doc', label: '文档/会议纪要', color: '#3B82F6', group: 'office' },
{ id: 'ocr', label: 'OCR识别', color: '#F59E0B' }, { id: 'office_data', label: '数据/报表分析', color: '#6366F1', group: 'office' },
{ id: 'embedding', label: '嵌入向量', color: '#10B981' }, { id: 'office_email', label: '邮件/协作', color: '#0EA5E9', group: 'office' },
{ id: 'rerank', label: '重排序', color: '#EC4899' }, { id: 'office_pm', label: '项目/周报', color: '#8B5CF6', group: 'office' },
{ id: 'video', label: '视频生成', color: '#EF4444' }, // 育人教育者
{ id: 'edu_prepare', label: '备课/课件', color: '#10B981', group: 'educator' },
{ id: 'edu_grade', label: '作业批改/测评', color: '#14B8A6', group: 'educator' },
{ id: 'edu_tutor', label: '学情辅导/答疑', color: '#22C55E', group: 'educator' },
{ id: 'edu_home', label: '家校沟通', color: '#84CC16', group: 'educator' },
// 电商创业
{ id: 'biz_product', label: '商品/营销文案', color: '#EC4899', group: 'commerce' },
{ id: 'biz_service', label: '客服/转化', color: '#F43F5E', group: 'commerce' },
{ id: 'biz_ops', label: '运营/投放', color: '#D946EF', group: 'commerce' },
// 通用提效
{ id: 'general_write', label: '通用写作', color: '#64748B', group: 'general' },
{ id: 'general_research', label: '资料/调研', color: '#06B6D4', group: 'general' },
{ id: 'general_agent', label: '智能体/自动化', color: '#A855F7', group: 'general' },
]; ];
const SCENE_GROUPS: { id: string; label: string }[] = [
{ id: 'freelance', label: '自由职业者' },
{ id: 'office', label: '上班从业者' },
{ id: 'educator', label: '育人教育者' },
{ id: 'commerce', label: '电商创业' },
{ id: 'general', label: '通用提效' },
];
const SCENE_BY_GROUP: Record<string, typeof SCENES> = SCENE_GROUPS.reduce((acc, g) => {
acc[g.id] = SCENES.filter(s => s.group === g.id);
return acc;
}, {} as Record<string, typeof SCENES>);
function CapabilityBadge({ capability }: { capability?: string | null }) { function CapabilityBadge({ capability }: { capability?: string | null }) {
if (!capability) return null; if (!capability) return null;
const cap = CAPABILITIES.find(c => c.id === capability); const cap = SCENES.find(c => c.id === capability);
if (!cap) return null; if (!cap) return null;
return ( return (
<span <span
className="capability-badge" className="capability-badge"
style={{ color: cap.color, background: cap.color + '1A', borderColor: cap.color + '40' }} style={{ color: cap.color, background: cap.color + '1A', borderColor: cap.color + '40' }}
title={`能力分类:${cap.label}`} title={`业务场景:${cap.label}`}
> >
{cap.label} {cap.label}
</span> </span>
@@ -751,7 +774,7 @@ const CreateToolModal: React.FC<CreateToolModalProps> = ({ appType, onClose, onS
<label className="form-label">能力分类 <span className="cap-hint">(AI验证后自动识别,可修改)</span></label> <label className="form-label">能力分类 <span className="cap-hint">(AI验证后自动识别,可修改)</span></label>
<select className="form-input" value={capability} onChange={e => setCapability(e.target.value)}> <select className="form-input" value={capability} onChange={e => setCapability(e.target.value)}>
<option value="">未指定(由AI自动归类)</option> <option value="">未指定(由AI自动归类)</option>
{CAPABILITIES.map(c => ( {SCENES.map(c => (
<option key={c.id} value={c.id}>{c.label}</option> <option key={c.id} value={c.id}>{c.label}</option>
))} ))}
</select> </select>
@@ -1134,7 +1157,7 @@ const HubImportModal: React.FC<HubImportModalProps> = ({ appType, platforms, onC
<label className="form-label">能力分类 <span className="cap-hint">(AI验证后自动识别,可修改)</span></label> <label className="form-label">能力分类 <span className="cap-hint">(AI验证后自动识别,可修改)</span></label>
<select className="form-input" value={capability} onChange={e => setCap(e.target.value)}> <select className="form-input" value={capability} onChange={e => setCap(e.target.value)}>
<option value="">未指定(由AI自动归类)</option> <option value="">未指定(由AI自动归类)</option>
{CAPABILITIES.map(c => ( {SCENES.map(c => (
<option key={c.id} value={c.id}>{c.label}</option> <option key={c.id} value={c.id}>{c.label}</option>
))} ))}
</select> </select>
@@ -1460,7 +1483,7 @@ const AgentConnectModal: React.FC<AgentConnectModalProps> = ({ onClose, onConnec
<label className="form-label">能力分类 <span className="cap-hint">(可选,未指定由AI自动归类)</span></label> <label className="form-label">能力分类 <span className="cap-hint">(可选,未指定由AI自动归类)</span></label>
<select className="form-input" value={capability} onChange={e => setCapability(e.target.value)}> <select className="form-input" value={capability} onChange={e => setCapability(e.target.value)}>
<option value="">未指定(由AI自动归类)</option> <option value="">未指定(由AI自动归类)</option>
{CAPABILITIES.map(c => ( {SCENES.map(c => (
<option key={c.id} value={c.id}>{c.label}</option> <option key={c.id} value={c.id}>{c.label}</option>
))} ))}
</select> </select>
@@ -1799,19 +1822,24 @@ const MarketPage: React.FC = () => {
</div> </div>
)} )}
{/* 能力分类筛选 */} {/* 业务场景筛选(按人群分组) */}
<div className="capability-filter"> <div className="capability-filter">
<button <button
className={`cap-chip ${!capabilityFilter ? 'active' : ''}`} className={`cap-chip ${!capabilityFilter ? 'active' : ''}`}
onClick={() => setCapabilityFilter(null)} onClick={() => setCapabilityFilter(null)}
>全部能力</button> >全部场景</button>
{CAPABILITIES.map(c => ( {SCENE_GROUPS.map(g => (
<button <React.Fragment key={g.id}>
key={c.id} <span className="cap-group-label">{g.label}</span>
className={`cap-chip ${capabilityFilter === c.id ? 'active' : ''}`} {SCENE_BY_GROUP[g.id].map(c => (
style={capabilityFilter === c.id ? { color: '#fff', background: c.color, borderColor: c.color } : { color: c.color, borderColor: c.color + '55' }} <button
onClick={() => setCapabilityFilter(capabilityFilter === c.id ? null : c.id)} key={c.id}
>{c.label}</button> className={`cap-chip ${capabilityFilter === c.id ? 'active' : ''}`}
style={capabilityFilter === c.id ? { color: '#fff', background: c.color, borderColor: c.color } : { color: c.color, borderColor: c.color + '55' }}
onClick={() => setCapabilityFilter(capabilityFilter === c.id ? null : c.id)}
>{c.label}</button>
))}
</React.Fragment>
))} ))}
</div> </div>
@@ -0,0 +1,14 @@
-- 018: 将 market_apps.capability 从旧的「AI 技术能力」取值规范为「业务场景」取值
-- 旧的 text/thinking/vision/tool/image/audio/asr/ocr/embedding/rerank/video 已不再使用,
-- 统一置空,后续由 AI 验证 / 导入阶段按业务场景重新归类。
-- 幂等:执行一次后不再有匹配行,可安全每次重启重跑。
UPDATE market_apps
SET capability = NULL
WHERE capability IS NOT NULL
AND capability NOT IN (
'freelance_content', 'freelance_client', 'freelance_finance',
'office_doc', 'office_data', 'office_email', 'office_pm',
'edu_prepare', 'edu_grade', 'edu_tutor', 'edu_home',
'biz_product', 'biz_service', 'biz_ops',
'general_write', 'general_research', 'general_agent'
);