HowdenParser 5.1.0__tar.gz → 5.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {howdenparser-5.1.0 → howdenparser-5.2.0}/HowdenParser/parser.py +27 -0
- {howdenparser-5.1.0 → howdenparser-5.2.0}/HowdenParser/parsers/llama_parser.py +8 -1
- {howdenparser-5.1.0 → howdenparser-5.2.0}/PKG-INFO +1 -1
- {howdenparser-5.1.0 → howdenparser-5.2.0}/pyproject.toml +1 -1
- {howdenparser-5.1.0 → howdenparser-5.2.0}/HowdenParser/__init__.py +0 -0
- {howdenparser-5.1.0 → howdenparser-5.2.0}/HowdenParser/parameter/__init__.py +0 -0
- {howdenparser-5.1.0 → howdenparser-5.2.0}/HowdenParser/parameter/llamaparser.py +0 -0
- {howdenparser-5.1.0 → howdenparser-5.2.0}/HowdenParser/parameter/mistralocr.py +0 -0
- {howdenparser-5.1.0 → howdenparser-5.2.0}/HowdenParser/parsers/__init__.py +0 -0
- {howdenparser-5.1.0 → howdenparser-5.2.0}/HowdenParser/parsers/langchain_parser.py +0 -0
- {howdenparser-5.1.0 → howdenparser-5.2.0}/HowdenParser/parsers/mistral_parser.py +0 -0
- {howdenparser-5.1.0 → howdenparser-5.2.0}/README.md +0 -0
|
@@ -3,6 +3,9 @@ import logging
|
|
|
3
3
|
import dotenv
|
|
4
4
|
from typing import overload, Literal
|
|
5
5
|
from inspect import signature, Signature
|
|
6
|
+
from typing import Any
|
|
7
|
+
import json
|
|
8
|
+
import hashlib
|
|
6
9
|
|
|
7
10
|
dotenv.load_dotenv()
|
|
8
11
|
logger = logging.getLogger(__name__)
|
|
@@ -26,6 +29,30 @@ class BaseParser(ABC):
|
|
|
26
29
|
def parse(self, text: str, include_pagenumbers: bool = False):
|
|
27
30
|
pass
|
|
28
31
|
|
|
32
|
+
def make_serializable(self, obj: Any) -> Any:
|
|
33
|
+
if obj is None or isinstance(obj, (str, int, float, bool)):
|
|
34
|
+
return obj
|
|
35
|
+
if isinstance(obj, (list, tuple, set)):
|
|
36
|
+
return [self.make_serializable(v) for v in obj]
|
|
37
|
+
if isinstance(obj, dict):
|
|
38
|
+
return {k: self.make_serializable(v) for k, v in sorted(obj.items())}
|
|
39
|
+
if hasattr(obj, "__dict__"):
|
|
40
|
+
return self.make_serializable(vars(obj))
|
|
41
|
+
return f"{type(obj).__name__}:{repr(obj)}"
|
|
42
|
+
|
|
43
|
+
def compute_hash(self, parameter:dict) -> str:
|
|
44
|
+
|
|
45
|
+
attrs = {
|
|
46
|
+
k: v
|
|
47
|
+
for k, v in parameter.items()
|
|
48
|
+
if k != "hash"
|
|
49
|
+
and not k.startswith("_")
|
|
50
|
+
and k not in ("client", "provider")
|
|
51
|
+
}
|
|
52
|
+
serializable = self.make_serializable(attrs)
|
|
53
|
+
attrs_str = json.dumps(serializable, sort_keys=True, ensure_ascii=True)
|
|
54
|
+
hashed = hashlib.sha256(attrs_str.encode()).hexdigest()[:8]
|
|
55
|
+
return hashed
|
|
29
56
|
|
|
30
57
|
class Parser(BaseParser):
|
|
31
58
|
"""Factory + registry interface for all parsers."""
|
|
@@ -9,6 +9,13 @@ class LlamaParser(BaseParser, name="llamaparser"):
|
|
|
9
9
|
hide_footers: bool, hide_headers: bool) -> None:
|
|
10
10
|
|
|
11
11
|
super().__init__()
|
|
12
|
+
# Capture only input parameters
|
|
13
|
+
self._input_params = {
|
|
14
|
+
k: v
|
|
15
|
+
for k, v in locals().items()
|
|
16
|
+
if k not in ("self", "__class__", "__len__")
|
|
17
|
+
}
|
|
18
|
+
|
|
12
19
|
logging.info("Configuring LlamaParser (lazy init enabled)...")
|
|
13
20
|
|
|
14
21
|
# Store configuration only
|
|
@@ -20,7 +27,7 @@ class LlamaParser(BaseParser, name="llamaparser"):
|
|
|
20
27
|
self.preserve_layout_alignment_across_pages = preserve_layout_alignment_across_pages
|
|
21
28
|
self.hide_footers = hide_footers
|
|
22
29
|
self.hide_headers = hide_headers
|
|
23
|
-
|
|
30
|
+
self.hashed = self.compute_hash(self._input_params)
|
|
24
31
|
# DO NOT CREATE LlamaParse HERE
|
|
25
32
|
# It creates asyncio objects bound to the wrong loop
|
|
26
33
|
self._parser = None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|