refactor(backend): 重构后端代码 wave 3
This commit is contained in:
1 parent
affe139bf9
commit
8415653365
97 files changed
+4673
-6164
No files matched your search
@@ -1,3 +1,11 @@
|
||||
"""
|
||||
services/text2sql.py
|
||||
|
||||
Purpose: Translate natural-language ERP asset queries into safe Oracle SQL and format results.
|
||||
Dependencies: Oracle client, LLM client, and docs/integrations/erp/text2sql_schema.md.
|
||||
Flow: The chat fast route calls this service; this service loads the ERP schema to build SQL prompts.
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
@@ -424,17 +432,26 @@ class Text2SQLService:
|
||||
|
||||
@classmethod
|
||||
def get_schema(cls):
|
||||
"""
|
||||
Load the ERP schema document used as context for Text2SQL generation.
|
||||
|
||||
The environment override is checked first, followed by the packaged and source-tree
|
||||
locations, so the same schema is available in containers and local development.
|
||||
|
||||
Returns:
|
||||
str: UTF-8 schema text, or a diagnostic string when no schema document is available.
|
||||
"""
|
||||
if cls._schema_text is None:
|
||||
schema_filename = '(表+字段).md'
|
||||
schema_relative_path = os.path.join('integrations', 'erp', 'text2sql_schema.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),
|
||||
os.path.join(cls._backend_dir(), 'docs', schema_relative_path),
|
||||
os.path.join(cls._project_root(), 'docs', schema_relative_path),
|
||||
os.path.join(os.getcwd(), 'docs', schema_relative_path),
|
||||
])
|
||||
|
||||
unique_paths = []
|
||||
|
||||
Reference in new issue
Block a user