feat(file-summary): 实现文件处理技能链路
This commit is contained in:
31
review_agent/file_summary/services/product_detect.py
Normal file
31
review_agent/file_summary/services/product_detect.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from review_agent.models import FileSummaryBatch
|
||||
|
||||
|
||||
def detect_product_name(batch: FileSummaryBatch) -> str:
|
||||
product_name = ""
|
||||
for item in batch.items.order_by("file_index"):
|
||||
parts = Path(item.relative_path).parts
|
||||
if len(parts) > 1:
|
||||
product_name = parts[0]
|
||||
break
|
||||
name = Path(item.file_name).stem
|
||||
for keyword in ("产品", "试剂盒", "说明书"):
|
||||
if keyword in name:
|
||||
product_name = name
|
||||
break
|
||||
if product_name:
|
||||
break
|
||||
|
||||
if not product_name:
|
||||
return ""
|
||||
|
||||
batch.product_name = product_name
|
||||
batch.save(update_fields=["product_name"])
|
||||
if batch.conversation.title.startswith("新对话"):
|
||||
batch.conversation.title = f"{product_name}-文件汇总"
|
||||
batch.conversation.save(update_fields=["title", "updated_at"])
|
||||
return product_name
|
||||
Reference in New Issue
Block a user