import os import time import json import urllib.request SKILLS_DIR = "/opt/ai-os/products/ceo/workspace/claude-seo/skills" API_URL = "http://127.0.0.1:20128/v1/chat/completions" with os.popen("cat /root/.hermes/.env | grep LOCAL9R_KEY | cut -d= -f2") as f_env: API_KEY = f_env.read().strip() skills_list = [ # Group 1: Technical & Architecture (Da xong) ["seo-audit", "seo-technical", "seo-page", "seo-schema", "seo-sitemap", "seo-hreflang", "seo-images"], # Group 2: Content & GEO ["seo-content", "seo-content-brief", "seo-cluster", "seo-geo", "seo-programmatic", "seo-sxo"], # Group 3: Competition & Specialty ["seo-competitor-pages", "seo-backlinks", "seo-local", "seo-maps", "seo-ecommerce", "seo-drift", "seo-plan"] ] def parse_sse(response_text): full_content = "" for line in response_text.splitlines(): if line.startswith("data: ") and line != "data: [DONE]": try: data = json.loads(line[6:]) delta = data.get("choices", [{}])[0].get("delta", {}) if "content" in delta: full_content += delta["content"] except Exception: pass return full_content def analyze_group(group_idx, skills): print(f"=== BAT DAU PHAN TICH NHOM {group_idx + 1} ===") results = [] for skill in skills: skill_path = os.path.join(SKILLS_DIR, skill, "SKILL.md") if not os.path.exists(skill_path): print(f"Khong tim thay file: {skill_path}") continue print(f"Dang doc skill: {skill}...") with open(skill_path, "r", encoding="utf-8") as f: content = f.read()[:5000] prompt = ( "Ban la chuyen gia phan tich he thong SEO. Hay tom tat cot loi cua ky nang sau (duoi 150 tu).\n" "Chi ra: 1) Chuc nang chinh, 2) Cac script/API no goi, 3) Tinh kha thi khi mang ve Hermes Agent.\n" "Yeu cau dac biet: Khong dung ky tu gach ngang hoac gach noi (dash) trong phan hoi. Su dung so thu tu de liet ke.\n" f"Noi dung skill:\n{content}" ) req_data = { "model": "complex", "messages": [{"role": "user", "content": prompt}], "temperature": 0.2 } success = False attempts = 0 while not success and attempts < 3: try: attempts += 1 req = urllib.request.Request( API_URL, data=json.dumps(req_data).encode("utf-8"), headers={"Content-Type": "application/json", "Authorization": f"Bearer {API_KEY}"} ) with urllib.request.urlopen(req, timeout=120) as response: raw_res = response.read().decode("utf-8") summary = parse_sse(raw_res) if summary: print(f"Da phan tich xong: {skill}\n{summary}\n") results.append({"skill": skill, "summary": summary}) success = True else: print("Khong nhan duoc noi dung, thu lai...") except Exception as e: print(f"Loi: {str(e)}. Dang ngu 35s truoc khi thu lai...") time.sleep(35) print("Dang ngu 25 giay de tuanchau Rate Limit...") time.sleep(25) with open(f"seo_group_{group_idx + 1}_report.json", "w", encoding="utf-8") as f_out: json.dump(results, f_out, ensure_ascii=False, indent=2) print(f"=== DA HOAN THANH NHOM {group_idx + 1} ===") if __name__ == "__main__": import sys g_idx = 1 # Chạy Nhóm 2 if len(sys.argv) > 1: g_idx = int(sys.argv[1]) analyze_group(g_idx, skills_list[g_idx])