18个文件已修改
1 文件已重命名
2个文件已添加
New file |
| | |
| | | """dialogs add parameters |
| | | |
| | | Revision ID: 019bbe8d4833 |
| | | Revises: 37606c5a9b9e |
| | | Create Date: 2025-01-15 11:26:21.253007 |
| | | |
| | | """ |
| | | from typing import Sequence, Union |
| | | |
| | | from alembic import op |
| | | import sqlalchemy as sa |
| | | from sqlalchemy.dialects import mysql |
| | | |
| | | # revision identifiers, used by Alembic. |
| | | revision: str = '019bbe8d4833' |
| | | down_revision: Union[str, None] = '37606c5a9b9e' |
| | | branch_labels: Union[str, Sequence[str], None] = None |
| | | depends_on: Union[str, Sequence[str], None] = None |
| | | |
| | | |
| | | def upgrade() -> None: |
| | | # ### commands auto generated by Alembic - please adjust! ### |
| | | op.drop_table('user_tenant') |
| | | op.drop_table('knowledgebase') |
| | | op.drop_table('apps') |
| | | op.drop_table('dialog') |
| | | op.drop_table('flow') |
| | | op.add_column('dialogs', sa.Column('parameters', sa.Text(), nullable=True)) |
| | | # ### end Alembic commands ### |
| | | |
| | | |
| | | def downgrade() -> None: |
| | | # ### commands auto generated by Alembic - please adjust! ### |
| | | op.drop_column('dialogs', 'parameters') |
| | | op.create_table('flow', |
| | | sa.Column('id', mysql.VARCHAR(length=255), nullable=False), |
| | | sa.Column('name', mysql.VARCHAR(length=255), nullable=False), |
| | | sa.Column('status', mysql.INTEGER(), autoincrement=False, nullable=False), |
| | | sa.Column('description', mysql.VARCHAR(length=255), nullable=False), |
| | | sa.Column('user_id', mysql.INTEGER(), autoincrement=False, nullable=False), |
| | | sa.PrimaryKeyConstraint('id'), |
| | | mysql_collate='utf8mb4_0900_ai_ci', |
| | | mysql_default_charset='utf8mb4', |
| | | mysql_engine='InnoDB' |
| | | ) |
| | | op.create_table('dialog', |
| | | sa.Column('id', mysql.VARCHAR(length=255), nullable=False), |
| | | sa.Column('name', mysql.VARCHAR(length=255), nullable=False), |
| | | sa.Column('status', mysql.VARCHAR(length=1), nullable=False), |
| | | sa.Column('description', mysql.VARCHAR(length=255), nullable=False), |
| | | sa.Column('tenant_id', mysql.VARCHAR(length=36), nullable=False), |
| | | sa.PrimaryKeyConstraint('id'), |
| | | mysql_collate='utf8mb4_0900_ai_ci', |
| | | mysql_default_charset='utf8mb4', |
| | | mysql_engine='InnoDB' |
| | | ) |
| | | op.create_table('apps', |
| | | sa.Column('id', mysql.VARCHAR(length=36), nullable=False), |
| | | sa.Column('name', mysql.VARCHAR(length=255), nullable=False), |
| | | sa.Column('status', mysql.VARCHAR(length=16), nullable=False), |
| | | sa.Column('description', mysql.TEXT(), nullable=False), |
| | | sa.Column('tenant_id', mysql.VARCHAR(length=36), nullable=False), |
| | | sa.Column('mode', mysql.VARCHAR(length=36), nullable=False), |
| | | sa.PrimaryKeyConstraint('id'), |
| | | mysql_collate='utf8mb4_0900_ai_ci', |
| | | mysql_default_charset='utf8mb4', |
| | | mysql_engine='InnoDB' |
| | | ) |
| | | op.create_table('knowledgebase', |
| | | sa.Column('id', mysql.VARCHAR(length=36), nullable=False), |
| | | sa.Column('name', mysql.VARCHAR(length=128), nullable=True), |
| | | sa.Column('permission', mysql.VARCHAR(length=32), nullable=True), |
| | | sa.Column('tenant_id', mysql.VARCHAR(length=32), nullable=True), |
| | | sa.Column('description', mysql.TEXT(), nullable=True), |
| | | sa.Column('status', mysql.VARCHAR(length=1), nullable=True), |
| | | sa.Column('doc_num', mysql.INTEGER(), autoincrement=False, nullable=True), |
| | | sa.PrimaryKeyConstraint('id'), |
| | | mysql_collate='utf8mb4_0900_ai_ci', |
| | | mysql_default_charset='utf8mb4', |
| | | mysql_engine='InnoDB' |
| | | ) |
| | | op.create_table('user_tenant', |
| | | sa.Column('id', mysql.VARCHAR(length=36), nullable=False), |
| | | sa.Column('tenant_id', mysql.VARCHAR(length=32), nullable=True), |
| | | sa.Column('user_id', mysql.VARCHAR(length=32), nullable=True), |
| | | sa.Column('role', mysql.VARCHAR(length=32), nullable=True), |
| | | sa.PrimaryKeyConstraint('id'), |
| | | mysql_collate='utf8mb4_0900_ai_ci', |
| | | mysql_default_charset='utf8mb4', |
| | | mysql_engine='InnoDB' |
| | | ) |
| | | # ### end Alembic commands ### |
New file |
| | |
| | | """account token |
| | | |
| | | Revision ID: 37606c5a9b9e |
| | | Revises: |
| | | Create Date: 2025-01-15 09:57:58.619279 |
| | | |
| | | """ |
| | | from typing import Sequence, Union |
| | | |
| | | from alembic import op |
| | | import sqlalchemy as sa |
| | | from sqlalchemy.dialects import mysql |
| | | |
| | | # revision identifiers, used by Alembic. |
| | | revision: str = '37606c5a9b9e' |
| | | down_revision: Union[str, None] = None |
| | | branch_labels: Union[str, Sequence[str], None] = None |
| | | depends_on: Union[str, Sequence[str], None] = None |
| | | |
| | | |
| | | def upgrade() -> None: |
| | | # ### commands auto generated by Alembic - please adjust! ### |
| | | op.drop_table('flow') |
| | | op.drop_table('dialog') |
| | | op.drop_table('apps') |
| | | op.drop_table('user_tenant') |
| | | op.drop_table('knowledgebase') |
| | | op.drop_index('session_id_ix', table_name='chat_sessions') |
| | | op.drop_index('tenant_id_ix', table_name='chat_sessions') |
| | | op.drop_index('update_tine_ix', table_name='chat_sessions') |
| | | op.drop_table('chat_sessions') |
| | | op.alter_column('chat_api_tokens', 'app_id', |
| | | existing_type=mysql.VARCHAR(charset='utf8mb3', collation='utf8mb3_general_ci', length=36), |
| | | nullable=True) |
| | | op.alter_column('chat_api_tokens', 'type', |
| | | existing_type=mysql.VARCHAR(charset='utf8mb3', collation='utf8mb3_general_ci', length=16), |
| | | nullable=True) |
| | | op.drop_index('app_id_ix', table_name='chat_api_tokens') |
| | | op.create_index(op.f('ix_chat_api_tokens_app_id'), 'chat_api_tokens', ['app_id'], unique=False) |
| | | op.drop_index('update_ix_index', table_name='conversation') |
| | | # ### end Alembic commands ### |
| | | |
| | | |
| | | def downgrade() -> None: |
| | | # ### commands auto generated by Alembic - please adjust! ### |
| | | op.create_index('update_ix_index', 'conversation', ['update_time'], unique=False) |
| | | op.drop_index(op.f('ix_chat_api_tokens_app_id'), table_name='chat_api_tokens') |
| | | op.create_index('app_id_ix', 'chat_api_tokens', ['app_id'], unique=False) |
| | | op.alter_column('chat_api_tokens', 'type', |
| | | existing_type=mysql.VARCHAR(charset='utf8mb3', collation='utf8mb3_general_ci', length=16), |
| | | nullable=False) |
| | | op.alter_column('chat_api_tokens', 'app_id', |
| | | existing_type=mysql.VARCHAR(charset='utf8mb3', collation='utf8mb3_general_ci', length=36), |
| | | nullable=False) |
| | | op.create_table('chat_sessions', |
| | | sa.Column('id', mysql.VARCHAR(charset='utf8mb3', collation='utf8mb3_general_ci', length=36), nullable=False), |
| | | sa.Column('name', mysql.VARCHAR(charset='utf8mb3', collation='utf8mb3_general_ci', length=255), nullable=True), |
| | | sa.Column('agent_id', mysql.VARCHAR(charset='utf8mb3', collation='utf8mb3_general_ci', length=255), nullable=True), |
| | | sa.Column('agent_type', mysql.INTEGER(), autoincrement=False, nullable=True), |
| | | sa.Column('create_date', mysql.DATETIME(), nullable=True), |
| | | sa.Column('update_date', mysql.DATETIME(), nullable=True), |
| | | sa.Column('tenant_id', mysql.INTEGER(), autoincrement=False, nullable=True), |
| | | sa.Column('message', mysql.LONGTEXT(charset='utf8mb3', collation='utf8mb3_general_ci'), nullable=True), |
| | | sa.Column('reference', mysql.LONGTEXT(charset='utf8mb3', collation='utf8mb3_general_ci'), nullable=True), |
| | | sa.Column('conversation_id', mysql.VARCHAR(charset='utf8mb3', collation='utf8mb3_general_ci', length=36), nullable=True), |
| | | sa.Column('event_type', mysql.VARCHAR(charset='utf8mb3', collation='utf8mb3_general_ci', length=16), nullable=True), |
| | | sa.Column('session_type', mysql.VARCHAR(charset='utf8mb3', collation='utf8mb3_general_ci', length=16), nullable=True), |
| | | sa.PrimaryKeyConstraint('id'), |
| | | mysql_default_charset='utf8mb3', |
| | | mysql_engine='InnoDB', |
| | | mysql_row_format='DYNAMIC' |
| | | ) |
| | | op.create_index('update_tine_ix', 'chat_sessions', ['update_date'], unique=False) |
| | | op.create_index('tenant_id_ix', 'chat_sessions', ['tenant_id'], unique=False) |
| | | op.create_index('session_id_ix', 'chat_sessions', ['conversation_id'], unique=False) |
| | | op.create_table('knowledgebase', |
| | | sa.Column('id', mysql.VARCHAR(length=36), nullable=False), |
| | | sa.Column('name', mysql.VARCHAR(length=128), nullable=True), |
| | | sa.Column('create_date', mysql.DATETIME(), nullable=True), |
| | | sa.Column('update_date', mysql.DATETIME(), nullable=True), |
| | | sa.Column('tenant_id', mysql.VARCHAR(length=32), nullable=True), |
| | | sa.Column('description', mysql.TEXT(), nullable=True), |
| | | sa.Column('status', mysql.VARCHAR(length=1), nullable=True), |
| | | sa.Column('documents', mysql.INTEGER(), autoincrement=False, nullable=True), |
| | | sa.Column('icon', mysql.VARCHAR(length=128), nullable=True), |
| | | sa.Column('knowledge_type', mysql.VARCHAR(length=1), nullable=True), |
| | | sa.Column('permission', mysql.VARCHAR(length=32), nullable=True), |
| | | sa.PrimaryKeyConstraint('id'), |
| | | mysql_collate='utf8mb4_0900_ai_ci', |
| | | mysql_default_charset='utf8mb4', |
| | | mysql_engine='InnoDB' |
| | | ) |
| | | op.create_table('user_tenant', |
| | | sa.Column('id', mysql.VARCHAR(length=36), nullable=False), |
| | | sa.Column('tenant_id', mysql.VARCHAR(length=32), nullable=True), |
| | | sa.Column('user_id', mysql.VARCHAR(length=32), nullable=True), |
| | | sa.Column('role', mysql.VARCHAR(length=32), nullable=True), |
| | | sa.PrimaryKeyConstraint('id'), |
| | | mysql_collate='utf8mb4_0900_ai_ci', |
| | | mysql_default_charset='utf8mb4', |
| | | mysql_engine='InnoDB' |
| | | ) |
| | | op.create_table('apps', |
| | | sa.Column('id', mysql.VARCHAR(length=36), nullable=False), |
| | | sa.Column('name', mysql.VARCHAR(length=255), nullable=False), |
| | | sa.Column('status', mysql.VARCHAR(length=16), nullable=False), |
| | | sa.Column('description', mysql.TEXT(), nullable=False), |
| | | sa.Column('tenant_id', mysql.VARCHAR(length=36), nullable=False), |
| | | sa.PrimaryKeyConstraint('id'), |
| | | mysql_collate='utf8mb4_0900_ai_ci', |
| | | mysql_default_charset='utf8mb4', |
| | | mysql_engine='InnoDB' |
| | | ) |
| | | op.create_table('dialog', |
| | | sa.Column('id', mysql.VARCHAR(length=255), nullable=False), |
| | | sa.Column('name', mysql.VARCHAR(length=255), nullable=False), |
| | | sa.Column('status', mysql.VARCHAR(length=1), nullable=False), |
| | | sa.Column('description', mysql.VARCHAR(length=255), nullable=False), |
| | | sa.Column('tenant_id', mysql.VARCHAR(length=36), nullable=False), |
| | | sa.PrimaryKeyConstraint('id'), |
| | | mysql_collate='utf8mb4_0900_ai_ci', |
| | | mysql_default_charset='utf8mb4', |
| | | mysql_engine='InnoDB' |
| | | ) |
| | | op.create_table('flow', |
| | | sa.Column('id', mysql.VARCHAR(length=255), nullable=False), |
| | | sa.Column('name', mysql.VARCHAR(length=255), nullable=False), |
| | | sa.Column('status', mysql.INTEGER(), autoincrement=False, nullable=False), |
| | | sa.Column('description', mysql.VARCHAR(length=255), nullable=False), |
| | | sa.Column('user_id', mysql.INTEGER(), autoincrement=False, nullable=False), |
| | | sa.PrimaryKeyConstraint('id'), |
| | | mysql_collate='utf8mb4_0900_ai_ci', |
| | | mysql_default_charset='utf8mb4', |
| | | mysql_engine='InnoDB' |
| | | ) |
| | | # ### end Alembic commands ### |
| | |
| | | user = authenticate_user(db, login_data.username, password) |
| | | if not user: |
| | | return Response(code=400, msg="Incorrect username or password") |
| | | """ |
| | | app_register = AppRegisterDao(db).get_apps() |
| | | token_dict = {} |
| | | for app in app_register: |
| | |
| | | token_dict[app["id"]] = token |
| | | except Exception as e: |
| | | return Response(code=500, msg=f"Failed to login with {app['id']}: {str(e)}") |
| | | |
| | | """ |
| | | # 创建本地token |
| | | access_token = create_access_token(data={"sub": user.username, "user_id": user.id}) |
| | | |
| | | await update_token(db, user.id, access_token, token_dict) |
| | | await update_user_token(db, user.id, token_dict) |
| | | # await update_token(db, user.id, access_token, token_dict) |
| | | # await update_user_token(db, user.id, token_dict) |
| | | ''' |
| | | result = await pdb.execute(select(AppToken).where(AppToken.id == user.id)) |
| | | db_app_token = result.scalars().first() |
| | | if isinstance(access_token, bytes): |
| | |
| | | db_app_token.app_token = json.dumps(token_dict) |
| | | await pdb.commit() |
| | | await pdb.refresh(db_app_token) |
| | | ''' |
| | | return Response(code=200, msg="Login successful", data={ |
| | | "access_token": access_token, |
| | | "token_type": "bearer", |
| | |
| | | db_user = db.query(UserModel).filter(UserModel.username == user.username).first() |
| | | if db_user: |
| | | return Response(code=200, msg="Username already registered") |
| | | """ |
| | | app_register = AppRegisterDao(db).get_apps() |
| | | register_dict = {} |
| | | token = "" |
| | |
| | | register_dict[app['id']] = {"id":register_info.get("id"), "name": name, "email": register_info.get("email")} |
| | | except Exception as e: |
| | | return Response(code=500, msg=f"Failed to register with {app['id']}: {str(e)}") |
| | | user_id = await save_register_user(db, user.username, password, user.email, app_password, register_dict) |
| | | """ |
| | | user_id = await save_register_user(db, user.username, password, user.email, "", {}) |
| | | if not user_id: |
| | | return Response(code=500, msg=f"Failed to register with app") |
| | | return Response(code=200, msg="User registered successfully",data={"userFlag": user_id}) |
| | |
| | | data = await service_chat_parameters(db, chatId, 1) |
| | | if not data: |
| | | status_code = http_400 |
| | | return Response(json.dumps(data), media_type="application/json", status_code=status_code) |
| | | data = "{}" |
| | | return Response(data, media_type="application/json", status_code=status_code) |
| | | |
| | | # @chat_router_v2.get("/{chatId}/parameters") |
| | | # async def api_chat_parameters(chatId:str, db: Session = Depends(get_db)): # current_user: UserModel = Depends(get_current_user) |
| | |
| | | secret_key: your-secret-key |
| | | sgb_base_url: http://192.168.20.116:13001 |
| | | sgb_websocket_url: ws://192.168.20.116:13001 |
| | | fwr_base_url: http://192.168.20.116:11080 |
| | | database_url: mysql+pymysql://root:rag_gateway@192.168.20.116:23306/rag_gateway |
| | | sgb_base_url: http://192.168.20.119:13001 |
| | | sgb_websocket_url: ws://192.168.20.119:13001 |
| | | fwr_base_url: http://192.168.20.119:11080 |
| | | database_url: mysql+pymysql://root:infini_rag_flow@192.168.20.119:5455/rag_basic |
| | | sgb_db_url: mysql+pymysql://root:1234@192.168.20.119:13306/bisheng |
| | | fwr_db_url: mysql+pymysql://root:infini_rag_flow@192.168.20.116:15455/rag_flow |
| | | fwr_db_url: mysql+pymysql://root:infini_rag_flow@192.168.20.119:15455/rag_flow |
| | | PUBLIC_KEY: | |
| | | -----BEGIN PUBLIC KEY----- |
| | | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArq9XTUSeYr2+N1h3Afl/z8Dse/2yD0ZGrKwx+EEEcdsBLca9Ynmx3nIB5obmLlSfmskLpBo0UACBmB5rEjBp2Q2f3AG3Hjd4B+gNCG6BDaawuDlgANIhGnaTLrIqWrrcm4EMzJOnAOI1fgzJRsOOUEfaS318Eq9OVO3apEyCCt0lOQK6PuksduOjVxtltDav+guVAA068NrPYmRNabVKRNLJpL8w4D44sfth5RvZ3q9t+6RTArpEtc5sh5ChzvqPOzKGMXW83C95TxmXqpbK6olN4RevSfVjEAgCydH6HN6OhtOQEcnrU97r9H0iZOWwbw3pVrZiUkuRD1R56Wzs2wIDAQAB |
| | |
| | | basic_paper_url: http://192.168.20.231:8000 |
| | | dify_base_url: http://192.168.20.116 |
| | | dify_api_token: app-YmOAMDsPpDDlqryMHnc9TzTO |
| | | postgresql_database_url: postgresql+asyncpg://kong:kongpass@192.168.20.116:15433/kong |
| | | postgresql_database_url: postgresql+asyncpg://kong:kongpass@192.168.20.119:5432/kong |
| | | dify_workflow_clean: app-OpF0drPu0XcgqcekQpT4FA8a |
| | | dify_workflow_report: app-0MAkdFWqh9zxwmU69O0BFU1s |
| | | dify_database_url: postgresql+psycopg2://postgres:difyai123456@192.168.20.116:15432/dify |
| | | |
| | | |
| | | |
File was renamed from app/config/env_conf/config1.yaml |
| | |
| | | secret_key: your-secret-key |
| | | sgb_base_url: http://192.168.20.119:13001 |
| | | sgb_websocket_url: ws://192.168.20.119:13001 |
| | | fwr_base_url: http://192.168.20.119:11080 |
| | | database_url: mysql+pymysql://root:infini_rag_flow@192.168.20.119:5455/rag_basic |
| | | sgb_base_url: http://192.168.20.116:13001 |
| | | sgb_websocket_url: ws://192.168.20.116:13001 |
| | | fwr_base_url: http://192.168.20.116:11080 |
| | | database_url: mysql+pymysql://root:rag_gateway@192.168.20.116:23306/rag_gateway |
| | | sgb_db_url: mysql+pymysql://root:1234@192.168.20.119:13306/bisheng |
| | | fwr_db_url: mysql+pymysql://root:infini_rag_flow@192.168.20.119:15455/rag_flow |
| | | fwr_db_url: mysql+pymysql://root:infini_rag_flow@192.168.20.116:15455/rag_flow |
| | | PUBLIC_KEY: | |
| | | -----BEGIN PUBLIC KEY----- |
| | | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArq9XTUSeYr2+N1h3Afl/z8Dse/2yD0ZGrKwx+EEEcdsBLca9Ynmx3nIB5obmLlSfmskLpBo0UACBmB5rEjBp2Q2f3AG3Hjd4B+gNCG6BDaawuDlgANIhGnaTLrIqWrrcm4EMzJOnAOI1fgzJRsOOUEfaS318Eq9OVO3apEyCCt0lOQK6PuksduOjVxtltDav+guVAA068NrPYmRNabVKRNLJpL8w4D44sfth5RvZ3q9t+6RTArpEtc5sh5ChzvqPOzKGMXW83C95TxmXqpbK6olN4RevSfVjEAgCydH6HN6OhtOQEcnrU97r9H0iZOWwbw3pVrZiUkuRD1R56Wzs2wIDAQAB |
| | |
| | | basic_paper_url: http://192.168.20.231:8000 |
| | | dify_base_url: http://192.168.20.116 |
| | | dify_api_token: app-YmOAMDsPpDDlqryMHnc9TzTO |
| | | postgresql_database_url: postgresql+asyncpg://kong:kongpass@192.168.20.119:5432/kong |
| | | postgresql_database_url: postgresql+asyncpg://kong:kongpass@192.168.20.116:15433/kong |
| | | dify_workflow_clean: app-OpF0drPu0XcgqcekQpT4FA8a |
| | | dify_workflow_report: app-0MAkdFWqh9zxwmU69O0BFU1s |
| | | dify_database_url: postgresql+psycopg2://postgres:difyai123456@192.168.20.116:15432/dify |
| | | |
| | | |
| | | |
| | |
| | | "name": "报表合并", |
| | | "description": "报表合并", |
| | | "icon": "intellFrame4", |
| | | "agentType": "excelMerge" |
| | | "agentType": "excelMerge", |
| | | "parameters": { |
| | | "retriever_resource": { |
| | | "enabled": false |
| | | }, |
| | | "user_input_form": [ |
| | | { |
| | | "file-list": { |
| | | "allowed_file_extensions": [ |
| | | "xlsx" |
| | | ], |
| | | "allowed_file_types": [ |
| | | "document" |
| | | ], |
| | | "allowed_file_upload_methods": [ |
| | | "local_file" |
| | | ], |
| | | "label": "文档解析站", |
| | | "max_length": 30, |
| | | "options": [], |
| | | "required": true, |
| | | "type": "file-list", |
| | | "variable": "file_list" |
| | | } |
| | | } |
| | | ], |
| | | "file_upload":{ |
| | | "enabled": false |
| | | } |
| | | } |
| | | }, |
| | | { |
| | | "id": "basic_excel_talk", |
| | | "name": "智能数据", |
| | | "description": "智能数据", |
| | | "icon": "intellFrame4", |
| | | "agentType": "excelTalk" |
| | | "agentType": "excelTalk", |
| | | "parameters": { |
| | | "retriever_resource": { |
| | | "enabled": true |
| | | }, |
| | | "user_input_form": [ |
| | | { |
| | | "file-list": { |
| | | "allowed_file_extensions": [ |
| | | "xlsx", "xls","csv","db" |
| | | ], |
| | | "allowed_file_types": [ |
| | | "document" |
| | | ], |
| | | "allowed_file_upload_methods": [ |
| | | "local_file" |
| | | ], |
| | | "label": "上传文档", |
| | | "max_length": 30, |
| | | "options": [], |
| | | "required": true, |
| | | "type": "file-list", |
| | | "variable": "file_list", |
| | | "fileUploadConfig": { |
| | | "file_size_limit": 30, |
| | | "batch_count_limit": 5, |
| | | "image_file_size_limit": 10, |
| | | "video_file_size_limit": 100, |
| | | "audio_file_size_limit": 50, |
| | | "workflow_file_upload_limit": 100 |
| | | } |
| | | } |
| | | } |
| | | ], |
| | | "file_upload":{ |
| | | "enabled": false |
| | | } |
| | | } |
| | | }, |
| | | { |
| | | "id": "basic_question_talk", |
| | | "name": "出题组卷", |
| | | "description": "出题组卷", |
| | | "icon": "intellFrame4", |
| | | "agentType": "questionTalk" |
| | | "agentType": "questionTalk", |
| | | "parameters": { |
| | | "retriever_resource": { |
| | | "enabled": true |
| | | }, |
| | | { |
| | | "id": "basic_paper_talk", |
| | | "name": "文档出卷", |
| | | "description": "文档出卷", |
| | | "icon": "intellFrame4", |
| | | "agentType": "paperTalk" |
| | | "user_input_form": [], |
| | | "file_upload":{ |
| | | "enabled": false |
| | | } |
| | | } |
| | | } |
| | | ], |
| | | "bs": [] |
| | |
| | | from app.models.base_model import SessionLocal |
| | | from app.service.v2.initialize_data import dialog_menu_sync, default_group_sync, default_role_sync, app_register_sync, \ |
| | | basic_agent_sync, admin_account_sync |
| | | from app.task.fetch_agent import sync_resources_from_json |
| | | |
| | | |
| | | async def sync_default_data(): |
| | |
| | | from .public_api_model import * |
| | | from .menu_model import * |
| | | from .label_model import * |
| | | from .v2.session_model import * |
| | | |
| | | |
| | | # 获取当前时区的时间 |
| | |
| | | dialog_type = Column(String(1)) # 平台 |
| | | # agent_id = Column(String(36)) |
| | | mode = Column(String(36)) |
| | | parameters = Column(Text) |
| | | |
| | | def get_id(self): |
| | | return str(self.id) |
| | |
| | | |
| | | class ApiTokenModel(Base): |
| | | __tablename__ = "chat_api_tokens" |
| | | id = Column(String(32), primary_key=True) |
| | | app_id = Column(String(32), index=True) |
| | | id = Column(String(36), primary_key=True) |
| | | app_id = Column(String(36), index=True) |
| | | type = Column(String(16)) |
| | | token = Column(String(255)) |
| | | created_at = Column(DateTime, default=datetime.now()) |
| | |
| | | 'access_token': self.access_token, |
| | | 'refresh_token': self.refresh_token, |
| | | } |
| | | @staticmethod |
| | | def encrypted_password(password): |
| | | return cipher_suite.encrypt(password.encode("utf-8")).decode("utf-8") |
| | | |
| | | @staticmethod |
| | | def decrypted_password(password): |
| | | return cipher_suite.decrypt(password).decode("utf-8") |
| | |
| | | try: |
| | | hashed_password = pwd_context.hash(password) |
| | | db_user = UserModel(username=username, hashed_password=hashed_password, email=email, sync_flag=sync_flag) |
| | | pwd = db_user.encrypted_password(app_password) |
| | | db_user.password = pwd |
| | | # pwd = db_user.encrypted_password(app_password) |
| | | # db_user.password = pwd |
| | | db_user.roles = [db.query(RoleModel).filter(RoleModel.role_type == 2).first()] |
| | | db_user.groups = [db.query(GroupModel).filter(GroupModel.group_type == 2).first()] |
| | | db.add(db_user) |
| | | db.commit() |
| | | db.refresh(db_user) |
| | | ''' |
| | | user_id = db_user.id |
| | | for k, v in register_dict.items(): |
| | | await UserAppDao(db).update_and_insert_data(v.get("name"), pwd, v.get("email"), user_id, str(v.get("id")), k) |
| | | |
| | | ''' |
| | | except Exception as e: |
| | | logger.error(e) |
| | | # db.roolback() |
| | | if user_id: |
| | | db.query(UserModel).filter(UserModel.id == user_id).delete() |
| | | db.commit |
| | | db.rollback() |
| | | return False |
| | | return sync_flag |
| | | |
| | |
| | | |
| | | async def create_user(db, user_name, email, phone, login_name, password, roles, groups, user_id): |
| | | try: |
| | | app_register = AppRegisterDao(db).get_apps() |
| | | |
| | | register_dict = {} |
| | | token = "" |
| | | |
| | | """ |
| | | app_password = await generate_password() |
| | | app_register = AppRegisterDao(db).get_apps() |
| | | for app in app_register: |
| | | if app["id"] == RAGFLOW: |
| | | service = RagflowService(settings.fwr_base_url) |
| | |
| | | except Exception as e: |
| | | logger.error(e) |
| | | return False |
| | | |
| | | """ |
| | | # 存储用户信息 |
| | | hashed_password = pwd_context.hash(password) |
| | | sync_flag = str(uuid.uuid4()) |
| | | user_model = UserModel(username=user_name, hashed_password=hashed_password, email=email, |
| | | ## ragflow_id=ragflow_info.get("id"),bisheng_id=bisheng_info.get("user_id"), |
| | | phone=phone, login_name=login_name,sync_flag=sync_flag) |
| | | pwd = user_model.encrypted_password(app_password) |
| | | # pwd = user_model.encrypted_password(app_password) |
| | | # user_model.password = pwd |
| | | user_model.roles = [db.get(RoleModel, roleId) for roleId in roles] |
| | | user_model.password = pwd |
| | | if groups: |
| | | user_model.groups = [db.get(GroupModel, groupId) for groupId in groups] |
| | | user_model.creator = user_id |
| | | db.add(user_model) |
| | | db.commit() |
| | | db.refresh(user_model) |
| | | """ |
| | | u_id = user_model.id |
| | | user_app_dao = UserAppDao(db) |
| | | for k, v in register_dict.items(): |
| | | await user_app_dao.update_and_insert_data(v.get("name"), pwd, v.get("email"), u_id, str(v.get("id")), k) |
| | | """ |
| | | except Exception as e: |
| | | logger.error(e) |
| | | # db.rollback() |
| | |
| | | async def chat_post(self, url, data, headers): |
| | | |
| | | res = await self.http_post(url, data, headers) |
| | | if res.status_code == 200: |
| | | if res.status_code == 200 or res.status_code == 201: |
| | | return res.json() |
| | | else: |
| | | return {} |
| | |
| | | chat_info = db.query(DialogModel).filter_by(id=chat_id).first() |
| | | if not chat_info: |
| | | return {} |
| | | if chat_info.dialog_type == RG_TYPE: |
| | | return {"retriever_resource": |
| | | { |
| | | "enabled": True |
| | | } |
| | | } |
| | | elif chat_info.dialog_type == BASIC_TYPE: |
| | | ... |
| | | elif chat_info.dialog_type == DF_TYPE: |
| | | token = await get_chat_token(db, chat_id) |
| | | if not token: |
| | | return {} |
| | | url = settings.dify_base_url + DF_CHAT_PARAMETERS |
| | | chat = ChatBaseApply() |
| | | return await chat.chat_get(url, {"user": str(user_id)}, await chat.get_headers(token)) |
| | | return chat_info.parameters |
| | | # if chat_info.dialog_type == RG_TYPE: |
| | | # return {"retriever_resource": |
| | | # { |
| | | # "enabled": True |
| | | # } |
| | | # } |
| | | # elif chat_info.dialog_type == BASIC_TYPE: |
| | | # ... |
| | | # elif chat_info.dialog_type == DF_TYPE: |
| | | # token = await get_chat_token(db, chat_id) |
| | | # if not token: |
| | | # return {} |
| | | # url = settings.dify_base_url + DF_CHAT_PARAMETERS |
| | | # chat = ChatBaseApply() |
| | | # return await chat.chat_get(url, {"user": str(user_id)}, await chat.get_headers(token)) |
| | | |
| | | |
| | | async def service_chat_sessions(db, chat_id, name): |
| | |
| | | dialog.name = agent["name"] |
| | | dialog.description = agent["description"] |
| | | dialog.icon = agent["icon"] |
| | | dialog.parameters = json.dumps(agent["parameters"]) |
| | | db.commit() |
| | | except Exception as e: |
| | | logger.error(e) |
| | |
| | | try: |
| | | dialog = DialogModel(id=agent["id"], name=agent["name"], description=agent["description"], |
| | | icon=agent["icon"], tenant_id=user.id if user else "", dialog_type="3", |
| | | agent_id=agent["id"]) |
| | | agent_id=agent["id"], parameters = json.dumps(agent["parameters"])) |
| | | db.add(dialog) |
| | | db.commit() |
| | | db.refresh(dialog) |
| | |
| | | |
| | | def get_data_from_ragflow_v2(names: List[str]) -> List[Dict]: |
| | | db = SessionRagflow() |
| | | para = { |
| | | "user_input_form": [], |
| | | "retriever_resource": { |
| | | "enabled": True |
| | | }, |
| | | "file_upload": { |
| | | "enabled": False |
| | | } |
| | | } |
| | | try: |
| | | if names: |
| | | query = db.query(Dialog.id, Dialog.name, Dialog.description, Dialog.status, Dialog.tenant_id) \ |
| | |
| | | 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"} for row in results] |
| | | "user_id": str(row[4]), "mode": "agent-dialog", "parameters": para} for row in results] |
| | | return formatted_results |
| | | finally: |
| | | db.close() |
| | | |
| | | |
| | | def get_data_from_dify_v2(names: List[str]) -> List[Dict]: |
| | | def get_data_from_dy_v2(names: List[str]) -> List[Dict]: |
| | | db = SessionDify() |
| | | try: |
| | | if 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]} for row in results] |
| | | "user_id": str(row[4]), "mode": row[5], "parameters": {}} for row in results] |
| | | return formatted_results |
| | | finally: |
| | | db.close() |
| | |
| | | if existing_agent: |
| | | existing_agent.name = row["name"] |
| | | 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, mode=row["mode"]) |
| | | dialog_type=dialog_type, mode=row["mode"], parameters=json.dumps(row["parameters"])) |
| | | db.add(existing) |
| | | db.commit() |
| | | for dialog in db.query(DialogModel).filter_by(dialog_type=dialog_type).all(): |
| | |
| | | ragflow_data = get_data_from_ragflow_v2([]) |
| | | if ragflow_data: |
| | | update_ids_in_local_v2(ragflow_data, "1") |
| | | elif app["id"] == BISHENG: |
| | | bisheng_data = get_data_from_bisheng_v2([]) |
| | | if bisheng_data: |
| | | update_ids_in_local_v2(bisheng_data, "2") |
| | | # elif app["id"] == BISHENG: |
| | | # bisheng_data = get_data_from_bisheng_v2([]) |
| | | # if bisheng_data: |
| | | # update_ids_in_local_v2(bisheng_data, "2") |
| | | elif app["id"] == DIFY: |
| | | dify_data = get_data_from_dify_v2([]) |
| | | dify_data = get_data_from_dy_v2([]) |
| | | if dify_data: |
| | | update_ids_in_local_v2(dify_data, "4") |
| | | print("v2 Agents synchronized successfully") |
| | |
| | | 4.token获取:login |
| | | df:/console/api/workspaces |
| | | rg:/v1/system/version |
| | | 5.跟新本地token和kong网关token |
| | | :return: |
| | | """ |
| | |
| | | import random |
| | | import string |
| | | |
| | | from cryptography.fernet import Fernet |
| | | from app.config.config import settings |
| | | |
| | | cipher_suite = Fernet(settings.PASSWORD_KEY.encode("utf-8")) |
| | | |
| | | async def generate_password(length=10): |
| | | if length < 6: # 至少需要3位密码以包含所有必要的字符 |
| | |
| | | # 将列表转换为字符串 |
| | | return ''.join(password) |
| | | |
| | | |
| | | async def password_encrypted(password): |
| | | hash_pwd = cipher_suite.encrypt(password.encode("utf-8")).decode("utf-8") |
| | | print(hash_pwd) |
| | | return hash_pwd |
| | | |
| | | |
| | | async def password_decrypted(hash_password): |
| | | pwd = cipher_suite.decrypt(hash_password).decode("utf-8") |
| | | print(pwd) |
| | | return pwd |
| | | if __name__ == "__main__": |
| | | # 生成一个10位的密码 |
| | | asyncio.run(generate_password(10)) |
| | | # asyncio.run(generate_password(10)) |
| | | # password = generate_password(10) |
| | | # print(password) |
| | | |
| | | asyncio.run(password_encrypted("123456")) |
| | | asyncio.run(password_decrypted("gAAAAABnhyOiGUnAqK7FW_pHsXifje8WG1cirtF_eu3a44FrMYM3AkSBsWjsJrwpzUlD2GDzzZOS6yYu4Ie5gnkYuy8HVN3FBw==")) |
| | |
| | | |
| | | |
| | | |
| | | # await sync_default_data() |
| | | await sync_default_data() |
| | | # |
| | | # sync_agents_v2() |
| | | # sync_knowledge() |
| | | # sync_resources_from_json() |
| | | sync_agents_v2() |
| | | sync_knowledge() |
| | | sync_resources_from_json() |
| | | yield |
| | | # 在应用关闭时执行清理操作(如果需要) |
| | | pass |