kaxil commented on code in PR #77478:
URL: https://github.com/apache/airflow/pull/77478#discussion_r4741454461
##########
providers/common/ai/src/airflow/providers/common/ai/operators/document_loader.py:
##########
@@ -483,19 +511,24 @@ def _parse_docx_stream(self, stream: BinaryIO, *,
source_hint: str) -> list[dict
raise AirflowOptionalProviderFeatureException(e)
doc = Document(stream)
+ budget = _DocxBudget()
blocks = []
- for block in doc.iter_inner_content():
- if isinstance(block, Table):
- rows = self._get_docx_table_rows_or_none(
- block, Table, _Cell, InvalidXmlError,
source_hint=source_hint
- )
- if rows is None:
- continue
- text = "\n".join(f"| {' | '.join(cells)} |" for cells in rows)
- else:
- text = block.text
- if text.strip():
- blocks.append(text)
+ try:
+ for block in doc.iter_inner_content():
+ if isinstance(block, Table):
+ rows = self._get_docx_table_rows_or_none(
+ block, Table, _Cell, InvalidXmlError, budget=budget,
source_hint=source_hint
+ )
+ if rows is None:
+ continue
+ text = "\n".join(f"| {' | '.join(cells)} |" for cells in
rows)
+ else:
+ text = block.text
+ budget.charge(len(text))
+ if text.strip():
+ blocks.append(text)
+ except _DocxLimitReachedError as e:
+ self.log.warning("Stopped reading %s because %s; the rest is left
out.", source_hint, e)
text = "\n\n".join(blocks)
return [{"text": text, "metadata": {}}]
Review Comment:
I'd set it there too: either way the text isn't the whole file, and that's
what a downstream step needs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]