Files

26 lines
1.3 KiB
Python
Raw Permalink Normal View History

"""插入画布模板(无产品场/纯心法场)"""
import sys
sys.path.insert(0, r'C:\Users\xinmiclaw\Desktop\雅文内容创造工作台\server')
from sqlmodel import Session, select
from app.db import engine
from app.models import Canvas
from app.seed import default_canvas
with Session(engine) as s:
exist = {c.name for c in s.exec(select(Canvas)).all()}
if "【模板】无产品场" not in exist:
no_product = [n for n in default_canvas()["nodes"] if n["node_id"] != "n4"]
edges = [e for e in default_canvas()["edges"] if e["from"] != "n4" and e["to"] != "n4"]
s.add(Canvas(name="【模板】无产品场", nodes=no_product, edges=edges))
print("已插入 【模板】无产品场")
if "【模板】纯心法场" not in exist:
s.add(Canvas(name="【模板】纯心法场", nodes=[
{"node_id": "n1", "agent_id": 2, "enabled": True},
{"node_id": "n2", "agent_id": 3, "enabled": True},
{"node_id": "n3", "agent_id": 3, "enabled": True},
{"node_id": "n5", "agent_id": 6, "enabled": True},
], edges=[{"from": "n1", "to": "n2"}, {"from": "n2", "to": "n3"}, {"from": "n3", "to": "n5"}]))
print("已插入 【模板】纯心法场")
s.commit()
print("当前画布:", [c.name for c in s.exec(select(Canvas)).all()])