Commit
·
d66c623
1
Parent(s):
8bc2fc9
Update version display on web UI (#3405)
Browse files### What problem does this PR solve?
_Briefly describe what this PR aims to solve. Include background context
that will help reviewers understand the purpose of the PR._
### Type of change
- [x] Refactoring
---------
Signed-off-by: jinhai <[email protected]>
- api/apps/system_app.py +2 -2
- api/db/runtime_config.py +2 -2
- api/ragflow_server.py +4 -4
- api/versions.py +21 -23
api/apps/system_app.py
CHANGED
@@ -30,7 +30,7 @@ from api.utils.api_utils import (
|
|
30 |
server_error_response,
|
31 |
generate_confirmation_token,
|
32 |
)
|
33 |
-
from api.versions import
|
34 |
from api.settings import docStoreConn
|
35 |
from rag.utils.storage_factory import STORAGE_IMPL, STORAGE_IMPL_TYPE
|
36 |
from timeit import default_timer as timer
|
@@ -58,7 +58,7 @@ def version():
|
|
58 |
type: string
|
59 |
description: Version number.
|
60 |
"""
|
61 |
-
return get_json_result(data=
|
62 |
|
63 |
|
64 |
@manager.route("/status", methods=["GET"])
|
|
|
30 |
server_error_response,
|
31 |
generate_confirmation_token,
|
32 |
)
|
33 |
+
from api.versions import get_ragflow_version
|
34 |
from api.settings import docStoreConn
|
35 |
from rag.utils.storage_factory import STORAGE_IMPL, STORAGE_IMPL_TYPE
|
36 |
from timeit import default_timer as timer
|
|
|
58 |
type: string
|
59 |
description: Version number.
|
60 |
"""
|
61 |
+
return get_json_result(data=get_ragflow_version())
|
62 |
|
63 |
|
64 |
@manager.route("/status", methods=["GET"])
|
api/db/runtime_config.py
CHANGED
@@ -13,7 +13,7 @@
|
|
13 |
# See the License for the specific language governing permissions and
|
14 |
# limitations under the License.
|
15 |
#
|
16 |
-
from api.versions import
|
17 |
from .reload_config_base import ReloadConfigBase
|
18 |
|
19 |
|
@@ -35,7 +35,7 @@ class RuntimeConfig(ReloadConfigBase):
|
|
35 |
|
36 |
@classmethod
|
37 |
def init_env(cls):
|
38 |
-
cls.ENV.update(
|
39 |
|
40 |
@classmethod
|
41 |
def load_config_manager(cls):
|
|
|
13 |
# See the License for the specific language governing permissions and
|
14 |
# limitations under the License.
|
15 |
#
|
16 |
+
from api.versions import get_ragflow_version
|
17 |
from .reload_config_base import ReloadConfigBase
|
18 |
|
19 |
|
|
|
35 |
|
36 |
@classmethod
|
37 |
def init_env(cls):
|
38 |
+
cls.ENV.update({"version": get_ragflow_version()})
|
39 |
|
40 |
@classmethod
|
41 |
def load_config_manager(cls):
|
api/ragflow_server.py
CHANGED
@@ -44,7 +44,7 @@ from api import utils
|
|
44 |
|
45 |
from api.db.db_models import init_database_tables as init_web_db
|
46 |
from api.db.init_data import init_web_data
|
47 |
-
from api.versions import
|
48 |
|
49 |
|
50 |
def update_progress():
|
@@ -66,7 +66,7 @@ if __name__ == '__main__':
|
|
66 |
|
67 |
""")
|
68 |
logging.info(
|
69 |
-
f'RAGFlow version: {
|
70 |
)
|
71 |
logging.info(
|
72 |
f'project base: {utils.file_utils.get_project_base_directory()}'
|
@@ -87,7 +87,7 @@ if __name__ == '__main__':
|
|
87 |
)
|
88 |
args = parser.parse_args()
|
89 |
if args.version:
|
90 |
-
print(
|
91 |
sys.exit(0)
|
92 |
|
93 |
RuntimeConfig.DEBUG = args.debug
|
@@ -103,7 +103,7 @@ if __name__ == '__main__':
|
|
103 |
|
104 |
# start http server
|
105 |
try:
|
106 |
-
logging.info("
|
107 |
run_simple(
|
108 |
hostname=HOST,
|
109 |
port=HTTP_PORT,
|
|
|
44 |
|
45 |
from api.db.db_models import init_database_tables as init_web_db
|
46 |
from api.db.init_data import init_web_data
|
47 |
+
from api.versions import get_ragflow_version
|
48 |
|
49 |
|
50 |
def update_progress():
|
|
|
66 |
|
67 |
""")
|
68 |
logging.info(
|
69 |
+
f'RAGFlow version: {get_ragflow_version()}'
|
70 |
)
|
71 |
logging.info(
|
72 |
f'project base: {utils.file_utils.get_project_base_directory()}'
|
|
|
87 |
)
|
88 |
args = parser.parse_args()
|
89 |
if args.version:
|
90 |
+
print(get_ragflow_version())
|
91 |
sys.exit(0)
|
92 |
|
93 |
RuntimeConfig.DEBUG = args.debug
|
|
|
103 |
|
104 |
# start http server
|
105 |
try:
|
106 |
+
logging.info("RAGFlow HTTP server start...")
|
107 |
run_simple(
|
108 |
hostname=HOST,
|
109 |
port=HTTP_PORT,
|
api/versions.py
CHANGED
@@ -17,35 +17,33 @@ import dotenv
|
|
17 |
import typing
|
18 |
import subprocess
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
dotenv.load_dotenv(dotenv.find_dotenv())
|
23 |
-
return dotenv.dotenv_values()
|
24 |
-
|
25 |
-
|
26 |
-
def get_rag_version() -> typing.Optional[str]:
|
27 |
-
return get_versions().get("RAGFLOW_IMAGE", "infiniflow/ragflow:dev").split(":")[-1]
|
28 |
|
29 |
|
30 |
RAGFLOW_VERSION_INFO = "dev"
|
31 |
|
32 |
|
33 |
def get_closest_tag_and_count():
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
49 |
|
50 |
|
51 |
if RAGFLOW_VERSION_INFO == 'dev':
|
|
|
17 |
import typing
|
18 |
import subprocess
|
19 |
|
20 |
+
def get_ragflow_version() -> typing.Optional[str]:
|
21 |
+
return RAGFLOW_VERSION_INFO
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
|
24 |
RAGFLOW_VERSION_INFO = "dev"
|
25 |
|
26 |
|
27 |
def get_closest_tag_and_count():
|
28 |
+
try:
|
29 |
+
# Get the current commit hash
|
30 |
+
commit_id = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip().decode('utf-8')
|
31 |
+
# Get the closest tag
|
32 |
+
closest_tag = subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0']).strip().decode('utf-8')
|
33 |
+
# Get the commit hash of the closest tag
|
34 |
+
closest_tag_commit = subprocess.check_output(['git', 'rev-list', '-n', '1', closest_tag]).strip().decode(
|
35 |
+
'utf-8')
|
36 |
+
# Get the commit count since the closest tag
|
37 |
+
process = subprocess.Popen(['git', 'rev-list', '--count', f'{closest_tag}..HEAD'], stdout=subprocess.PIPE)
|
38 |
+
commits_count, _ = process.communicate()
|
39 |
+
commits_count = int(commits_count.strip())
|
40 |
+
|
41 |
+
if commits_count == 0:
|
42 |
+
return closest_tag
|
43 |
+
else:
|
44 |
+
return f"{commit_id}({closest_tag}~{commits_count})"
|
45 |
+
except Exception as e:
|
46 |
+
return 'unknown'
|
47 |
|
48 |
|
49 |
if RAGFLOW_VERSION_INFO == 'dev':
|