feat(agent): 增加 LLM 路由与诊断日志
This commit is contained in:
@@ -1,25 +1,49 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from review_agent.models import FileSummaryItem
|
||||
|
||||
from ..services.page_count import SUPPORTED_EXTENSIONS, count_document_pages
|
||||
from .base import BaseSkill, SkillResult, WorkflowContext
|
||||
|
||||
|
||||
logger = logging.getLogger("review_agent.file_summary.skills.document_page_count")
|
||||
|
||||
|
||||
class DocumentPageCountSkill(BaseSkill):
|
||||
name = "document_page_count"
|
||||
|
||||
def run(self, context: WorkflowContext) -> SkillResult:
|
||||
success_files = failed_files = unsupported_files = uncertain_files = total_pages = 0
|
||||
logger.info("Document page count started", extra={"batch_id": context.batch.pk})
|
||||
for item in context.batch.items.order_by("file_index"):
|
||||
if item.file_type not in SUPPORTED_EXTENSIONS:
|
||||
item.statistics_status = FileSummaryItem.StatisticsStatus.UNSUPPORTED
|
||||
unsupported_files += 1
|
||||
item.save(update_fields=["statistics_status", "updated_at"])
|
||||
logger.info(
|
||||
"Document page count unsupported",
|
||||
extra={
|
||||
"batch_id": context.batch.pk,
|
||||
"item_id": item.pk,
|
||||
"file_type": item.file_type,
|
||||
"file_name": item.file_name,
|
||||
},
|
||||
)
|
||||
continue
|
||||
|
||||
result = None
|
||||
for attempt in range(1, 4):
|
||||
logger.info(
|
||||
"Document page count attempt",
|
||||
extra={
|
||||
"batch_id": context.batch.pk,
|
||||
"item_id": item.pk,
|
||||
"attempt": attempt,
|
||||
"storage_path": item.storage_path,
|
||||
},
|
||||
)
|
||||
result = count_document_pages(item.storage_path)
|
||||
item.retry_count = attempt - 1
|
||||
if result.status != "failed":
|
||||
@@ -46,6 +70,15 @@ class DocumentPageCountSkill(BaseSkill):
|
||||
unsupported_files += 1
|
||||
else:
|
||||
failed_files += 1
|
||||
logger.warning(
|
||||
"Document page count failed",
|
||||
extra={
|
||||
"batch_id": context.batch.pk,
|
||||
"item_id": item.pk,
|
||||
"file_name": item.file_name,
|
||||
"error": result.error_message,
|
||||
},
|
||||
)
|
||||
|
||||
context.batch.success_files = success_files
|
||||
context.batch.failed_files = failed_files
|
||||
@@ -61,4 +94,15 @@ class DocumentPageCountSkill(BaseSkill):
|
||||
"total_pages",
|
||||
]
|
||||
)
|
||||
logger.info(
|
||||
"Document page count finished",
|
||||
extra={
|
||||
"batch_id": context.batch.pk,
|
||||
"success_files": success_files,
|
||||
"failed_files": failed_files,
|
||||
"unsupported_files": unsupported_files,
|
||||
"uncertain_files": uncertain_files,
|
||||
"total_pages": total_pages,
|
||||
},
|
||||
)
|
||||
return SkillResult(success=True)
|
||||
|
||||
Reference in New Issue
Block a user