### What problem does this PR solve? 1. Remove unused code. 2. Move some codes from settings to constants ### Type of change - [x] Refactoring --------- Signed-off-by: jinhai <haijin.chn@gmail.com>tags/v0.14.0
| @@ -22,6 +22,7 @@ from flask import Blueprint, Flask | |||
| from werkzeug.wrappers.request import Request | |||
| from flask_cors import CORS | |||
| from flasgger import Swagger | |||
| from itsdangerous.url_safe import URLSafeTimedSerializer as Serializer | |||
| from api.db import StatusEnum | |||
| from api.db.db_models import close_connection | |||
| @@ -32,7 +33,7 @@ from flask_session import Session | |||
| from flask_login import LoginManager | |||
| from api import settings | |||
| from api.utils.api_utils import server_error_response | |||
| from itsdangerous.url_safe import URLSafeTimedSerializer as Serializer | |||
| from api.constants import API_VERSION | |||
| __all__ = ["app"] | |||
| @@ -119,7 +120,7 @@ def register_page(page_path): | |||
| spec.loader.exec_module(page) | |||
| page_name = getattr(page, "page_name", page_name) | |||
| url_prefix = ( | |||
| f"/api/{settings.API_VERSION}" if "/sdk/" in path else f"/{settings.API_VERSION}/{page_name}" | |||
| f"/api/{API_VERSION}" if "/sdk/" in path else f"/{API_VERSION}/{page_name}" | |||
| ) | |||
| app.register_blueprint(page.manager, url_prefix=url_prefix) | |||
| @@ -17,4 +17,9 @@ NAME_LENGTH_LIMIT = 2 ** 10 | |||
| IMG_BASE64_PREFIX = 'data:image/png;base64,' | |||
| SERVICE_CONF = "service_conf.yaml" | |||
| SERVICE_CONF = "service_conf.yaml" | |||
| API_VERSION = "v1" | |||
| RAG_FLOW_SERVICE_NAME = "ragflow" | |||
| REQUEST_WAIT_SEC = 2 | |||
| REQUEST_MAX_WAIT_SEC = 300 | |||
| @@ -23,13 +23,10 @@ import rag.utils | |||
| from rag.nlp import search | |||
| from graphrag import search as kg_search | |||
| from api.utils import get_base_config, decrypt_database_config | |||
| from api.constants import RAG_FLOW_SERVICE_NAME | |||
| API_VERSION = "v1" | |||
| RAG_FLOW_SERVICE_NAME = "ragflow" | |||
| LIGHTEN = int(os.environ.get('LIGHTEN', "0")) | |||
| REQUEST_WAIT_SEC = 2 | |||
| REQUEST_MAX_WAIT_SEC = 300 | |||
| LLM = None | |||
| LLM_FACTORY = None | |||
| LLM_BASE_URL = None | |||
| @@ -173,15 +170,6 @@ def init_settings(): | |||
| retrievaler = search.Dealer(docStoreConn) | |||
| kg_retrievaler = kg_search.KGSearch(docStoreConn) | |||
| def get_host_ip(): | |||
| global HOST_IP | |||
| return HOST_IP | |||
| def get_host_port(): | |||
| global HOST_PORT | |||
| return HOST_PORT | |||
| class CustomEnum(Enum): | |||
| @classmethod | |||
| @@ -201,16 +189,6 @@ class CustomEnum(Enum): | |||
| return [member.name for member in cls.__members__.values()] | |||
| class PythonDependenceName(CustomEnum): | |||
| Rag_Source_Code = "python" | |||
| Python_Env = "miniconda" | |||
| class ModelStorage(CustomEnum): | |||
| REDIS = "redis" | |||
| MYSQL = "mysql" | |||
| class RetCode(IntEnum, CustomEnum): | |||
| SUCCESS = 0 | |||
| NOT_EFFECTIVE = 10 | |||
| @@ -39,6 +39,7 @@ from api import settings | |||
| from api import settings | |||
| from api.utils import CustomJSONEncoder, get_uuid | |||
| from api.utils import json_dumps | |||
| from api.constants import REQUEST_WAIT_SEC, REQUEST_MAX_WAIT_SEC | |||
| requests.models.complexjson.dumps = functools.partial( | |||
| json.dumps, cls=CustomJSONEncoder) | |||
| @@ -87,7 +88,7 @@ def request(**kwargs): | |||
| def get_exponential_backoff_interval(retries, full_jitter=False): | |||
| """Calculate the exponential backoff wait time.""" | |||
| # Will be zero if factor equals 0 | |||
| countdown = min(settings.REQUEST_MAX_WAIT_SEC, settings.REQUEST_WAIT_SEC * (2 ** retries)) | |||
| countdown = min(REQUEST_MAX_WAIT_SEC, REQUEST_WAIT_SEC * (2 ** retries)) | |||
| # Full jitter according to | |||
| # https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/ | |||
| if full_jitter: | |||