feat(attachments): 增加附件阅读解析能力
This commit is contained in:
31
review_agent/file_summary/skills/attachment_reader.py
Normal file
31
review_agent/file_summary/skills/attachment_reader.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable
|
||||
|
||||
from review_agent.models import FileAttachment
|
||||
|
||||
from ..services.attachment_reader import read_attachment_details
|
||||
from .base import BaseSkill, SkillResult, WorkflowContext
|
||||
|
||||
|
||||
class AttachmentReaderSkill(BaseSkill):
|
||||
name = "attachment_reader"
|
||||
|
||||
def run(self, context: WorkflowContext) -> SkillResult:
|
||||
attachments = FileAttachment.objects.filter(
|
||||
conversation=context.batch.conversation,
|
||||
is_active=True,
|
||||
).exclude(upload_status=FileAttachment.UploadStatus.DELETED)
|
||||
return self.run_for_attachments(attachments)
|
||||
|
||||
def run_for_attachments(self, attachments: Iterable[FileAttachment]) -> SkillResult:
|
||||
results = [read_attachment_details(attachment).to_dict() for attachment in attachments]
|
||||
if not results:
|
||||
return SkillResult(success=False, message="当前对话没有可读取的附件。")
|
||||
|
||||
has_success = any(item["status"] == "success" for item in results)
|
||||
return SkillResult(
|
||||
success=has_success,
|
||||
data={"attachments": results},
|
||||
message="附件解析完成。" if has_success else "附件解析失败。",
|
||||
)
|
||||
Reference in New Issue
Block a user