test
This commit is contained in:
1 parent
10d0f5bad8
commit
fcb70b85f4
3 files changed
+43
-16
No files matched your search
@@ -154,15 +154,41 @@ class Text2SQLService:
|
||||
@classmethod
|
||||
def get_schema(cls):
|
||||
if cls._schema_text is None:
|
||||
try:
|
||||
# docs is at the project root: c:\Users\PC\Desktop\HX工作目录\hxops\hxops\docs
|
||||
# This file is in backend/app/services/text2sql.py
|
||||
base_dir = cls._project_root()
|
||||
doc_path = os.path.join(base_dir, 'docs', '(表+字段).md')
|
||||
with open(doc_path, 'r', encoding='utf-8') as f:
|
||||
cls._schema_text = f.read()
|
||||
except Exception as e:
|
||||
cls._schema_text = f"Failed to load schema: {e}"
|
||||
schema_filename = '(表+字段).md'
|
||||
env_path = (os.getenv("TEXT2SQL_SCHEMA_PATH") or "").strip()
|
||||
candidate_paths = []
|
||||
if env_path:
|
||||
candidate_paths.append(env_path)
|
||||
|
||||
candidate_paths.extend([
|
||||
os.path.join(cls._backend_dir(), 'docs', schema_filename),
|
||||
os.path.join(cls._project_root(), 'docs', schema_filename),
|
||||
os.path.join(os.getcwd(), 'docs', schema_filename),
|
||||
])
|
||||
|
||||
unique_paths = []
|
||||
seen = set()
|
||||
for path in candidate_paths:
|
||||
normalized = os.path.normpath(path)
|
||||
if normalized not in seen:
|
||||
seen.add(normalized)
|
||||
unique_paths.append(path)
|
||||
|
||||
for doc_path in unique_paths:
|
||||
try:
|
||||
if not os.path.exists(doc_path):
|
||||
continue
|
||||
with open(doc_path, 'r', encoding='utf-8') as f:
|
||||
cls._schema_text = f.read()
|
||||
cls._log("info", f"Loaded Text2SQL schema from {doc_path}")
|
||||
break
|
||||
except Exception as exc:
|
||||
cls._log("warning", f"Failed to load Text2SQL schema from {doc_path}: {exc}")
|
||||
|
||||
if cls._schema_text is None:
|
||||
tried = ", ".join(unique_paths)
|
||||
cls._schema_text = f"Failed to load schema: schema file not found. Tried: {tried}"
|
||||
cls._log("warning", cls._schema_text)
|
||||
return cls._schema_text
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in new issue
Block a user