feat(agent): 增加 LLM 路由与诊断日志
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
@@ -12,6 +13,9 @@ from review_agent.models import Conversation, FileAttachment
|
||||
from .constants import ATTACHMENT_ROOT
|
||||
|
||||
|
||||
logger = logging.getLogger("review_agent.file_summary.storage")
|
||||
|
||||
|
||||
def _safe_original_name(name: str) -> str:
|
||||
clean = get_valid_filename(Path(name).name)
|
||||
return clean or f"upload-{uuid4().hex}"
|
||||
@@ -42,6 +46,16 @@ def save_uploaded_attachment(*, conversation: Conversation, user, uploaded_file)
|
||||
"""Stores an uploaded file and creates a versioned attachment record."""
|
||||
|
||||
original_name = _safe_original_name(uploaded_file.name)
|
||||
logger.info(
|
||||
"Attachment upload save started",
|
||||
extra={
|
||||
"conversation_id": conversation.pk,
|
||||
"user_id": user.pk,
|
||||
"original_name": original_name,
|
||||
"file_size": uploaded_file.size,
|
||||
"content_type": getattr(uploaded_file, "content_type", "") or "",
|
||||
},
|
||||
)
|
||||
latest = (
|
||||
FileAttachment.objects.filter(conversation=conversation, original_name=original_name)
|
||||
.order_by("-version_no")
|
||||
@@ -63,7 +77,7 @@ def save_uploaded_attachment(*, conversation: Conversation, user, uploaded_file)
|
||||
is_active=True,
|
||||
).update(is_active=False)
|
||||
|
||||
return FileAttachment.objects.create(
|
||||
attachment = FileAttachment.objects.create(
|
||||
conversation=conversation,
|
||||
user=user,
|
||||
original_name=original_name,
|
||||
@@ -73,6 +87,16 @@ def save_uploaded_attachment(*, conversation: Conversation, user, uploaded_file)
|
||||
file_size=uploaded_file.size,
|
||||
content_type=getattr(uploaded_file, "content_type", "") or "",
|
||||
)
|
||||
logger.info(
|
||||
"Attachment upload save finished",
|
||||
extra={
|
||||
"conversation_id": conversation.pk,
|
||||
"attachment_id": attachment.pk,
|
||||
"version_no": attachment.version_no,
|
||||
"storage_path": attachment.storage_path,
|
||||
},
|
||||
)
|
||||
return attachment
|
||||
|
||||
|
||||
def serialize_attachment(attachment: FileAttachment) -> dict[str, object]:
|
||||
|
||||
Reference in New Issue
Block a user