Zhiyuan Liang jinhai-2012 zhichyu commited on
Commit
b6c5e1b
·
1 Parent(s): 8a4c42a

Add enviroment validation at server startup phase (#3388)

Browse files

### What problem does this PR solve?

1. Validate the Python version should >= 3.11
2. Download nltk data

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
- [x] Refactoring

---------

Signed-off-by: jinhai <[email protected]>
Co-authored-by: jinhai <[email protected]>
Co-authored-by: Zhichang Yu <[email protected]>

Files changed (2) hide show
  1. api/ragflow_server.py +1 -0
  2. api/validation.py +37 -0
api/ragflow_server.py CHANGED
@@ -22,6 +22,7 @@ import time
22
  import traceback
23
  from concurrent.futures import ThreadPoolExecutor
24
 
 
25
  from werkzeug.serving import run_simple
26
  from api.apps import app
27
  from api.db.runtime_config import RuntimeConfig
 
22
  import traceback
23
  from concurrent.futures import ThreadPoolExecutor
24
 
25
+ import validation
26
  from werkzeug.serving import run_simple
27
  from api.apps import app
28
  from api.db.runtime_config import RuntimeConfig
api/validation.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # Copyright 2024 The InfiniFlow Authors. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ import sys
18
+ from api.utils.log_utils import logger
19
+
20
+ def python_version_validation():
21
+ # Check python version
22
+ required_python_version = (3, 10)
23
+ if sys.version_info < required_python_version:
24
+ logger.info(
25
+ f"Required Python: >= {required_python_version[0]}.{required_python_version[1]}. Current Python version: {sys.version_info[0]}.{sys.version_info[1]}."
26
+ )
27
+ sys.exit(1)
28
+ else:
29
+ logger.info(f"Python version: {sys.version_info[0]}.{sys.version_info[1]}")
30
+
31
+
32
+ python_version_validation()
33
+
34
+ # Download nltk data
35
+ import nltk
36
+ nltk.download('wordnet')
37
+ nltk.download('punkt_tab')