Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

add monkey patch for docx parse error

Windfarer6058f1cbe07c
diff --git a/docreader/parser/docx_parser.py b/docreader/parser/docx_parser.py
index 12ffd4a98..882da7e4c 100644
--- a/docreader/parser/docx_parser.py
+++ b/docreader/parser/docx_parser.py
@@ -11,6 +11,28 @@ from io import BytesIO
from multiprocessing import Manager
from typing import Any, Dict, List, Optional, Tuple
+from docx.opc.pkgreader import _SerializedRelationships, _SerializedRelationship
+from docx.opc.oxml import parse_xml
+
+
+def load_from_xml_v2(baseURI, rels_item_xml):
+ """
+ Return |_SerializedRelationships| instance loaded with the
+ relationships contained in *rels_item_xml*. Returns an empty
+ collection if *rels_item_xml* is |None|.
+ """
+ srels = _SerializedRelationships()
+ if rels_item_xml is not None:
+ rels_elm = parse_xml(rels_item_xml)
+ for rel_elm in rels_elm.Relationship_lst:
+ if rel_elm.target_ref in ('../NULL', 'NULL'):
+ continue
+ srels._srels.append(_SerializedRelationship(baseURI, rel_elm))
+ return srels
+
+
+_SerializedRelationships.load_from_xml = load_from_xml_v2
+
from docx import Document
from docx.image.exceptions import (
InvalidImageStreamError,