Commit
·
98a13e9
1
Parent(s):
be05496
Remove unused code (#3448)
Browse files### 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 <[email protected]>
- api/apps/__init__.py +3 -2
- api/constants.py +6 -1
- api/settings.py +1 -23
- api/utils/api_utils.py +2 -1
api/apps/__init__.py
CHANGED
|
@@ -22,6 +22,7 @@ from flask import Blueprint, Flask
|
|
| 22 |
from werkzeug.wrappers.request import Request
|
| 23 |
from flask_cors import CORS
|
| 24 |
from flasgger import Swagger
|
|
|
|
| 25 |
|
| 26 |
from api.db import StatusEnum
|
| 27 |
from api.db.db_models import close_connection
|
|
@@ -32,7 +33,7 @@ from flask_session import Session
|
|
| 32 |
from flask_login import LoginManager
|
| 33 |
from api import settings
|
| 34 |
from api.utils.api_utils import server_error_response
|
| 35 |
-
from
|
| 36 |
|
| 37 |
__all__ = ["app"]
|
| 38 |
|
|
@@ -119,7 +120,7 @@ def register_page(page_path):
|
|
| 119 |
spec.loader.exec_module(page)
|
| 120 |
page_name = getattr(page, "page_name", page_name)
|
| 121 |
url_prefix = (
|
| 122 |
-
f"/api/{
|
| 123 |
)
|
| 124 |
|
| 125 |
app.register_blueprint(page.manager, url_prefix=url_prefix)
|
|
|
|
| 22 |
from werkzeug.wrappers.request import Request
|
| 23 |
from flask_cors import CORS
|
| 24 |
from flasgger import Swagger
|
| 25 |
+
from itsdangerous.url_safe import URLSafeTimedSerializer as Serializer
|
| 26 |
|
| 27 |
from api.db import StatusEnum
|
| 28 |
from api.db.db_models import close_connection
|
|
|
|
| 33 |
from flask_login import LoginManager
|
| 34 |
from api import settings
|
| 35 |
from api.utils.api_utils import server_error_response
|
| 36 |
+
from api.constants import API_VERSION
|
| 37 |
|
| 38 |
__all__ = ["app"]
|
| 39 |
|
|
|
|
| 120 |
spec.loader.exec_module(page)
|
| 121 |
page_name = getattr(page, "page_name", page_name)
|
| 122 |
url_prefix = (
|
| 123 |
+
f"/api/{API_VERSION}" if "/sdk/" in path else f"/{API_VERSION}/{page_name}"
|
| 124 |
)
|
| 125 |
|
| 126 |
app.register_blueprint(page.manager, url_prefix=url_prefix)
|
api/constants.py
CHANGED
|
@@ -17,4 +17,9 @@ NAME_LENGTH_LIMIT = 2 ** 10
|
|
| 17 |
|
| 18 |
IMG_BASE64_PREFIX = 'data:image/png;base64,'
|
| 19 |
|
| 20 |
-
SERVICE_CONF = "service_conf.yaml"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
IMG_BASE64_PREFIX = 'data:image/png;base64,'
|
| 19 |
|
| 20 |
+
SERVICE_CONF = "service_conf.yaml"
|
| 21 |
+
|
| 22 |
+
API_VERSION = "v1"
|
| 23 |
+
RAG_FLOW_SERVICE_NAME = "ragflow"
|
| 24 |
+
REQUEST_WAIT_SEC = 2
|
| 25 |
+
REQUEST_MAX_WAIT_SEC = 300
|
api/settings.py
CHANGED
|
@@ -23,13 +23,10 @@ import rag.utils
|
|
| 23 |
from rag.nlp import search
|
| 24 |
from graphrag import search as kg_search
|
| 25 |
from api.utils import get_base_config, decrypt_database_config
|
|
|
|
| 26 |
|
| 27 |
-
API_VERSION = "v1"
|
| 28 |
-
RAG_FLOW_SERVICE_NAME = "ragflow"
|
| 29 |
LIGHTEN = int(os.environ.get('LIGHTEN', "0"))
|
| 30 |
|
| 31 |
-
REQUEST_WAIT_SEC = 2
|
| 32 |
-
REQUEST_MAX_WAIT_SEC = 300
|
| 33 |
LLM = None
|
| 34 |
LLM_FACTORY = None
|
| 35 |
LLM_BASE_URL = None
|
|
@@ -173,15 +170,6 @@ def init_settings():
|
|
| 173 |
retrievaler = search.Dealer(docStoreConn)
|
| 174 |
kg_retrievaler = kg_search.KGSearch(docStoreConn)
|
| 175 |
|
| 176 |
-
def get_host_ip():
|
| 177 |
-
global HOST_IP
|
| 178 |
-
return HOST_IP
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
def get_host_port():
|
| 182 |
-
global HOST_PORT
|
| 183 |
-
return HOST_PORT
|
| 184 |
-
|
| 185 |
|
| 186 |
class CustomEnum(Enum):
|
| 187 |
@classmethod
|
|
@@ -201,16 +189,6 @@ class CustomEnum(Enum):
|
|
| 201 |
return [member.name for member in cls.__members__.values()]
|
| 202 |
|
| 203 |
|
| 204 |
-
class PythonDependenceName(CustomEnum):
|
| 205 |
-
Rag_Source_Code = "python"
|
| 206 |
-
Python_Env = "miniconda"
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
class ModelStorage(CustomEnum):
|
| 210 |
-
REDIS = "redis"
|
| 211 |
-
MYSQL = "mysql"
|
| 212 |
-
|
| 213 |
-
|
| 214 |
class RetCode(IntEnum, CustomEnum):
|
| 215 |
SUCCESS = 0
|
| 216 |
NOT_EFFECTIVE = 10
|
|
|
|
| 23 |
from rag.nlp import search
|
| 24 |
from graphrag import search as kg_search
|
| 25 |
from api.utils import get_base_config, decrypt_database_config
|
| 26 |
+
from api.constants import RAG_FLOW_SERVICE_NAME
|
| 27 |
|
|
|
|
|
|
|
| 28 |
LIGHTEN = int(os.environ.get('LIGHTEN', "0"))
|
| 29 |
|
|
|
|
|
|
|
| 30 |
LLM = None
|
| 31 |
LLM_FACTORY = None
|
| 32 |
LLM_BASE_URL = None
|
|
|
|
| 170 |
retrievaler = search.Dealer(docStoreConn)
|
| 171 |
kg_retrievaler = kg_search.KGSearch(docStoreConn)
|
| 172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
class CustomEnum(Enum):
|
| 175 |
@classmethod
|
|
|
|
| 189 |
return [member.name for member in cls.__members__.values()]
|
| 190 |
|
| 191 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
class RetCode(IntEnum, CustomEnum):
|
| 193 |
SUCCESS = 0
|
| 194 |
NOT_EFFECTIVE = 10
|
api/utils/api_utils.py
CHANGED
|
@@ -39,6 +39,7 @@ from api import settings
|
|
| 39 |
from api import settings
|
| 40 |
from api.utils import CustomJSONEncoder, get_uuid
|
| 41 |
from api.utils import json_dumps
|
|
|
|
| 42 |
|
| 43 |
requests.models.complexjson.dumps = functools.partial(
|
| 44 |
json.dumps, cls=CustomJSONEncoder)
|
|
@@ -87,7 +88,7 @@ def request(**kwargs):
|
|
| 87 |
def get_exponential_backoff_interval(retries, full_jitter=False):
|
| 88 |
"""Calculate the exponential backoff wait time."""
|
| 89 |
# Will be zero if factor equals 0
|
| 90 |
-
countdown = min(
|
| 91 |
# Full jitter according to
|
| 92 |
# https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
|
| 93 |
if full_jitter:
|
|
|
|
| 39 |
from api import settings
|
| 40 |
from api.utils import CustomJSONEncoder, get_uuid
|
| 41 |
from api.utils import json_dumps
|
| 42 |
+
from api.constants import REQUEST_WAIT_SEC, REQUEST_MAX_WAIT_SEC
|
| 43 |
|
| 44 |
requests.models.complexjson.dumps = functools.partial(
|
| 45 |
json.dumps, cls=CustomJSONEncoder)
|
|
|
|
| 88 |
def get_exponential_backoff_interval(retries, full_jitter=False):
|
| 89 |
"""Calculate the exponential backoff wait time."""
|
| 90 |
# Will be zero if factor equals 0
|
| 91 |
+
countdown = min(REQUEST_MAX_WAIT_SEC, REQUEST_WAIT_SEC * (2 ** retries))
|
| 92 |
# Full jitter according to
|
| 93 |
# https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
|
| 94 |
if full_jitter:
|