Fix/caption failure logging visibility#608
Conversation
|
I'll retrieve the logs for job 81396718755 to identify the failure and provide a solution.The primary failure is a Python syntax error in the code. Let me retrieve the problematic file to see the exact issue:## Solution for Job 81396718755 The job is failing due to an indentation error in Root CauseLine 185 has incorrect indentation. The The Problem183| return response.choices[0].message.content.strip()
184|
185| except Exception as exc: # ❌ Only 3 spaces (should be 4)
186| logger.warning(The FixChange line 185 to use 4 spaces for indentation: 183| return response.choices[0].message.content.strip()
184|
185| except Exception as exc: # ✅ 4 spaces
186| logger.warning(
187| "OpenAI vision caption failed — falling back to OCR/placeholder. "
188| "This may be a transient API error (rate-limit, timeout). Error: %s",
189| exc,
190| exc_info=True,
191| )
192| return ""Additionally, there's duplicate code in the file (lines 234-254). The def caption_image(
image_bytes: "bytes | List[bytes]",
page: "int | List[int] | None" = None,
) -> "str | List[str]":
"""Generate a caption for a single image or a batch of images.
Resolution order:
1. Configured VLM provider (set VISION_PROVIDER in .env)
2. Local OCR via pytesseract
3. Placeholder string with page number and dimensions
"""
if isinstance(image_bytes, list):
pages = (
page if isinstance(page, list)
else ([page] * len(image_bytes) if page is not None else [None] * len(image_bytes))
)
return [caption_image(img, pg) for img, pg in zip(image_bytes, pages)]
# Strategy: try the configured VLM provider
provider = get_vision_provider(getattr(settings, "VISION_PROVIDER", None))
if provider is not None:
result = provider.caption(image_bytes)
if result:
return result
# Fallback 1: local OCR
ocr = _ocr_caption(image_bytes)
if ocr:
return ocr
# Fallback 2: placeholder
try:
pix = fitz.Pixmap(image_bytes)
dims = f"{pix.width}x{pix.height} px"
except Exception:
dims = "unknown size"
return f"Figure on page {page} ({dims})." if page else f"Figure ({dims})."Remove lines 235-254 as they duplicate the logic already present above. |
|
@param20h please merge this branch |
|
@param20h please merge this branch |
|
running the checks |
|
Backend issues still |
📝 What does this PR do?
Improves visibility of image captioning failures in
generate_captions_for_chunksand
_openai_caption. Previously, exceptions were silently swallowed withlogger.debug, meaning admins had no way to know that image data was beingpermanently discarded. This PR upgrades both to
logger.warningwith actionablemessages and full tracebacks via
exc_info=True.Fixes #590
🗂️ Type of Change
🧪 How was this tested?
npm run devinsidefrontend/)📸 Screenshots (if UI change)
N/A
No flags.
✅ Self-Review Checklist
dev, notmainmainbranch or any HuggingFace deployment config