专家归属切换功能使用指南
📋 概述
专家归属切换功能允许管理员在平台专家和开发者专家之间切换专家的归属。本文档说明如何使用切换脚本和API。
🛠️ 使用方法
方法1:使用脚本(推荐用于批量操作)
查看专家归属信息
python scripts/switch_expert_ownership.py --expert-id psychotherapy_expert --to info
输出示例:
专家ID: psychotherapy_expert
知识库ID: psychotherapy_kb_001
归属类型: developer
开发者ID: mbe_developer
在平台索引: 是
市场配置: 已设置
发布状态: 未发布
定价: 已配置
市场状态: 未发布到市场
切换到开发者专家
python scripts/switch_expert_ownership.py \
--expert-id psychotherapy_expert \
--to developer \
--developer-id mbe_developer \
--remove-from-platform
参数说明:
--expert-id: 专家ID(必需)--to developer: 切换到开发者专家--developer-id: 开发者ID(必需)--remove-from-platform: 可选,是否从平台索引移除
切换到平台专家
python scripts/switch_expert_ownership.py \
--expert-id psychotherapy_expert \
--to platform \
--remove-from-market
参数说明:
--expert-id: 专家ID(必需)--to platform: 切换到平台专家--remove-from-market: 是否从市场移除(默认True)
方法2:使用API(推荐用于Web界面集成)
获取专家归属信息
GET /api/admin/expert-ownership/{expert_id}/info
Cookie: admin_session=...
响应示例:
{
"success": true,
"data": {
"expert_id": "psychotherapy_expert",
"kb_id": "psychotherapy_kb_001",
"ownership_type": "developer",
"developer_id": "mbe_developer",
"marketplace_config": {
"published": false,
"category": "health",
"tags": ["心理咨询", "情绪管理"],
"pricing": {...}
},
"market_status": null,
"in_platform_index": true
}
}
切换到开发者专家
POST /api/admin/expert-ownership/{expert_id}/switch-to-developer
Cookie: admin_session=...
Content-Type: application/json
{
"developer_id": "mbe_developer",
"pricing_config": {
"free_trial": 3,
"per_call": {
"single": 5.0,
"package_10": 39.0,
"package_30": 99.0
}
},
"marketplace_config": {
"published": false,
"category": "health",
"tags": ["心理咨询", "情绪管理"],
"revenue_share": {
"developer": 0.7,
"platform": 0.3
}
},
"remove_from_platform": false
}
响应示例:
{
"success": true,
"message": "专家 psychotherapy_expert 已切换为开发者专家",
"data": {
"expert_id": "psychotherapy_expert",
"developer_id": "mbe_developer",
"kb_id": "psychotherapy_kb_001",
"removed_from_platform": false
}
}
切换到平台专家
POST /api/admin/expert-ownership/{expert_id}/switch-to-platform
Cookie: admin_session=...
Content-Type: application/json
{
"remove_from_market": true
}
响应示例:
{
"success": true,
"message": "专家 psychotherapy_expert 已切换为平台专家",
"data": {
"expert_id": "psychotherapy_expert",
"kb_id": "psychotherapy_kb_001",
"removed_from_market": true
}
}
⚠️ 注意事项
1. 权限要求
- API: 需要管理员权限(
admin或super_admin) - 脚本: 需要直接访问文件系统权限
2. 数据一致性
切换操作会自动确保:
- 知识库和专家的
developer_id一致 - 索引文件同步更新
- 市场状态正确更新
3. 用户影响
平台专家 → 开发者专家:
- 已使用该专家的用户需要购买
- 建议提前通知用户
- 可以考虑提供过渡期
开发者专家 → 平台专家:
- 已购买的用户需要退款或补偿
- 需要通知开发者
- 需要处理收益结算
4. 发布流程
切换到开发者专家后,专家不会自动发布到市场。需要:
- 通过
/api/market/publish发布专家 - 等待审核通过
- 审核通过后,专家才会在市场显示
5. 回滚
如果切换出错,可以:
- 使用相反方向的切换操作回滚
- 检查日志文件了解详细错误信息
- 手动修复索引文件(不推荐)
📝 实际案例
案例1:将心理治疗专家切换为开发者专家
当前状态:
- 专家ID:
psychotherapy_expert - 知识库ID:
psychotherapy_kb_001 - 已设置
developer_id: "mbe_developer" - 未发布到市场
操作步骤:
查看当前归属:
python scripts/switch_expert_ownership.py --expert-id psychotherapy_expert --info确认已正确设置(如果需要):
python scripts/switch_expert_ownership.py \ --expert-id psychotherapy_expert \ --to developer \ --developer-id mbe_developer发布到市场(通过API):
POST /api/market/publish { "expert_id": "psychotherapy_expert", "category": "health", "tags": "心理咨询,情绪管理", "price_per_1k_tokens": 0.01 }
案例2:将开发者专家切换回平台专家
操作步骤:
从市场下架:
python scripts/switch_expert_ownership.py \ --expert-id psychotherapy_expert \ --to platform \ --remove-from-market验证切换结果:
python scripts/switch_expert_ownership.py --expert-id psychotherapy_expert --info
🔍 故障排查
问题1:专家不存在
错误:专家 {expert_id} 不存在
解决方案:
- 检查专家ID是否正确
- 确认专家在
knowledge_bases/experts/index.json中
问题2:知识库不存在
错误:专家 {expert_id} 没有关联的知识库
解决方案:
- 检查专家的
kb_id字段 - 确认知识库在
knowledge_bases/index.json中
问题3:市场模型删除失败
警告:从市场移除失败: ...
解决方案:
- 检查Redis连接
- 手动检查市场系统中的模型
- 可以忽略此警告(如果专家未发布到市场)