tmp
zhaoqingang
2025-01-14 36c00e400801786ee0f06a50e6046f49777ed188
app/service/v2/initialize_data.py
@@ -220,3 +220,33 @@
    if not user_id:
        raise Exception("Failed to register with app")
    print({"msg": "User registered successfully", "userFlag": user_id})
async def admin_account_sync(db):
    agent_list = []
    with open(os.path.join(ENV_CONF_PATH, "default_agent_conf.json"), 'r', encoding='utf-8') as file:
        # 加载JSON数据
        agent_dict = json.load(file)
        agent_list = agent_dict.get("basic", [])
    user = db.query(UserModel).filter_by(permission="admin").first()
    for agent in agent_list:
        dialog = db.query(DialogModel).filter(DialogModel.id == agent["id"]).first()
        if dialog:
            try:
                dialog.name = agent["name"]
                dialog.description = agent["description"]
                dialog.icon = agent["icon"]
                db.commit()
            except Exception as e:
                logger.error(e)
        else:
            try:
                dialog = DialogModel(id=agent["id"], name=agent["name"], description=agent["description"],
                                     icon=agent["icon"], tenant_id=user.id if user else "", dialog_type="3",
                                     agent_id=agent["id"])
                db.add(dialog)
                db.commit()
                db.refresh(dialog)
            except Exception as e:
                print(e)
                db.rollback()