| | |
| | | from app.config.agent_base_url import RG_APP_TOKEN_LIST, RG_APP_NEW_TOKEN, DF_CHAT_API_KEY |
| | | # from app.api import pwd_context |
| | | from app.config.const import DIFY, ENV_CONF_PATH, RAGFLOW, smart_server, chat_server, workflow_server, TMP_DICT, \ |
| | | rg_api_token |
| | | rg_api_token, Dialog_STATSU_ON |
| | | from app.models import MenuCapacityModel, WebMenuModel, GroupModel, RoleModel, DialogModel, UserModel, UserAppModel, \ |
| | | cipher_suite, UserTokenModel, ApiTokenModel, ComplexChatModel |
| | | from app.service.auth import UserAppDao |
| | |
| | | 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: |
| | |
| | | dialog.icon = agent["icon"] |
| | | dialog.mode = agent["mode"] |
| | | dialog.chat_mode = agent["chat_mode"] |
| | | dialog.status = Dialog_STATSU_ON |
| | | # dialog.parameters = json.dumps(agent["parameters"]) |
| | | db.commit() |
| | | except Exception as e: |
| | |
| | | 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) |