| | |
| | | except Exception as e: |
| | | print(e) |
| | | db.rollback() |
| | | |
| | | now_complex_list = [] |
| | | for agent in complex_list: |
| | | now_complex_list.append(agent["id"]) |
| | | dialog = db.query(ComplexChatModel).filter(ComplexChatModel.id == agent["id"]).first() |
| | | if dialog: |
| | | try: |
| | |
| | | except Exception as e: |
| | | print(e) |
| | | db.rollback() |
| | | |
| | | for i in db.query(ComplexChatModel).filter(ComplexChatModel.status == "1").all(): |
| | | if i.id not in now_complex_list: |
| | | try: |
| | | db.query(ComplexChatModel).filter(ComplexChatModel.id==i.id).update(({"status": "0"})) |
| | | db.commit() |
| | | except: |
| | | ... |
| | | |
| | | |
| | | |
| | | async def user_update_app(userid, db): |
| | |
| | | for i in complex_list: |
| | | user_token = db.query(ApiTokenModel).filter(ApiTokenModel.app_id == i.id).first() |
| | | if not user_token: |
| | | chat = ChatBaseApply() |
| | | url = settings.dify_base_url + DF_CHAT_API_KEY.format(i.id) |
| | | access_token = await get_app_token(db, workflow_server) |
| | | 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") |
| | | # dialog.parameters = json.dumps(param) |
| | | else: |
| | | param = await chat.chat_post(url, {}, await chat.get_headers(access_token)) |
| | | if param: |
| | | token = param.get("token") |
| | | token_id = param.get("id") |
| | | try: |
| | | chat = ChatBaseApply() |
| | | url = settings.dify_base_url + DF_CHAT_API_KEY.format(i.id) |
| | | access_token = await get_app_token(db, workflow_server) |
| | | 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") |
| | | # dialog.parameters = json.dumps(param) |
| | | else: |
| | | param = await chat.chat_post(url, {}, await chat.get_headers(access_token)) |
| | | if param: |
| | | token = param.get("token") |
| | | token_id = param.get("id") |
| | | |
| | | if token: |
| | | db.add(ApiTokenModel(id=token_id, app_id=i.id, type="app", token=token)) |
| | | db.commit() |
| | | print("df_api_token: 更新成功!") |
| | | if token: |
| | | db.add(ApiTokenModel(id=token_id, app_id=i.id, type="app", token=token)) |
| | | db.commit() |
| | | print("df_api_token: 更新成功!") |
| | | except Exception as e: |
| | | print(e) |
| | | |
| | | |
| | | except Exception as e: |
| | | print(e) |