Files
aiagent/backend/scripts/templates/template_ops_log_analysis.py
renjianbo 0608161c82 feat: 完善企业场景多线路由与执行稳定性
补齐平台模板与场景 DSL、预算控制、执行看板和企业场景脚本,增强 Windows 启动/迁移与前端代理和聊天会话记忆,修复执行创建阶段 500 与异步链路排障体验。

Made-with: Cursor
2026-04-09 21:58:53 +08:00

55 lines
1.7 KiB
Python

#!/usr/bin/env python3
"""
路线图场景模板:运维 / 日志分析 — 通过 API 从模板创建 Agent。
用法:
cd backend && .\\venv\\Scripts\\python.exe scripts/templates/template_ops_log_analysis.py
"""
from __future__ import annotations
import os
import sys
import time
import requests
BASE = os.getenv("PLATFORM_BASE_URL", "http://127.0.0.1:8037").rstrip("/")
USER = os.getenv("PLATFORM_USERNAME", "admin")
PWD = os.getenv("PLATFORM_PASSWORD", "123456")
TEMPLATE_ID = "template_ops_log_analysis"
DEFAULT_NAME = os.getenv("TARGET_NAME") or f"场景模板_运维_{int(time.time())}"
def main() -> int:
r = requests.post(
f"{BASE}/api/v1/auth/login",
data={"username": USER, "password": PWD},
headers={"Content-Type": "application/x-www-form-urlencoded"},
timeout=15,
)
if r.status_code != 200:
print("登录失败:", r.status_code, r.text[:500], file=sys.stderr)
return 1
token = r.json().get("access_token")
if not token:
print("无 access_token", file=sys.stderr)
return 1
h = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
body = {
"template_id": TEMPLATE_ID,
"name": DEFAULT_NAME,
"description": "由 scripts/templates/template_ops_log_analysis.py 创建",
"parameters": {"temperature": 0.3},
}
cr = requests.post(f"{BASE}/api/v1/agents/from-scene-template", json=body, headers=h, timeout=60)
if cr.status_code not in (200, 201):
print("创建失败:", cr.status_code, cr.text[:800], file=sys.stderr)
return 1
print(cr.json().get("id"), cr.json().get("name"))
return 0
if __name__ == "__main__":
raise SystemExit(main())