diff --git a/.gitignore b/.gitignore index ef1a39a..381dd6b 100644 --- a/.gitignore +++ b/.gitignore @@ -120,8 +120,9 @@ test_*.json rag_response.json nul -# 临时调试脚本(下划线开头) -scripts/_*.py +# 调试脚本和临时计划(仅本地使用) +scripts/ +plans/ # Qoder 工具目录 .qoder/ diff --git a/api/document_routes.py b/api/document_routes.py index 4fea09c..04a7ad0 100644 --- a/api/document_routes.py +++ b/api/document_routes.py @@ -45,6 +45,7 @@ import logging logger = logging.getLogger(__name__) from werkzeug.utils import secure_filename from auth.gateway import require_gateway_auth +from config import DEV_MODE from core.status_codes import ( UPLOAD_SUCCESS, BATCH_UPLOAD_SUCCESS, BAD_REQUEST, SUCCESS, NO_FILE, NO_FILE_SELECTED, NO_COLLECTION, NOT_FOUND, @@ -171,9 +172,9 @@ def serve_document_file(doc_path: str) -> Tuple[Any, int]: 文件内容或错误响应 Note: - 仅在 DEV_MODE=true 时可用 + 仅在 DEV_MODE=true 时可用(需在 .env 中显式设置) """ - if os.environ.get('DEV_MODE', 'true').lower() == 'false': + if not DEV_MODE: return error_response("FORBIDDEN", FORBIDDEN, "仅开发环境可用", http_status=403) from config import DOCUMENTS_PATH diff --git a/config.example.py b/config.example.py index 1d18fcc..0954970 100644 --- a/config.example.py +++ b/config.example.py @@ -201,6 +201,18 @@ MINERU_DEVICE_MODE = os.getenv("MINERU_DEVICE_MODE", "cpu") # cpu / cuda MINERU_API_TOKEN = os.getenv("MINERU_API_TOKEN", "") # 在 https://mineru.net/apiManage/token 申请 MINERU_API_URL = os.getenv("MINERU_API_URL", "https://mineru.net/api/v4/extract/task") MINERU_PREFER_ONLINE = os.getenv("MINERU_PREFER_ONLINE", "true").lower() == "true" +MINERU_PREFER_V2 = os.getenv("MINERU_PREFER_V2", "true").lower() == "true" # 优先使用 v2 格式(含 style 信息) + +# 标题识别规则引擎 +# 规则定义见 parsers/heading_rules.py,支持通过 config.py 覆盖 +HEADING_RULES_CONFIG = None # None=使用内置默认规则; dict 列表=自定义规则覆盖 +HEADING_SHORT_TEXT_ENABLED = True # 是否启用短中文文本标题识别(最易误判的规则,可单独关闭) +HEADING_SHORT_TEXT_MAX_LENGTH = 20 # 短文本最大字符数阈值 + +# 表单类型二次校正 +# MinerU 解析 Word 文档时,某些表单被标记为 text,根据内容特征修正为 table +FORM_RECLASSIFY_ENABLED = True # 是否启用 text->table 表单检测 +FORM_RECLASSIFY_MIN_INDICATORS = 2 # 最少命中几个表单特征指标才校正 # 分块参数 CHUNK_SIZE = 1000 diff --git a/core/llm_utils.py b/core/llm_utils.py index d4af40f..97a49d4 100644 --- a/core/llm_utils.py +++ b/core/llm_utils.py @@ -352,7 +352,7 @@ def quick_yes_no( if keywords is None: keywords = ["是", "需要", "yes", "true"] - result = call_llm(client, prompt, model, temperature=0, max_tokens=10) + result = call_llm(client, prompt, model, temperature=0, max_tokens=128) if result is None: return False diff --git a/knowledge/router.py b/knowledge/router.py index ad34123..5793dc6 100644 --- a/knowledge/router.py +++ b/knowledge/router.py @@ -283,7 +283,7 @@ class KnowledgeBaseRouter: content = call_llm( self.llm_client, prompt, MODEL, temperature=0.1, - max_tokens=100 + max_tokens=512 ) if content is None: diff --git a/services/feedback.py b/services/feedback.py index d31a5ae..223c6e0 100644 --- a/services/feedback.py +++ b/services/feedback.py @@ -616,7 +616,7 @@ class FeedbackService: prompt=prompt, model=self.model, temperature=0.7, - max_tokens=200 + max_tokens=512 ) if not response: