32 lines
955 B
Python
32 lines
955 B
Python
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
|