feat(agent): 增加 LLM 路由与诊断日志
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import csv
|
||||
import logging
|
||||
from dataclasses import asdict, dataclass, field
|
||||
from pathlib import Path
|
||||
|
||||
@@ -15,6 +16,9 @@ MAX_PREVIEW_CHARS = 3000
|
||||
MAX_ROWS_PER_SHEET = 20
|
||||
|
||||
|
||||
logger = logging.getLogger("review_agent.file_summary.attachment_reader")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class AttachmentReadResult:
|
||||
status: str
|
||||
@@ -32,10 +36,29 @@ class AttachmentReadResult:
|
||||
def read_attachment_details(attachment: FileAttachment) -> AttachmentReadResult:
|
||||
file_path = _attachment_absolute_path(attachment)
|
||||
file_type = Path(attachment.original_name).suffix.lower().lstrip(".")
|
||||
logger.info(
|
||||
"Attachment read started",
|
||||
extra={
|
||||
"attachment_id": attachment.pk,
|
||||
"conversation_id": attachment.conversation_id,
|
||||
"original_name": attachment.original_name,
|
||||
"file_type": file_type,
|
||||
"storage_path": attachment.storage_path,
|
||||
"resolved_path": str(file_path),
|
||||
},
|
||||
)
|
||||
|
||||
if not file_path.exists():
|
||||
logger.warning(
|
||||
"Attachment read missing file",
|
||||
extra={"attachment_id": attachment.pk, "resolved_path": str(file_path)},
|
||||
)
|
||||
return _failed(attachment, file_type, "附件文件不存在。")
|
||||
if file_type not in SUPPORTED_EXTENSIONS:
|
||||
logger.warning(
|
||||
"Attachment read unsupported type",
|
||||
extra={"attachment_id": attachment.pk, "file_type": file_type},
|
||||
)
|
||||
return _failed(attachment, file_type, f"暂不支持解析 .{file_type or 'unknown'} 文件。", "unsupported")
|
||||
|
||||
try:
|
||||
@@ -52,9 +75,21 @@ def read_attachment_details(attachment: FileAttachment) -> AttachmentReadResult:
|
||||
else:
|
||||
sections = _read_text(file_path)
|
||||
except Exception as exc:
|
||||
logger.exception(
|
||||
"Attachment read failed",
|
||||
extra={"attachment_id": attachment.pk, "file_type": file_type, "error": str(exc)},
|
||||
)
|
||||
return _failed(attachment, file_type, str(exc))
|
||||
|
||||
preview = _build_preview(sections)
|
||||
logger.info(
|
||||
"Attachment read finished",
|
||||
extra={
|
||||
"attachment_id": attachment.pk,
|
||||
"section_count": len(sections),
|
||||
"preview_length": len(preview),
|
||||
},
|
||||
)
|
||||
return AttachmentReadResult(
|
||||
status="success",
|
||||
filename=attachment.original_name,
|
||||
|
||||
Reference in New Issue
Block a user