Simplify
This commit is contained in:
parent
788fac422e
commit
387032511e
3 changed files with 11 additions and 16 deletions
|
|
@ -33,10 +33,9 @@ def _warn_if_descriptions_missing(
|
|||
"""
|
||||
if not config.processing.conversion_options.picture_description.enabled:
|
||||
return
|
||||
pictures = list(doc.pictures or [])
|
||||
if not pictures:
|
||||
if not doc.pictures:
|
||||
return
|
||||
described = sum(1 for p in pictures if _picture_description_text(p))
|
||||
described = sum(1 for p in doc.pictures if _picture_description_text(p))
|
||||
if described == 0:
|
||||
model = config.processing.conversion_options.picture_description.model
|
||||
logger.warning(
|
||||
|
|
@ -46,7 +45,7 @@ def _warn_if_descriptions_missing(
|
|||
"reachable from the converter and that the model name '%s' "
|
||||
"resolves on the server.",
|
||||
source,
|
||||
len(pictures),
|
||||
len(doc.pictures),
|
||||
model.base_url or "<provider default>",
|
||||
model.name,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -315,11 +315,10 @@ async def _patch_picture_descriptions(client: "HaikuRAG", doc: Document) -> int:
|
|||
|
||||
needs_description: list[str] = []
|
||||
for pic in docling_doc.pictures:
|
||||
meta = getattr(pic, "meta", None)
|
||||
existing = (
|
||||
getattr(getattr(meta, "description", None), "text", None) if meta else None
|
||||
pic.meta.description.text if pic.meta and pic.meta.description else None
|
||||
)
|
||||
if not (isinstance(existing, str) and existing.strip()):
|
||||
if not (existing and existing.strip()):
|
||||
needs_description.append(pic.self_ref)
|
||||
|
||||
if not needs_description:
|
||||
|
|
|
|||
|
|
@ -24,15 +24,12 @@ def _picture_description_text(item: "PictureItem") -> str | None:
|
|||
falls back to ``annotations`` entries that carry a ``text`` field
|
||||
(PictureDescriptionData and similar).
|
||||
"""
|
||||
meta = getattr(item, "meta", None)
|
||||
if meta is not None:
|
||||
description = getattr(meta, "description", None)
|
||||
if description is not None:
|
||||
text = getattr(description, "text", None)
|
||||
if isinstance(text, str) and text.strip():
|
||||
return text
|
||||
annotations = getattr(item, "annotations", None) or []
|
||||
for ann in annotations:
|
||||
if item.meta and item.meta.description:
|
||||
text = item.meta.description.text
|
||||
if text and text.strip():
|
||||
return text
|
||||
# Annotations is a tagged union; only some variants carry `text`.
|
||||
for ann in item.annotations:
|
||||
text = getattr(ann, "text", None)
|
||||
if isinstance(text, str) and text.strip():
|
||||
return text
|
||||
|
|
|
|||
Loading…
Reference in a new issue