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:
|
if not config.processing.conversion_options.picture_description.enabled:
|
||||||
return
|
return
|
||||||
pictures = list(doc.pictures or [])
|
if not doc.pictures:
|
||||||
if not pictures:
|
|
||||||
return
|
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:
|
if described == 0:
|
||||||
model = config.processing.conversion_options.picture_description.model
|
model = config.processing.conversion_options.picture_description.model
|
||||||
logger.warning(
|
logger.warning(
|
||||||
|
|
@ -46,7 +45,7 @@ def _warn_if_descriptions_missing(
|
||||||
"reachable from the converter and that the model name '%s' "
|
"reachable from the converter and that the model name '%s' "
|
||||||
"resolves on the server.",
|
"resolves on the server.",
|
||||||
source,
|
source,
|
||||||
len(pictures),
|
len(doc.pictures),
|
||||||
model.base_url or "<provider default>",
|
model.base_url or "<provider default>",
|
||||||
model.name,
|
model.name,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -315,11 +315,10 @@ async def _patch_picture_descriptions(client: "HaikuRAG", doc: Document) -> int:
|
||||||
|
|
||||||
needs_description: list[str] = []
|
needs_description: list[str] = []
|
||||||
for pic in docling_doc.pictures:
|
for pic in docling_doc.pictures:
|
||||||
meta = getattr(pic, "meta", None)
|
|
||||||
existing = (
|
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)
|
needs_description.append(pic.self_ref)
|
||||||
|
|
||||||
if not needs_description:
|
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
|
falls back to ``annotations`` entries that carry a ``text`` field
|
||||||
(PictureDescriptionData and similar).
|
(PictureDescriptionData and similar).
|
||||||
"""
|
"""
|
||||||
meta = getattr(item, "meta", None)
|
if item.meta and item.meta.description:
|
||||||
if meta is not None:
|
text = item.meta.description.text
|
||||||
description = getattr(meta, "description", None)
|
if text and text.strip():
|
||||||
if description is not None:
|
|
||||||
text = getattr(description, "text", None)
|
|
||||||
if isinstance(text, str) and text.strip():
|
|
||||||
return text
|
return text
|
||||||
annotations = getattr(item, "annotations", None) or []
|
# Annotations is a tagged union; only some variants carry `text`.
|
||||||
for ann in annotations:
|
for ann in item.annotations:
|
||||||
text = getattr(ann, "text", None)
|
text = getattr(ann, "text", None)
|
||||||
if isinstance(text, str) and text.strip():
|
if isinstance(text, str) and text.strip():
|
||||||
return text
|
return text
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue