| | |
| | | |
| | | from app.config.config import settings |
| | | from app.config.const import RAGFLOW, BISHENG, DIFY, ENV_CONF_PATH, Dialog_STATSU_DELETE, Dialog_STATSU_ON |
| | | from app.models import KnowledgeModel |
| | | from app.models import KnowledgeModel, ComplexChatDao |
| | | from app.models.dialog_model import DialogModel |
| | | from app.models.user_model import UserAppModel |
| | | from app.models.agent_model import AgentModel |
| | |
| | | db.close() |
| | | |
| | | |
| | | def get_data_from_ragflow_v2(names: List[str], tenant_id) -> List[Dict]: |
| | | def get_data_from_ragflow_v2(base_db, names: List[str], tenant_id) -> List[Dict]: |
| | | db = SessionRagflow() |
| | | para = { |
| | | "user_input_form": [], |
| | |
| | | } |
| | | } |
| | | try: |
| | | chat_ids = ComplexChatDao(base_db).get_complex_chat_ids() |
| | | # print(chat_ids) |
| | | if names: |
| | | query = db.query(Dialog.id, Dialog.name, Dialog.description, Dialog.status, Dialog.tenant_id) \ |
| | | .filter(Dialog.name.in_(names), Dialog.status == "1") |
| | |
| | | results = query.all() |
| | | formatted_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", "parameters": para} for row in results] |
| | | "user_id": str(row[4]), "mode": "agent-dialog", "parameters": para} for row in results if row[0] not in chat_ids] |
| | | return formatted_results |
| | | finally: |
| | | db.close() |
| | | |
| | | |
| | | def get_data_from_dy_v2(names: List[str]) -> List[Dict]: |
| | | def get_data_from_dy_v2(base_db, names: List[str]) -> List[Dict]: |
| | | db = SessionDify() |
| | | try: |
| | | chat_ids = ComplexChatDao(base_db).get_complex_chat_ids() |
| | | # print(chat_ids) |
| | | if names: |
| | | query = db.query(DfApps.id, DfApps.name, DfApps.description, DfApps.status, DfApps.tenant_id, DfApps.mode) \ |
| | | .filter(DfApps.name.in_(names)) |
| | |
| | | results = query.all() |
| | | formatted_results = [ |
| | | {"id": str(row[0]), "name": row[1], "description": row[2], "status": "1", |
| | | "user_id": str(row[4]), "mode": row[5], "parameters": {}} for row in results] |
| | | "user_id": str(row[4]), "mode": row[5], "parameters": {}} for row in results if str(row[0]) not in chat_ids] |
| | | return formatted_results |
| | | finally: |
| | | db.close() |
| | |
| | | for app in app_register: |
| | | try: |
| | | if app["id"] == RAGFLOW: |
| | | ragflow_data = get_data_from_ragflow_v2([], app["name"]) |
| | | ragflow_data = get_data_from_ragflow_v2(db, [], app["name"]) |
| | | if ragflow_data: |
| | | update_ids_in_local_v2(ragflow_data, "1") |
| | | elif app["id"] == DIFY: |
| | | dify_data = get_data_from_dy_v2([]) |
| | | dify_data = get_data_from_dy_v2(db, []) |
| | | if dify_data: |
| | | update_ids_in_local_v2(dify_data, "4") |
| | | except Exception as e: |