refactor: add type hints and FileParser.is_supported() helper
- Add return type annotation (list[str]) to Config.validate() - Add type annotations (msg: str, -> None) to logger convenience functions - Add FileParser.is_supported() classmethod for checking file format support
This commit is contained in:
parent
fa0f6519b1
commit
daec4b6be4
|
|
@ -64,9 +64,9 @@ class Config:
|
|||
REPORT_AGENT_TEMPERATURE = float(os.environ.get('REPORT_AGENT_TEMPERATURE', '0.5'))
|
||||
|
||||
@classmethod
|
||||
def validate(cls):
|
||||
def validate(cls) -> list[str]:
|
||||
"""验证必要配置"""
|
||||
errors = []
|
||||
errors: list[str] = []
|
||||
if not cls.LLM_API_KEY:
|
||||
errors.append("LLM_API_KEY 未配置")
|
||||
if not cls.ZEP_API_KEY:
|
||||
|
|
|
|||
|
|
@ -63,6 +63,20 @@ class FileParser:
|
|||
|
||||
SUPPORTED_EXTENSIONS = {'.pdf', '.md', '.markdown', '.txt'}
|
||||
|
||||
@classmethod
|
||||
def is_supported(cls, file_path: str) -> bool:
|
||||
"""
|
||||
检查文件是否为支持的格式
|
||||
|
||||
Args:
|
||||
file_path: 文件路径
|
||||
|
||||
Returns:
|
||||
如果文件格式受支持则返回 True
|
||||
"""
|
||||
suffix = Path(file_path).suffix.lower()
|
||||
return suffix in cls.SUPPORTED_EXTENSIONS
|
||||
|
||||
@classmethod
|
||||
def extract_text(cls, file_path: str) -> str:
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -109,18 +109,18 @@ logger = setup_logger()
|
|||
|
||||
|
||||
# 便捷方法
|
||||
def debug(msg, *args, **kwargs):
|
||||
def debug(msg: str, *args, **kwargs) -> None:
|
||||
logger.debug(msg, *args, **kwargs)
|
||||
|
||||
def info(msg, *args, **kwargs):
|
||||
def info(msg: str, *args, **kwargs) -> None:
|
||||
logger.info(msg, *args, **kwargs)
|
||||
|
||||
def warning(msg, *args, **kwargs):
|
||||
def warning(msg: str, *args, **kwargs) -> None:
|
||||
logger.warning(msg, *args, **kwargs)
|
||||
|
||||
def error(msg, *args, **kwargs):
|
||||
def error(msg: str, *args, **kwargs) -> None:
|
||||
logger.error(msg, *args, **kwargs)
|
||||
|
||||
def critical(msg, *args, **kwargs):
|
||||
def critical(msg: str, *args, **kwargs) -> None:
|
||||
logger.critical(msg, *args, **kwargs)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue