更新
This commit is contained in:
@@ -3432,9 +3432,101 @@ _TRANSFER_SOURCE_LABELS = (
|
||||
("transcript_segment_count", "转写片段"),
|
||||
)
|
||||
|
||||
_REQUIRED_TRANSFER_SECTIONS = (
|
||||
("basic_info", "基本信息"), ("vital_signs", "生命体征"),
|
||||
("chief_complaint", "主诉"), ("present_illness", "现病史"),
|
||||
("past_history", "既往史"), ("other_history", "其他病史"),
|
||||
("diagnosis_info", "诊断信息"), ("doctor_image_notes", "医生图片备注"),
|
||||
("doctor_file_notes", "医生文件备注"), ("daily_tracking", "日常整个页面"),
|
||||
("prescriptions", "历史处方"), ("video_consultation_text", "既往视频面诊文字"),
|
||||
("chat", "聊天"),
|
||||
)
|
||||
|
||||
|
||||
def _required_transfer_sections(meta: Mapping[str, Any]) -> list[Any] | None:
|
||||
sections = meta.get("required_sections")
|
||||
known_keys = dict(_REQUIRED_TRANSFER_SECTIONS)
|
||||
if isinstance(sections, list) and any(
|
||||
isinstance(item, Mapping) and str(item.get("key")) in known_keys for item in sections
|
||||
):
|
||||
return sections
|
||||
summary = meta.get("source_summary")
|
||||
if isinstance(summary, Mapping) and isinstance(summary.get("required_sections"), list):
|
||||
return summary["required_sections"]
|
||||
return sections if isinstance(sections, list) else None
|
||||
|
||||
|
||||
def _merge_stream_meta(meta: dict[str, Any], payload: Mapping[str, Any]) -> None:
|
||||
"""Keep observed transfer results when completion only repeats preparation.
|
||||
|
||||
Progress describes the latest actual request attempt, including a retry
|
||||
without files. Completion may instead carry the original prepared manifest;
|
||||
it is reply metadata and must not undo those observed transfer results.
|
||||
"""
|
||||
|
||||
live_fields = ("items", "attachment_count", "attachment_transfer", "required_sections")
|
||||
terminal = str(payload.get("event") or "").lower() == "done"
|
||||
observed = meta.get("_transfer_progress_observed") is True
|
||||
update = dict(payload)
|
||||
sections = _required_transfer_sections(payload)
|
||||
if sections is not None:
|
||||
update["required_sections"] = sections
|
||||
if terminal and observed and payload.get("transfer_manifest_final") is not True:
|
||||
for key in live_fields:
|
||||
if key in meta:
|
||||
if key == "required_sections" and not any(
|
||||
isinstance(item, Mapping)
|
||||
and str(item.get("key")) in dict(_REQUIRED_TRANSFER_SECTIONS)
|
||||
and item.get("status") in {"submitting", "submitted", "failed", "omitted"}
|
||||
for item in _required_transfer_sections(meta) or []
|
||||
):
|
||||
# An earlier attachment event does not prove that column
|
||||
# results were observed. Accept the first real manifest.
|
||||
continue
|
||||
update.pop(key, None)
|
||||
previous_summary, summary = meta.get("source_summary"), update.get("source_summary")
|
||||
if isinstance(previous_summary, Mapping) and isinstance(summary, Mapping):
|
||||
update["source_summary"] = {**previous_summary, **summary}
|
||||
meta.update(update)
|
||||
if isinstance(meta.get("source_summary"), Mapping) and "required_sections" in meta:
|
||||
meta["source_summary"] = {
|
||||
**meta["source_summary"], "required_sections": meta["required_sections"],
|
||||
}
|
||||
if (
|
||||
str(payload.get("event") or "").lower() == "progress"
|
||||
and (payload.get("phase") in {"attachments", "upstream"}
|
||||
or any(key in update for key in live_fields))
|
||||
):
|
||||
meta["_transfer_progress_observed"] = True
|
||||
|
||||
|
||||
def _is_video_transfer_item(item: Mapping[str, Any]) -> bool:
|
||||
return str(item.get("kind") or "").lower() == "video" or bool(
|
||||
re.fullmatch(r"视频附件\s*\d+", str(item.get("label") or ""))
|
||||
)
|
||||
|
||||
|
||||
def _transfer_description(meta: Mapping[str, Any], state: str) -> str:
|
||||
lines = [state]
|
||||
sections = _required_transfer_sections(meta)
|
||||
by_key = {str(item.get("key")): item for item in sections or []
|
||||
if isinstance(item, Mapping)}
|
||||
statuses = {
|
||||
"prepared": "已整理,待提交", "submitting": "提交中", "submitted": "已提交",
|
||||
"failed": "提交失败", "omitted": "未提交",
|
||||
}
|
||||
if any(key in by_key for key, _ in _REQUIRED_TRANSFER_SECTIONS):
|
||||
lines.append("资料栏目提交清单:")
|
||||
for key, label in _REQUIRED_TRANSFER_SECTIONS:
|
||||
item = by_key.get(key, {})
|
||||
status = statuses.get(str(item.get("status")), "状态未回报")
|
||||
if item.get("availability") == "empty":
|
||||
status = f"无({status})"
|
||||
lines.append(f"{label}:{status}")
|
||||
elif meta.get("event") == "done":
|
||||
lines.append("当前服务器未回传资料栏目清单,无法核对逐项提交状态。")
|
||||
else:
|
||||
lines.append("资料栏目清单:服务器尚未回传。")
|
||||
summary = meta.get("source_summary")
|
||||
if isinstance(summary, Mapping):
|
||||
counts = [f"{label} {summary[key]} 条" for key, label in _TRANSFER_SOURCE_LABELS
|
||||
@@ -3450,19 +3542,25 @@ def _transfer_description(meta: Mapping[str, Any], state: str) -> str:
|
||||
elif meta.get("source_form") == "full_context":
|
||||
lines.append("本次正文:来源上下文。")
|
||||
items = meta.get("items")
|
||||
visible_items: list[Mapping[str, Any]] = []
|
||||
if isinstance(items, list):
|
||||
kinds = {"image": "图片", "document": "文档", "audio": "音频", "video": "视频", "custom": "附件"}
|
||||
kinds = {"image": "图片", "document": "文档", "audio": "音频", "custom": "附件"}
|
||||
statuses = {"submitting": "提交中", "submitted": "引用已提交", "omitted": "未提交", "failed": "提交失败"}
|
||||
for index, item in enumerate(items, 1):
|
||||
if not isinstance(item, Mapping):
|
||||
continue
|
||||
visible_items = [item for item in items if isinstance(item, Mapping)
|
||||
and not _is_video_transfer_item(item)]
|
||||
for index, item in enumerate(visible_items, 1):
|
||||
kind = kinds.get(str(item.get("kind")), "附件")
|
||||
# Never display a legacy filename, URL or patient-identifying label.
|
||||
label = str(item.get("label") or "")
|
||||
if not re.fullmatch(r"(?:图片附件|文档附件|文件附件|音频附件|视频附件|自定义附件|附件|检查报告|舌象)\s*\d+", label):
|
||||
if not re.fullmatch(r"(?:图片附件|文档附件|文件附件|音频附件|自定义附件|附件|检查报告|舌象)\s*\d+", label):
|
||||
label = f"{kind}附件{index}"
|
||||
lines.append(f"{label}({kind}):{statuses.get(str(item.get('status')), '等待提交')}")
|
||||
count = meta.get("attachment_count")
|
||||
if isinstance(items, list) and any(
|
||||
isinstance(item, Mapping) and _is_video_transfer_item(item)
|
||||
for item in items
|
||||
):
|
||||
count = sum(item.get("status") != "omitted" for item in visible_items)
|
||||
if type(count) is int and count >= 0:
|
||||
lines.append(f"本请求附件通道:{count} 项;模型实际读取进度不可获取。")
|
||||
return "\n".join(lines)
|
||||
@@ -6477,14 +6575,14 @@ class AiConsultDialog(QDialog):
|
||||
payload = dict(event) if isinstance(event, Mapping) else {}
|
||||
kind = str(payload.get("event") or "").lower()
|
||||
if kind == "start":
|
||||
self._stream_meta.update(payload)
|
||||
_merge_stream_meta(self._stream_meta, payload)
|
||||
self._update_stream_elapsed()
|
||||
self._update_transfer_status(AI_STREAM_PENDING_TEXT)
|
||||
if self._stream_bubble is not None and not self._stream_text and not self._pending_chunks:
|
||||
self._stream_bubble.set_payload(AI_STREAM_WAITING_TEXT)
|
||||
return
|
||||
if kind == "progress":
|
||||
self._stream_meta.update(payload)
|
||||
_merge_stream_meta(self._stream_meta, payload)
|
||||
phase = str(payload.get("phase") or "")
|
||||
state = {
|
||||
"preparing": AI_STREAM_PENDING_TEXT,
|
||||
@@ -6493,7 +6591,15 @@ class AiConsultDialog(QDialog):
|
||||
"cancelled": "本次请求已取消;上游是否停止尚未确认。",
|
||||
}.get(phase, "正在处理本请求资料…")
|
||||
if phase == "attachments" and payload.get("status") == "submitted":
|
||||
state = "附件引用已提交,等待模型处理…"
|
||||
items = payload.get("items")
|
||||
visible = [item for item in items if isinstance(item, Mapping)
|
||||
and not _is_video_transfer_item(item)] if isinstance(items, list) else []
|
||||
if visible and all(item.get("status") == "omitted" for item in visible):
|
||||
state = "资料正文已提交;本次附件未提交,等待 AI 正文…"
|
||||
elif payload.get("attachment_count") == 0:
|
||||
state = "资料正文已提交,等待 AI 正文…"
|
||||
else:
|
||||
state = "附件引用已提交,等待模型处理…"
|
||||
if phase == "preparing" and payload.get("status") == "ready":
|
||||
state = "资料正文已整理,正在准备提交…"
|
||||
if payload.get("status") == "failed":
|
||||
@@ -6527,7 +6633,7 @@ class AiConsultDialog(QDialog):
|
||||
return
|
||||
if kind != "done":
|
||||
return
|
||||
self._stream_meta.update(payload)
|
||||
_merge_stream_meta(self._stream_meta, payload)
|
||||
self._stream_completed = True
|
||||
if self._stream_worker is not None:
|
||||
mark_completed = getattr(self._stream_worker, "mark_completed", None)
|
||||
|
||||
Reference in New Issue
Block a user