cang-ying/skill/skill_center.py
Zhuyuan Operations 80805449ca EED: 经验记忆推送——技能库(11技能+开源角色设定板)+遇事不决先搜索铁律+人物三/四视图+场景四视图工业级方法论+声画装配+多视图工具
- skill/ 技能库:index.json 11 技能 + community_techniques.md 社区技巧 + character_sheet_learn.md 角色版学习 + scene_4view_learn.md 场景四视图工业级方法 + character-sheet-generator 开源技能(7风格模板)
- tools/character_turnaround.py:人物三/四视图(主视觉+三视图/展示台)+场景四视角,Z-Image 本地
- tools/audio_pipeline.py:Edge-TTS配音+字幕+BGM+混音,Agent stage⑥有声成片
- agent_short_drama.py:一键短剧 Agent --until audio 全链路
- eed_web.py:技能库端点(/api/skills,/api/skill)+E2BIG根治(字节截断+巨兽降级)+一键短剧按钮
2026-08-01 03:16:48 +08:00

77 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""苍耳技能中心:技能注册表 + 提示词加载 + 工具执行
用法python3 skill_center.py [list|load <id>|run <id> [args...]]"""
import json, os, subprocess, sys
SKILL_DIR = os.path.dirname(os.path.abspath(__file__))
INDEX = os.path.join(SKILL_DIR, "index.json")
def _index():
with open(INDEX, encoding="utf-8") as f:
return json.load(f)
def list_skills():
return _index().get("skills", [])
def load(skill_id):
"""返回技能定义 + 提示词全文prompt_file 存在时)。"""
for s in list_skills():
if s["id"] == skill_id:
data = dict(s)
pf = data.get("prompt_file")
if pf:
p = os.path.normpath(os.path.join(SKILL_DIR, pf))
try:
with open(p, encoding="utf-8") as f:
data["prompt"] = f.read()
except Exception as e:
data["prompt"] = ""
data["prompt_error"] = str(e)
return data
return None
def run(skill_id, args=None):
"""执行工具型技能,返回 (ok, output)。"""
s = load(skill_id)
if not s:
return False, "技能不存在: " + skill_id
if s.get("type") != "tool":
return False, f"技能「{s.get('name','')}」是提示词型,请注入提示词使用"
tool = s.get("tool")
if not tool:
return False, "技能无执行命令"
cmd = tool.split() + (args or [])
try:
r = subprocess.run(cmd, capture_output=True, text=True, timeout=600)
return r.returncode == 0, (r.stdout or r.stderr)[-3000:]
except subprocess.TimeoutExpired:
return False, "执行超时10分钟"
except Exception as e:
return False, str(e)
if __name__ == "__main__":
if len(sys.argv) < 2:
print(json.dumps(list_skills(), ensure_ascii=False, indent=2)); sys.exit(0)
cmd = sys.argv[1]
if cmd == "list":
print(json.dumps({"skills": list_skills()}, ensure_ascii=False, indent=2)); sys.exit(0)
elif cmd == "load":
s = load(sys.argv[2]) if len(sys.argv) > 2 else None
if s:
print(json.dumps({"name": s.get("name"), "type": s.get("type"),
"prompt_len": len(s.get("prompt", "")),
"tool": s.get("tool")}, ensure_ascii=False))
else:
print("技能不存在"); sys.exit(1)
elif cmd == "run":
ok, out = run(sys.argv[2], sys.argv[3:])
print(("OK\n" if ok else "FAIL\n") + out)
sys.exit(0 if ok else 1)
else:
print("未知命令: " + cmd); sys.exit(1)