| | |
| | | else: |
| | | query = query.filter(DialogModel.status != Dialog_STATSU_DELETE) |
| | | id_list = [] |
| | | # if label: |
| | | # id_list = [i.object_id for i in db.query(LabelWorkerModel).filter(LabelWorkerModel.label_id==label).all()] |
| | | if user.permission != "admin": |
| | | dia_list = [j.id for i in user.groups for j in i.dialogs] |
| | | query = query.filter(or_(DialogModel.tenant_id == user_id, DialogModel.id.in_(dia_list))) |
| | | # else: |
| | | if label: |
| | | id_list = [i.object_id for i in db.query(LabelWorkerModel).filter(LabelWorkerModel.label_id == label).all()] |
| | | if user.permission != "admin": |
| | | dia_list = [j.id for i in user.groups for j in i.dialogs if not label or j.id in id_list] |
| | | query = query.filter(or_(DialogModel.tenant_id == user_id, DialogModel.id.in_(dia_list))) |
| | | else: |
| | | if label: |
| | | query = query.filter(or_(DialogModel.id.in_(id_list))) |
| | | query = query.filter(DialogModel.id.in_(id_list)) |
| | | |
| | | if keyword: |
| | | query = query.filter(DialogModel.name.like('%{}%'.format(keyword))) |
| | |
| | | |
| | | |
| | | async def create_dialog_service(db, dialog_id, dialog_name, description, icon, dialog_type, mode, user_id): |
| | | para = { |
| | | "user_input_form": [], |
| | | "retriever_resource": { |
| | | "enabled": True |
| | | }, |
| | | "file_upload": { |
| | | "enabled": False |
| | | } |
| | | } |
| | | try: |
| | | dialog_model = DialogModel(id=dialog_id, name=dialog_name, description=description, icon=icon, |
| | | dialog_type=dialog_type, tenant_id=user_id, mode=mode, update_date=datetime.now(), |
| | | create_date=datetime.now()) |
| | | create_date=datetime.now(), parameters=json.dumps(para)) |
| | | db.add(dialog_model) |
| | | db.commit() |
| | | db.refresh(dialog_model) |
| | |
| | | chat = ChatBaseApply() |
| | | token = await get_chat_token(db, dialog_id) |
| | | if not token: |
| | | workflow = await get_app_token(db, workflow_server) |
| | | if workflow: |
| | | access_token = await get_app_token(db, workflow_server) |
| | | # print(workflow) |
| | | if access_token: |
| | | url = settings.dify_base_url + DF_CHAT_API_KEY.format(dialog_id) |
| | | param = await chat.chat_get(url, {}, await chat.get_headers(workflow.access_token)) |
| | | param = await chat.chat_get(url, {}, await chat.get_headers(access_token)) |
| | | if param and param.get("data"): |
| | | token = param.get("data", [{}])[0].get("token") |
| | | token_id = param.get("data", [{}])[0].get("id") |
| | | await add_chat_token(db, {"id":token_id, "app_id": dialog_id, "type":"app", "token": token}) |
| | | # dialog.parameters = json.dumps(param) |
| | | else: |
| | | param = await chat.chat_post(url, {}, await chat.get_headers(workflow.access_token)) |
| | | param = await chat.chat_post(url, {}, await chat.get_headers(access_token)) |
| | | if param: |
| | | token = param.get("token") |
| | | token_id = param.get("id") |
| | |
| | | if user is None: |
| | | return {"rows": []} |
| | | query = db.query(DialogModel).filter(DialogModel.status != Dialog_STATSU_DELETE) |
| | | id_list = [] |
| | | if user.permission != "admin": |
| | | dia_list = [j.id for i in user.groups for j in i.dialogs] |
| | | query = query.filter(or_(DialogModel.tenant_id == user_id, DialogModel.id.in_(dia_list))) |
| | | |
| | | if label: |
| | | id_list = set( |
| | | [i.object_id for i in db.query(LabelWorkerModel).filter(LabelWorkerModel.label_id.in_(label)).all()]) |
| | | if user.permission != "admin": |
| | | dia_list = [j.id for i in user.groups for j in i.dialogs if not label or j.id in id_list] |
| | | query = query.filter(or_(DialogModel.tenant_id == user_id, DialogModel.id.in_(dia_list))) |
| | | else: |
| | | if label: |
| | | query = query.filter(or_(DialogModel.id.in_(id_list))) |
| | | query = query.filter(DialogModel.id.in_(id_list)) |
| | | |
| | | if keyword: |
| | | query = query.filter(DialogModel.name.like('%{}%'.format(keyword))) |