Update version display on web UI (#3405)

### 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 <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai 2024-11-14 17:51:21 +08:00 committed by GitHub
parent 30f6421760
commit e4c4fdabbd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 28 additions and 30 deletions

View File

@ -30,7 +30,7 @@ from api.utils.api_utils import (
server_error_response, server_error_response,
generate_confirmation_token, generate_confirmation_token,
) )
from api.versions import get_rag_version from api.versions import get_ragflow_version
from api.settings import docStoreConn from api.settings import docStoreConn
from rag.utils.storage_factory import STORAGE_IMPL, STORAGE_IMPL_TYPE from rag.utils.storage_factory import STORAGE_IMPL, STORAGE_IMPL_TYPE
from timeit import default_timer as timer from timeit import default_timer as timer
@ -58,7 +58,7 @@ def version():
type: string type: string
description: Version number. description: Version number.
""" """
return get_json_result(data=get_rag_version()) return get_json_result(data=get_ragflow_version())
@manager.route("/status", methods=["GET"]) @manager.route("/status", methods=["GET"])

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
from api.versions import get_versions from api.versions import get_ragflow_version
from .reload_config_base import ReloadConfigBase from .reload_config_base import ReloadConfigBase
@ -35,7 +35,7 @@ class RuntimeConfig(ReloadConfigBase):
@classmethod @classmethod
def init_env(cls): def init_env(cls):
cls.ENV.update(get_versions()) cls.ENV.update({"version": get_ragflow_version()})
@classmethod @classmethod
def load_config_manager(cls): def load_config_manager(cls):

View File

@ -44,7 +44,7 @@ from api import utils
from api.db.db_models import init_database_tables as init_web_db from api.db.db_models import init_database_tables as init_web_db
from api.db.init_data import init_web_data from api.db.init_data import init_web_data
from api.versions import get_versions, RAGFLOW_VERSION_INFO from api.versions import get_ragflow_version
def update_progress(): def update_progress():
@ -66,7 +66,7 @@ if __name__ == '__main__':
""") """)
logging.info( logging.info(
f'RAGFlow version: {RAGFLOW_VERSION_INFO}' f'RAGFlow version: {get_ragflow_version()}'
) )
logging.info( logging.info(
f'project base: {utils.file_utils.get_project_base_directory()}' f'project base: {utils.file_utils.get_project_base_directory()}'
@ -87,7 +87,7 @@ if __name__ == '__main__':
) )
args = parser.parse_args() args = parser.parse_args()
if args.version: if args.version:
print(get_versions()) print(get_ragflow_version())
sys.exit(0) sys.exit(0)
RuntimeConfig.DEBUG = args.debug RuntimeConfig.DEBUG = args.debug
@ -103,7 +103,7 @@ if __name__ == '__main__':
# start http server # start http server
try: try:
logging.info("RAG Flow http server start...") logging.info("RAGFlow HTTP server start...")
run_simple( run_simple(
hostname=HOST, hostname=HOST,
port=HTTP_PORT, port=HTTP_PORT,

View File

@ -17,35 +17,33 @@ import dotenv
import typing import typing
import subprocess import subprocess
def get_ragflow_version() -> typing.Optional[str]:
def get_versions() -> typing.Mapping[str, typing.Any]: return RAGFLOW_VERSION_INFO
dotenv.load_dotenv(dotenv.find_dotenv())
return dotenv.dotenv_values()
def get_rag_version() -> typing.Optional[str]:
return get_versions().get("RAGFLOW_IMAGE", "infiniflow/ragflow:dev").split(":")[-1]
RAGFLOW_VERSION_INFO = "dev" RAGFLOW_VERSION_INFO = "dev"
def get_closest_tag_and_count(): def get_closest_tag_and_count():
# Get the current commit hash try:
commit_id = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip().decode('utf-8') # Get the current commit hash
# Get the closest tag commit_id = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip().decode('utf-8')
closest_tag = subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0']).strip().decode('utf-8') # Get the closest tag
# Get the commit hash of the closest tag closest_tag = subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0']).strip().decode('utf-8')
closest_tag_commit = subprocess.check_output(['git', 'rev-list', '-n', '1', closest_tag]).strip().decode('utf-8') # Get the commit hash of the closest tag
# Get the commit count since the closest tag closest_tag_commit = subprocess.check_output(['git', 'rev-list', '-n', '1', closest_tag]).strip().decode(
process = subprocess.Popen(['git', 'rev-list', '--count', f'{closest_tag}..HEAD'], stdout=subprocess.PIPE) 'utf-8')
commits_count, _ = process.communicate() # Get the commit count since the closest tag
commits_count = int(commits_count.strip()) process = subprocess.Popen(['git', 'rev-list', '--count', f'{closest_tag}..HEAD'], stdout=subprocess.PIPE)
commits_count, _ = process.communicate()
commits_count = int(commits_count.strip())
if commits_count == 0: if commits_count == 0:
return closest_tag return closest_tag
else: else:
return f"{commit_id}({closest_tag}~{commits_count})" return f"{commit_id}({closest_tag}~{commits_count})"
except Exception as e:
return 'unknown'
if RAGFLOW_VERSION_INFO == 'dev': if RAGFLOW_VERSION_INFO == 'dev':