langchain-ocr-lib 0.3.1__py3-none-any.whl → 0.3.2__py3-none-any.whl
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.
- langchain_ocr_lib/di_config.py +9 -7
- langchain_ocr_lib/impl/langfuse_manager/langfuse_manager.py +12 -7
- langchain_ocr_lib/impl/settings/langfuse_settings.py +4 -0
- {langchain_ocr_lib-0.3.1.dist-info → langchain_ocr_lib-0.3.2.dist-info}/METADATA +10 -6
- {langchain_ocr_lib-0.3.1.dist-info → langchain_ocr_lib-0.3.2.dist-info}/RECORD +7 -7
- {langchain_ocr_lib-0.3.1.dist-info → langchain_ocr_lib-0.3.2.dist-info}/WHEEL +0 -0
- {langchain_ocr_lib-0.3.1.dist-info → langchain_ocr_lib-0.3.2.dist-info}/entry_points.txt +0 -0
langchain_ocr_lib/di_config.py
CHANGED
@@ -80,17 +80,19 @@ def lib_di_config(binder: Binder):
|
|
80
80
|
managed_prompts={
|
81
81
|
OcrChain.__name__: prompt,
|
82
82
|
},
|
83
|
+
enabled=langfuse_settings.enabled,
|
83
84
|
),
|
84
85
|
)
|
85
86
|
|
86
|
-
binder.bind(OcrChainKey, OcrChain())
|
87
|
+
binder.bind(OcrChainKey if langfuse_settings.enabled else LangfuseTracedChainKey, OcrChain())
|
87
88
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
89
|
+
if langfuse_settings.enabled:
|
90
|
+
binder.bind(
|
91
|
+
LangfuseTracedChainKey,
|
92
|
+
LangfuseTracedChain(
|
93
|
+
settings=langfuse_settings,
|
94
|
+
),
|
95
|
+
)
|
94
96
|
|
95
97
|
binder.bind(PdfConverterKey, Pdf2MarkdownConverter())
|
96
98
|
binder.bind(ImageConverterKey, Image2MarkdownConverter())
|
@@ -32,8 +32,10 @@ class LangfuseManager:
|
|
32
32
|
def __init__(
|
33
33
|
self,
|
34
34
|
managed_prompts: dict[str, str],
|
35
|
+
enabled: bool = True,
|
35
36
|
):
|
36
37
|
self._managed_prompts = managed_prompts
|
38
|
+
self._enabled = enabled
|
37
39
|
|
38
40
|
def get_langfuse_prompt(self, base_prompt_name: str) -> Optional[ChatPromptClient]:
|
39
41
|
"""
|
@@ -56,6 +58,9 @@ class LangfuseManager:
|
|
56
58
|
Exception
|
57
59
|
If an error occurs while retrieving the prompt template from Langfuse.
|
58
60
|
"""
|
61
|
+
if not self._enabled:
|
62
|
+
logger.info("Langfuse is not enabled. Using fallback prompt.")
|
63
|
+
return None
|
59
64
|
try:
|
60
65
|
langfuse_prompt = self._langfuse.get_prompt(base_prompt_name)
|
61
66
|
except NotFoundError:
|
@@ -72,11 +77,7 @@ class LangfuseManager:
|
|
72
77
|
)
|
73
78
|
langfuse_prompt = self._langfuse.get_prompt(base_prompt_name)
|
74
79
|
except Exception as error:
|
75
|
-
logger.error(
|
76
|
-
"Error occured while getting prompt template from langfuse. Error:\n{error}",
|
77
|
-
extra={error: error},
|
78
|
-
)
|
79
|
-
return None
|
80
|
+
logger.error(f"Error occurred while getting prompt template from langfuse. Error:\n{error}")
|
80
81
|
return langfuse_prompt
|
81
82
|
|
82
83
|
def get_base_llm(self, name: str) -> LLM:
|
@@ -94,9 +95,12 @@ class LangfuseManager:
|
|
94
95
|
The base Large Language Model. If the Langfuse prompt is not found,
|
95
96
|
returns the LLM with a fallback configuration.
|
96
97
|
"""
|
98
|
+
if not self._enabled:
|
99
|
+
logger.info("Langfuse is not enabled. Using fallback LLM.")
|
100
|
+
return self._llm
|
97
101
|
langfuse_prompt = self.get_langfuse_prompt(name)
|
98
102
|
if not langfuse_prompt:
|
99
|
-
logger.
|
103
|
+
logger.warning("Could not retrieve prompt template from langfuse. Using fallback LLM.")
|
100
104
|
return self._llm
|
101
105
|
|
102
106
|
return self._llm.with_config({"configurable": langfuse_prompt.config})
|
@@ -121,7 +125,8 @@ class LangfuseManager:
|
|
121
125
|
"""
|
122
126
|
langfuse_prompt = self.get_langfuse_prompt(name)
|
123
127
|
if not langfuse_prompt:
|
124
|
-
|
128
|
+
if self._enabled:
|
129
|
+
logger.warning("Could not retrieve prompt template from langfuse. Using fallback value.")
|
125
130
|
fallback = self._managed_prompts[name]
|
126
131
|
if isinstance(fallback, ChatPromptTemplate):
|
127
132
|
return fallback
|
@@ -27,3 +27,7 @@ class LangfuseSettings(BaseSettings):
|
|
27
27
|
secret_key: str = Field(default="", description="The secret key for Langfuse.")
|
28
28
|
public_key: str = Field(default="", description="The public key for Langfuse.")
|
29
29
|
host: str = Field(default="https://api.langchain.com", description="The host for Langfuse.")
|
30
|
+
enabled: bool = Field(
|
31
|
+
default=True,
|
32
|
+
description="Whether to enable Langfuse. If set to False, Langfuse will not be used.",
|
33
|
+
)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: langchain-ocr-lib
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.2
|
4
4
|
Summary: Modular, vision-LLM-powered chain to convert image and PDF documents into clean Markdown.
|
5
5
|
License: MIT
|
6
6
|
Author: Andreas Klos
|
@@ -25,9 +25,13 @@ Requires-Dist: pytest-asyncio (>=0.25.0,<0.26.0)
|
|
25
25
|
Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
|
26
26
|
Description-Content-Type: text/markdown
|
27
27
|
|
28
|
-
#
|
28
|
+
# langchain-ocr-lib
|
29
29
|
|
30
|
-
**
|
30
|
+
**langchain-ocr-lib** is the OCR processing engine behind LangChain-OCR. It provides a modular, vision-LLM-powered Chain to convert image and PDF documents into clean Markdown. Designed for direct CLI usage or integration into larger applications.
|
31
|
+
|
32
|
+
<div align="center">
|
33
|
+
<img src="./images/logo.png" alt="Logo" style="width:30%;">
|
34
|
+
</div>
|
31
35
|
|
32
36
|
## Table of Contents
|
33
37
|
|
@@ -137,7 +141,7 @@ class Converter:
|
|
137
141
|
return self._converter.convert2markdown(filename=filename)
|
138
142
|
|
139
143
|
converter = Converter()
|
140
|
-
markdown = converter.convert("../
|
144
|
+
markdown = converter.convert("../examples/invoice.pdf") # Adjust the file path as needed
|
141
145
|
print(markdown)
|
142
146
|
```
|
143
147
|
|
@@ -174,7 +178,7 @@ class Converter:
|
|
174
178
|
self._converter.convert(filename=filename)
|
175
179
|
|
176
180
|
converter = Converter()
|
177
|
-
converter.convert("../
|
181
|
+
converter.convert("../examples/invoice.pdf") # Adjust the file path as needed
|
178
182
|
```
|
179
183
|
|
180
184
|
### 4.3 Docker
|
@@ -183,6 +187,6 @@ Run OCR via Docker without local Python setup:
|
|
183
187
|
|
184
188
|
```bash
|
185
189
|
docker build -t ocr -f langchain_ocr_lib/Dockerfile .
|
186
|
-
docker run --net=host -it --rm -v ./
|
190
|
+
docker run --net=host -it --rm -v ./examples:/app/examples:ro ocr examples/invoice.png
|
187
191
|
```
|
188
192
|
|
@@ -5,7 +5,7 @@ langchain_ocr_lib/converter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMp
|
|
5
5
|
langchain_ocr_lib/converter/converter.py,sha256=oDUNzVWD743RgqIal7T4OVv-Z1RKE9uQYzAIPpgY3o8,1280
|
6
6
|
langchain_ocr_lib/di_binding_keys/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
7
|
langchain_ocr_lib/di_binding_keys/binding_keys.py,sha256=jE8rwNcLaI0NflIMkK0vu0LVy5o4y0pYgdjbpDNTGyk,338
|
8
|
-
langchain_ocr_lib/di_config.py,sha256=
|
8
|
+
langchain_ocr_lib/di_config.py,sha256=LvRnptts1VCDa3HVP7jtBtQTyG-QEErbyplGX86uaUA,3802
|
9
9
|
langchain_ocr_lib/impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
10
|
langchain_ocr_lib/impl/chains/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
11
|
langchain_ocr_lib/impl/chains/ocr_chain.py,sha256=stE8RLE1ieRHf6XHreKCRfhNfXzw9fNLTake7xQBGL8,2673
|
@@ -13,12 +13,12 @@ langchain_ocr_lib/impl/converter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRk
|
|
13
13
|
langchain_ocr_lib/impl/converter/image_converter.py,sha256=G1rDOCbudWNL4sDvSGJ7CeeFrWUblfWPGaZf5JsnpiM,2871
|
14
14
|
langchain_ocr_lib/impl/converter/pdf_converter.py,sha256=pTHPojuNLCSWJp4FzXBHshXva2sBGyOs6Y7jnKJrnNo,3760
|
15
15
|
langchain_ocr_lib/impl/langfuse_manager/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
16
|
-
langchain_ocr_lib/impl/langfuse_manager/langfuse_manager.py,sha256=
|
16
|
+
langchain_ocr_lib/impl/langfuse_manager/langfuse_manager.py,sha256=C2waQ1Mvqz6bECXAcaMiBsE8TLc2kLr5QUIgXqgH_cE,5311
|
17
17
|
langchain_ocr_lib/impl/llms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
18
18
|
langchain_ocr_lib/impl/llms/llm_factory.py,sha256=9DsUdoYNrjeWLGA9ISDdHN2cxcQ7DquNQ5it6zSxHlg,2199
|
19
19
|
langchain_ocr_lib/impl/llms/llm_type.py,sha256=_LKtdVuTRYX6gupkxJtEtIwrbtiMvZmG8WOxfzlm42M,286
|
20
20
|
langchain_ocr_lib/impl/settings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
21
|
-
langchain_ocr_lib/impl/settings/langfuse_settings.py,sha256=
|
21
|
+
langchain_ocr_lib/impl/settings/langfuse_settings.py,sha256=QT4_VwYj0msFbgL3qIQ-oer3Lt0qny0FFAyfssGu-q0,962
|
22
22
|
langchain_ocr_lib/impl/settings/language_settings.py,sha256=tdAC1t5wGu1MoH1jhjkDnxnX4Ui7giwxt7Qm8_LPkP8,627
|
23
23
|
langchain_ocr_lib/impl/settings/llm_class_type_settings.py,sha256=4KC6zxby13wn38rB8055J8LNVTsmUfrOiyLtLuToHaM,598
|
24
24
|
langchain_ocr_lib/impl/settings/ollama_chat_settings.py,sha256=YQkgD7CfOjHN5wkpJakO0GfM7-D2GqoJLP1gB2932ms,1525
|
@@ -32,7 +32,7 @@ langchain_ocr_lib/prompt_templates/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQe
|
|
32
32
|
langchain_ocr_lib/prompt_templates/ocr_prompt.py,sha256=3Be1AL-HJkxPnAP0DNH1MqvAxFWTCeM5UOKP63xkHsY,3543
|
33
33
|
langchain_ocr_lib/tracers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
34
34
|
langchain_ocr_lib/tracers/traced_chain.py,sha256=uxRkdLNn_G6dAsti_gUuF7muhIj10xrOUL7HUga40oc,3056
|
35
|
-
langchain_ocr_lib-0.3.
|
36
|
-
langchain_ocr_lib-0.3.
|
37
|
-
langchain_ocr_lib-0.3.
|
38
|
-
langchain_ocr_lib-0.3.
|
35
|
+
langchain_ocr_lib-0.3.2.dist-info/METADATA,sha256=MYG6NqcxYMkVY2UQ0SbSCdNmpSJJ98NUb5KLBSDciyg,6440
|
36
|
+
langchain_ocr_lib-0.3.2.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
37
|
+
langchain_ocr_lib-0.3.2.dist-info/entry_points.txt,sha256=l4mIs0tnIgbJYuVveZySQKVBnqNMHS-8ZZtLwz8ag5k,61
|
38
|
+
langchain_ocr_lib-0.3.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|