From 55c7856a04a8e685c0a246563315a8cffd2f72d2 Mon Sep 17 00:00:00 2001 From: zstar <65890619+zstar1003@users.noreply.github.com> Date: Tue, 1 Apr 2025 00:37:22 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=E6=9C=AA?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84=E5=AF=BC=E5=85=A5=E5=92=8C=E5=86=97?= =?UTF-8?q?=E4=BD=99=E4=BB=A3=E7=A0=81=EF=BC=8C=E4=BF=AE=E5=A4=8D=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8C=96=E6=B5=8B=E8=AF=95=E6=8A=A5=E9=94=99=20(#9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 清理多个文件中的未使用导入和冗余代码,以提高代码的可读性和维护性。主要改动包括移除未使用的模块导入和删除重复的版权声明。 --- api/ragflow_server.py | 28 ++----------------- .../chatgpt-on-wechat/plugins/__init__.py | 16 ----------- management/server/app.py | 1 - management/server/database.py | 1 - management/server/utils.py | 2 -- rag/svr/task_executor.py | 28 ++----------------- sdk/python/ragflow_sdk/__init__.py | 21 ++------------ 7 files changed, 8 insertions(+), 89 deletions(-) diff --git a/api/ragflow_server.py b/api/ragflow_server.py index 8f2697f..0ea6cfa 100644 --- a/api/ragflow_server.py +++ b/api/ragflow_server.py @@ -1,26 +1,3 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# from beartype import BeartypeConf -# from beartype.claw import beartype_all # <-- you didn't sign up for this -# beartype_all(conf=BeartypeConf(violation_type=UserWarning)) # <-- emit warnings from all code - -from api.utils.log_utils import initRootLogger -initRootLogger("ragflow_server") - import logging import os import signal @@ -29,14 +6,12 @@ import time import traceback from concurrent.futures import ThreadPoolExecutor import threading - from werkzeug.serving import run_simple from api import settings from api.apps import app from api.db.runtime_config import RuntimeConfig from api.db.services.document_service import DocumentService from api import utils - from api.db.db_models import init_database_tables as init_web_db from api.db.init_data import init_web_data from api.versions import get_ragflow_version @@ -44,6 +19,9 @@ from api.utils import show_configs from rag.settings import print_rag_settings from rag.utils.redis_conn import RedisDistributedLock +from api.utils.log_utils import initRootLogger +initRootLogger("ragflow_server") + stop_event = threading.Event() def update_progress(): diff --git a/intergrations/chatgpt-on-wechat/plugins/__init__.py b/intergrations/chatgpt-on-wechat/plugins/__init__.py index 557f0d1..28032b8 100644 --- a/intergrations/chatgpt-on-wechat/plugins/__init__.py +++ b/intergrations/chatgpt-on-wechat/plugins/__init__.py @@ -1,19 +1,3 @@ -# -# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - from beartype.claw import beartype_this_package beartype_this_package() diff --git a/management/server/app.py b/management/server/app.py index b72a63b..918e098 100644 --- a/management/server/app.py +++ b/management/server/app.py @@ -1,6 +1,5 @@ from flask import Flask, jsonify, request from flask_cors import CORS -import mysql.connector import database app = Flask(__name__) diff --git a/management/server/database.py b/management/server/database.py index 167f8a3..c3accf3 100644 --- a/management/server/database.py +++ b/management/server/database.py @@ -1,7 +1,6 @@ import mysql.connector from utils import generate_uuid, encrypt_password from datetime import datetime -from tabulate import tabulate # 数据库连接配置 db_config = { diff --git a/management/server/utils.py b/management/server/utils.py index 8dcc70c..0ccac3a 100644 --- a/management/server/utils.py +++ b/management/server/utils.py @@ -1,6 +1,5 @@ import uuid import base64 -from datetime import datetime from Cryptodome.PublicKey import RSA from Cryptodome.Cipher import PKCS1_v1_5 from werkzeug.security import generate_password_hash @@ -24,5 +23,4 @@ def rsa_psw(password: str) -> str: # 加密密码 def encrypt_password(raw_password: str) -> str: base64_password = base64.b64encode(raw_password.encode()).decode() - encrypted_password = rsa_psw(base64_password) return generate_password_hash(base64_password) \ No newline at end of file diff --git a/rag/svr/task_executor.py b/rag/svr/task_executor.py index ea2ad7a..f112c1c 100644 --- a/rag/svr/task_executor.py +++ b/rag/svr/task_executor.py @@ -1,32 +1,9 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# from beartype import BeartypeConf -# from beartype.claw import beartype_all # <-- you didn't sign up for this -# beartype_all(conf=BeartypeConf(violation_type=UserWarning)) # <-- emit warnings from all code import random import sys - from api.utils.log_utils import initRootLogger, get_project_base_directory from graphrag.general.index import run_graphrag from graphrag.utils import get_llm_cache, set_llm_cache, get_tags_from_cache, set_tags_to_cache from rag.prompts import keyword_extraction, question_proposal, content_tagging - -CONSUMER_NO = "0" if len(sys.argv) < 2 else sys.argv[1] -CONSUMER_NAME = "task_executor_" + CONSUMER_NO - import logging import os from datetime import datetime @@ -43,10 +20,8 @@ import signal import trio import exceptiongroup import faulthandler - import numpy as np from peewee import DoesNotExist - from api.db import LLMType, ParserType, TaskStatus from api.db.services.document_service import DocumentService from api.db.services.llm_service import LLMBundle @@ -65,6 +40,9 @@ from rag.utils.redis_conn import REDIS_CONN from rag.utils.storage_factory import STORAGE_IMPL from graphrag.utils import chat_limiter +CONSUMER_NO = "0" if len(sys.argv) < 2 else sys.argv[1] +CONSUMER_NAME = "task_executor_" + CONSUMER_NO + BATCH_SIZE = 64 FACTORY = { diff --git a/sdk/python/ragflow_sdk/__init__.py b/sdk/python/ragflow_sdk/__init__.py index 7535aa4..32a25ed 100644 --- a/sdk/python/ragflow_sdk/__init__.py +++ b/sdk/python/ragflow_sdk/__init__.py @@ -1,24 +1,5 @@ -# -# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - from beartype.claw import beartype_this_package -beartype_this_package() - import importlib.metadata - from .ragflow import RAGFlow from .modules.dataset import DataSet from .modules.chat import Chat @@ -27,6 +8,8 @@ from .modules.document import Document from .modules.chunk import Chunk from .modules.agent import Agent +beartype_this_package() + __version__ = importlib.metadata.version("ragflow_sdk") __all__ = [