| | |
| | | status = Column(String(16), nullable=False) |
| | | description = Column(Text, nullable=False) |
| | | tenant_id = Column(String(36), nullable=False) |
| | | mode = Column(String(36), nullable=False) |
| | | |
| | | |
| | | class RgKnowledge(Base): |
| | |
| | | try: |
| | | if names: |
| | | query = db.query(Flow.id, Flow.name, Flow.description, Flow.status, Flow.user_id) \ |
| | | .filter(Flow.name.in_(names)) |
| | | .filter(Flow.name.in_(names), Flow.status=="1") |
| | | else: |
| | | query = db.query(Flow.id, Flow.name, Flow.description, Flow.status, Flow.user_id) |
| | | query = db.query(Flow.id, Flow.name, Flow.description, Flow.status, Flow.user_id).filter(Flow.status=="1") |
| | | |
| | | results = query.all() |
| | | # print(f"Executing query: {query}") |
| | | # 格式化id为UUID |
| | | formatted_results = [{"id":format_uuid(row[0]), "name": row[1], "description": row[2], "status": "1" if row[3] ==2 else "0", "user_id": str(row[4])} for row in results] |
| | | formatted_results = [{"id":row[0], "name": row[1], "description": row[2], "status": row[3], "user_id": str(row[4]), "mode": "agent-dialog"} for row in results] |
| | | return formatted_results |
| | | finally: |
| | | db.close() |
| | |
| | | |
| | | results = query.all() |
| | | formatted_results = [ |
| | | {"id": format_uuid(row[0]), "name": row[1], "description": row[2], "status": str(row[3]) if row[3] ==1 else "2", |
| | | "user_id": str(row[4])} for row in results] |
| | | {"id": row[0], "name": row[1], "description": row[2], "status": "1" if row[3] == "1" else "2", |
| | | "user_id": str(row[4]), "mode": "agent-dialog"} for row in results] |
| | | return formatted_results |
| | | finally: |
| | | db.close() |
| | |
| | | db = SessionDify() |
| | | try: |
| | | if names: |
| | | query = db.query(DfApps.id, DfApps.name, DfApps.description, DfApps.status, DfApps.tenant_id) \ |
| | | query = db.query(DfApps.id, DfApps.name, DfApps.description, DfApps.status, DfApps.tenant_id, DfApps.mode) \ |
| | | .filter( DfApps.name.in_(names)) |
| | | else: |
| | | query = db.query(DfApps.id, DfApps.name, DfApps.description, DfApps.status, DfApps.tenant_id) |
| | | query = db.query(DfApps.id, DfApps.name, DfApps.description, DfApps.status, DfApps.tenant_id, DfApps.mode) |
| | | |
| | | results = query.all() |
| | | formatted_results = [ |
| | | {"id": str(row[0]), "name": row[1], "description": row[2], "status": "1", |
| | | "user_id": str(row[4])} for row in results] |
| | | "user_id": str(row[4]), "mode": row[5]} for row in results] |
| | | return formatted_results |
| | | finally: |
| | | db.close() |
| | |
| | | existing_agent = db.query(DialogModel).filter_by(id=row["id"]).first() |
| | | if existing_agent: |
| | | existing_agent.name = row["name"] |
| | | existing_agent.status = row["status"] |
| | | existing_agent.description = row["description"] |
| | | existing_agent.status = row["status"] |
| | | existing_agent.mode = row["mode"] |
| | | # existing_agent.tenant_id = get_rag_user_id(db, row["user_id"], type_dict[dialog_type]) |
| | | else: |
| | | existing = DialogModel(id=row["id"], status=row["status"], name=row["name"], description=row["description"], tenant_id=get_rag_user_id(db, row["user_id"], type_dict[dialog_type]), dialog_type=dialog_type) |
| | | existing = DialogModel(id=row["id"], status=row["status"], name=row["name"], description=row["description"], tenant_id=get_rag_user_id(db, row["user_id"], type_dict[dialog_type]), dialog_type=dialog_type, mode=row["mode"]) |
| | | db.add(existing) |
| | | db.commit() |
| | | for dialog in db.query(DialogModel).filter_by(dialog_type=dialog_type).all(): |
| | | if dialog.id not in agent_id_list: |
| | | # print(dialog.id) |
| | | db.query(DialogModel).filter_by(id=dialog.id).update({"status": "2"}) |
| | | db.commit() |
| | | except IntegrityError: |
| | |
| | | knowledge_type=1, permission=row["permission"], documents=row["doc_num"]) |
| | | db.add(existing) |
| | | db.commit() |
| | | for dialog in db.query(KnowledgeModel).filter_by(knowledge_type=type_dict[klg_type]).all(): |
| | | for dialog in db.query(KnowledgeModel).filter_by(knowledge_type=klg_type).all(): |
| | | if dialog.id not in agent_id_list: |
| | | db.query(KnowledgeModel).filter_by(id=dialog.id).delete() |
| | | db.commit() |