Merge branch 'dev' into test
This commit is contained in:
commit
f61dbf7611
2 files changed
+33
-20
No files matched your search
@@ -7,13 +7,39 @@ from flask import current_app
|
|||||||
class Text2SQLService:
|
class Text2SQLService:
|
||||||
_schema_text = None
|
_schema_text = None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _backend_dir() -> str:
|
||||||
|
return os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _project_root(cls) -> str:
|
||||||
|
return os.path.dirname(cls._backend_dir())
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _find_oracle_client_dir(cls) -> str | None:
|
||||||
|
candidate_roots = [
|
||||||
|
os.path.join(cls._backend_dir(), 'oracle_client'),
|
||||||
|
os.path.join(cls._project_root(), 'oracle_client'),
|
||||||
|
]
|
||||||
|
for oracle_client_dir in candidate_roots:
|
||||||
|
if not os.path.exists(oracle_client_dir):
|
||||||
|
continue
|
||||||
|
client_dirs = [
|
||||||
|
os.path.join(oracle_client_dir, d)
|
||||||
|
for d in os.listdir(oracle_client_dir)
|
||||||
|
if d.startswith('instantclient_') and os.path.isdir(os.path.join(oracle_client_dir, d))
|
||||||
|
]
|
||||||
|
if client_dirs:
|
||||||
|
return client_dirs[0]
|
||||||
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_schema(cls):
|
def get_schema(cls):
|
||||||
if cls._schema_text is None:
|
if cls._schema_text is None:
|
||||||
try:
|
try:
|
||||||
# docs is at the project root: c:\Users\PC\Desktop\HX工作目录\hxops\hxops\docs
|
# docs is at the project root: c:\Users\PC\Desktop\HX工作目录\hxops\hxops\docs
|
||||||
# This file is in backend/app/services/text2sql.py
|
# This file is in backend/app/services/text2sql.py
|
||||||
base_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
base_dir = cls._project_root()
|
||||||
doc_path = os.path.join(base_dir, 'docs', '(表+字段).md')
|
doc_path = os.path.join(base_dir, 'docs', '(表+字段).md')
|
||||||
with open(doc_path, 'r', encoding='utf-8') as f:
|
with open(doc_path, 'r', encoding='utf-8') as f:
|
||||||
cls._schema_text = f.read()
|
cls._schema_text = f.read()
|
||||||
@@ -190,27 +216,11 @@ class Text2SQLService:
|
|||||||
import tempfile
|
import tempfile
|
||||||
import shutil
|
import shutil
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
base_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
|
target_lib_dir = cls._find_oracle_client_dir()
|
||||||
oracle_client_dir = os.path.join(base_dir, 'oracle_client')
|
|
||||||
|
|
||||||
# Dynamically find the instantclient folder
|
|
||||||
client_dirs = []
|
|
||||||
if os.path.exists(oracle_client_dir):
|
|
||||||
client_dirs = [
|
|
||||||
os.path.join(oracle_client_dir, d)
|
|
||||||
for d in os.listdir(oracle_client_dir)
|
|
||||||
if d.startswith('instantclient_') and os.path.isdir(os.path.join(oracle_client_dir, d))
|
|
||||||
]
|
|
||||||
|
|
||||||
target_lib_dir = None
|
|
||||||
if client_dirs:
|
|
||||||
target_lib_dir = client_dirs[0]
|
|
||||||
else:
|
|
||||||
target_lib_dir = os.path.join(oracle_client_dir, 'instantclient_19_24')
|
|
||||||
|
|
||||||
# Fix for OCI path issue with Chinese characters (like "HX工作目录")
|
# Fix for OCI path issue with Chinese characters (like "HX工作目录")
|
||||||
# OCI C-library fails to load if path contains non-ASCII
|
# OCI C-library fails to load if path contains non-ASCII
|
||||||
if not target_lib_dir.isascii():
|
if target_lib_dir and not target_lib_dir.isascii():
|
||||||
temp_dir = os.path.join(tempfile.gettempdir(), 'hxops_oracle_client')
|
temp_dir = os.path.join(tempfile.gettempdir(), 'hxops_oracle_client')
|
||||||
safe_lib_dir = os.path.join(temp_dir, os.path.basename(target_lib_dir))
|
safe_lib_dir = os.path.join(temp_dir, os.path.basename(target_lib_dir))
|
||||||
if not os.path.exists(safe_lib_dir) and os.path.exists(target_lib_dir):
|
if not os.path.exists(safe_lib_dir) and os.path.exists(target_lib_dir):
|
||||||
@@ -218,7 +228,8 @@ class Text2SQLService:
|
|||||||
shutil.copytree(target_lib_dir, safe_lib_dir)
|
shutil.copytree(target_lib_dir, safe_lib_dir)
|
||||||
target_lib_dir = safe_lib_dir
|
target_lib_dir = safe_lib_dir
|
||||||
|
|
||||||
oracledb.init_oracle_client(lib_dir=target_lib_dir)
|
if target_lib_dir:
|
||||||
|
oracledb.init_oracle_client(lib_dir=target_lib_dir)
|
||||||
else:
|
else:
|
||||||
oracledb.init_oracle_client()
|
oracledb.init_oracle_client()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ flask-cors
|
|||||||
psycopg2-binary
|
psycopg2-binary
|
||||||
redis
|
redis
|
||||||
requests
|
requests
|
||||||
|
openai
|
||||||
gunicorn
|
gunicorn
|
||||||
gevent
|
gevent
|
||||||
pydantic
|
pydantic
|
||||||
@@ -14,4 +15,5 @@ openpyxl
|
|||||||
pycryptodome
|
pycryptodome
|
||||||
PyJWT
|
PyJWT
|
||||||
cryptography
|
cryptography
|
||||||
|
oracledb
|
||||||
pywin32; sys_platform == "win32"
|
pywin32; sys_platform == "win32"
|
||||||
Reference in new issue
Block a user