langchain-ocr-lib 0.2.0__py3-none-any.whl → 0.3.1__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 -3
- langchain_ocr_lib/impl/converter/pdf_converter.py +9 -4
- langchain_ocr_lib/impl/langfuse_manager/langfuse_manager.py +0 -14
- langchain_ocr_lib/impl/llms/llm_type.py +1 -0
- langchain_ocr_lib/impl/settings/ollama_chat_settings.py +1 -1
- langchain_ocr_lib/impl/settings/openai_chat_settings.py +9 -6
- langchain_ocr_lib/impl/settings/vllm_chat_settings.py +38 -0
- {langchain_ocr_lib-0.2.0.dist-info → langchain_ocr_lib-0.3.1.dist-info}/METADATA +5 -5
- {langchain_ocr_lib-0.2.0.dist-info → langchain_ocr_lib-0.3.1.dist-info}/RECORD +11 -10
- {langchain_ocr_lib-0.2.0.dist-info → langchain_ocr_lib-0.3.1.dist-info}/WHEEL +1 -1
- {langchain_ocr_lib-0.2.0.dist-info → langchain_ocr_lib-0.3.1.dist-info}/entry_points.txt +0 -0
langchain_ocr_lib/di_config.py
CHANGED
@@ -14,9 +14,11 @@ from langchain_ocr_lib.di_binding_keys.binding_keys import (
|
|
14
14
|
from langchain_ollama import ChatOllama
|
15
15
|
from langchain_openai import ChatOpenAI
|
16
16
|
from langfuse import Langfuse
|
17
|
+
from functools import partial
|
17
18
|
|
18
19
|
from langchain_ocr_lib.impl.chains.ocr_chain import OcrChain
|
19
20
|
from langchain_ocr_lib.impl.settings.ollama_chat_settings import OllamaSettings
|
21
|
+
from langchain_ocr_lib.impl.settings.vllm_chat_settings import VllmSettings
|
20
22
|
from langchain_ocr_lib.impl.settings.openai_chat_settings import OpenAISettings
|
21
23
|
from langchain_ocr_lib.impl.settings.llm_class_type_settings import LlmClassTypeSettings
|
22
24
|
from langchain_ocr_lib.impl.settings.langfuse_settings import LangfuseSettings
|
@@ -49,13 +51,17 @@ def lib_di_config(binder: Binder):
|
|
49
51
|
|
50
52
|
if llm_class_type_settings.llm_type == "ollama":
|
51
53
|
settings = OllamaSettings()
|
52
|
-
|
54
|
+
partial_llm_provider = partial(llm_provider,settings, ChatOllama)
|
53
55
|
elif llm_class_type_settings.llm_type == "openai":
|
54
56
|
settings = OpenAISettings()
|
55
|
-
|
57
|
+
partial_llm_provider = partial(llm_provider,settings, ChatOpenAI)
|
58
|
+
elif llm_class_type_settings.llm_type == "vllm":
|
59
|
+
settings = VllmSettings()
|
60
|
+
partial_llm_provider = partial(llm_provider,settings, ChatOpenAI)
|
56
61
|
else:
|
57
62
|
raise NotImplementedError("Configured LLM is not implemented")
|
58
|
-
|
63
|
+
|
64
|
+
binder.bind_to_provider(LargeLanguageModelKey, partial_llm_provider)
|
59
65
|
|
60
66
|
prompt = ocr_prompt_template_builder(language=language_settings.language, model_name=settings.model)
|
61
67
|
|
@@ -48,9 +48,11 @@ class Pdf2MarkdownConverter(File2MarkdownConverter):
|
|
48
48
|
with open(filename, "rb") as f:
|
49
49
|
file = f.read()
|
50
50
|
except Exception as e:
|
51
|
-
raise ValueError("PDF corrupted or unsupported file type
|
52
|
-
|
53
|
-
|
51
|
+
raise ValueError("PDF corrupted or unsupported file type") from e
|
52
|
+
try:
|
53
|
+
images = convert_from_bytes(file)
|
54
|
+
except Exception as e:
|
55
|
+
raise ValueError("PDF corrupted or unsupported file type") from e
|
54
56
|
|
55
57
|
markdown = ""
|
56
58
|
for image in images:
|
@@ -93,7 +95,10 @@ class Pdf2MarkdownConverter(File2MarkdownConverter):
|
|
93
95
|
except Exception as e:
|
94
96
|
raise ValueError("PDF corrupted or unsupported file type") from e
|
95
97
|
|
96
|
-
|
98
|
+
try:
|
99
|
+
images = convert_from_bytes(file)
|
100
|
+
except Exception as e:
|
101
|
+
raise ValueError("PDF corrupted or unsupported file type") from e
|
97
102
|
|
98
103
|
markdown = ""
|
99
104
|
for image in images:
|
@@ -35,20 +35,6 @@ class LangfuseManager:
|
|
35
35
|
):
|
36
36
|
self._managed_prompts = managed_prompts
|
37
37
|
|
38
|
-
def init_prompts(self) -> None:
|
39
|
-
"""
|
40
|
-
Initialize the prompts managed by the LangfuseManager.
|
41
|
-
|
42
|
-
This method iterates over the keys of the managed prompts and retrieves
|
43
|
-
each prompt using the `get_langfuse_prompt` method.
|
44
|
-
|
45
|
-
Returns
|
46
|
-
-------
|
47
|
-
None
|
48
|
-
"""
|
49
|
-
for key in list(self._managed_prompts.keys()):
|
50
|
-
self.get_langfuse_prompt(key)
|
51
|
-
|
52
38
|
def get_langfuse_prompt(self, base_prompt_name: str) -> Optional[ChatPromptClient]:
|
53
39
|
"""
|
54
40
|
Retrieve the prompt from Langfuse Prompt Management.
|
@@ -35,7 +35,7 @@ class OllamaSettings(BaseSettings):
|
|
35
35
|
env_prefix = "OLLAMA_"
|
36
36
|
case_sensitive = False
|
37
37
|
|
38
|
-
model: str = Field(default="gemma3:4b-it-q4_K_M")
|
38
|
+
model: str = Field(default="gemma3:4b-it-q4_K_M", title="LLM Model")
|
39
39
|
base_url: str = Field(default="http://localhost:11434")
|
40
40
|
top_k: int = Field(default=0, title="LLM Top K")
|
41
41
|
top_p: float = Field(default=0, title="LLM Top P")
|
@@ -18,8 +18,8 @@ class OpenAISettings(BaseSettings):
|
|
18
18
|
Total probability mass of tokens to consider at each step.
|
19
19
|
temperature : float
|
20
20
|
What sampling temperature to use.
|
21
|
-
|
22
|
-
|
21
|
+
base_url : str
|
22
|
+
The base URL for the OpenAI API endpoint.
|
23
23
|
"""
|
24
24
|
|
25
25
|
class Config:
|
@@ -28,8 +28,11 @@ class OpenAISettings(BaseSettings):
|
|
28
28
|
env_prefix = "OPENAI_"
|
29
29
|
case_sensitive = False
|
30
30
|
|
31
|
-
model: str = Field(default="gpt-4o-mini-search-preview-2025-03-11", description="The model identifier")
|
31
|
+
model: str = Field(default="gpt-4o-mini-search-preview-2025-03-11", description="The model identifier", title="LLM Model")
|
32
32
|
api_key: str = Field(default="", description="The API key for authentication")
|
33
|
-
top_p: float = Field(default=1.0, description="Total probability mass of tokens to consider at each step")
|
34
|
-
temperature: float = Field(default=0
|
35
|
-
|
33
|
+
top_p: float = Field(default=1.0, description="Total probability mass of tokens to consider at each step", title="Top P")
|
34
|
+
temperature: float = Field(default=0, description="What sampling temperature to use", title="Temperature")
|
35
|
+
base_url: str = Field(
|
36
|
+
default="https://api.openai.com/v1",
|
37
|
+
description="The base URL for the OpenAI API endpoint",
|
38
|
+
)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
"""Module contains settings regarding the Vllm API."""
|
2
|
+
|
3
|
+
from pydantic import Field
|
4
|
+
from pydantic_settings import BaseSettings
|
5
|
+
|
6
|
+
|
7
|
+
class VllmSettings(BaseSettings):
|
8
|
+
"""
|
9
|
+
Contains settings regarding the Vllm API.
|
10
|
+
|
11
|
+
Attributes
|
12
|
+
----------
|
13
|
+
model : str
|
14
|
+
The model identifier.
|
15
|
+
api_key : str
|
16
|
+
The API key for authentication.
|
17
|
+
top_p : float
|
18
|
+
Total probability mass of tokens to consider at each step.
|
19
|
+
temperature : float
|
20
|
+
What sampling temperature to use.
|
21
|
+
base_url : str
|
22
|
+
The base URL for the Vllm API endpoint.
|
23
|
+
"""
|
24
|
+
|
25
|
+
class Config:
|
26
|
+
"""Config class for reading fields from environment variables."""
|
27
|
+
|
28
|
+
env_prefix = "VLLM_"
|
29
|
+
case_sensitive = False
|
30
|
+
|
31
|
+
model: str = Field(default="", description="The model identifier", title="LLM Model")
|
32
|
+
api_key: str = Field(default="", description="The API key for authentication")
|
33
|
+
top_p: float = Field(default=1.0, description="Total probability mass of tokens to consider at each step", title="Top P")
|
34
|
+
temperature: float = Field(default=0, description="What sampling temperature to use", title="Temperature")
|
35
|
+
base_url: str = Field(
|
36
|
+
default="http://localhost:8000/v1",
|
37
|
+
description="The base URL for the Vllm API endpoint",
|
38
|
+
)
|
@@ -1,7 +1,7 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.3
|
2
2
|
Name: langchain-ocr-lib
|
3
|
-
Version: 0.
|
4
|
-
Summary:
|
3
|
+
Version: 0.3.1
|
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
|
7
7
|
Author-email: aklos@outlook.de
|
@@ -54,7 +54,7 @@ This package offers the core functionality to extract text from documents using
|
|
54
54
|
|
55
55
|
## 2. Features
|
56
56
|
|
57
|
-
- **Vision-Language OCR:** Supports Ollama. Other LLM providers
|
57
|
+
- **Vision-Language OCR:** Supports Ollama, vLLM and OpenAI (and other OpenAI conform providers). Other LLM providers can be easily integrated.
|
58
58
|
- **CLI Interface:** Simple local execution via command line or container
|
59
59
|
- **Highly Configurable:** Use environment variables to configure the OCR
|
60
60
|
- **Dependency Injection:** Easily swap out components for custom implementations
|
@@ -70,7 +70,7 @@ This package offers the core functionality to extract text from documents using
|
|
70
70
|
- **Python:** 3.11+
|
71
71
|
- **Poetry:** [Install Poetry](https://python-poetry.org/docs/)
|
72
72
|
- **Docker:** For containerized CLI usage (optional)
|
73
|
-
- **Ollama:** Follow instructions [here](https://ollama.com)
|
73
|
+
- **Ollama:** Follow instructions [here](https://ollama.com) (other LLM providers can be used as well, see [here](#2-features))
|
74
74
|
- **Langfuse:** Different options for self hosting, see [here](https://langfuse.com/self-hosting) (optional, for observability)
|
75
75
|
|
76
76
|
### 3.2 Environment Setup
|
@@ -5,24 +5,25 @@ 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=K11ZHkUDP1TsYzZSRMnrbnroovw-_CCbyxHNo9kjRCw,3640
|
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
|
12
12
|
langchain_ocr_lib/impl/converter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
13
|
langchain_ocr_lib/impl/converter/image_converter.py,sha256=G1rDOCbudWNL4sDvSGJ7CeeFrWUblfWPGaZf5JsnpiM,2871
|
14
|
-
langchain_ocr_lib/impl/converter/pdf_converter.py,sha256=
|
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=nfIuOSOsewH6azNNtrsGxSrGI2Blt2fhbp-PBbgXJ2I,4995
|
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
|
-
langchain_ocr_lib/impl/llms/llm_type.py,sha256=
|
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
21
|
langchain_ocr_lib/impl/settings/langfuse_settings.py,sha256=5lr3tVeiHXDUaYtWAnZPXrKxBJgM2wgaz7yyZThhCsE,812
|
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
|
-
langchain_ocr_lib/impl/settings/ollama_chat_settings.py,sha256=
|
25
|
-
langchain_ocr_lib/impl/settings/openai_chat_settings.py,sha256=
|
24
|
+
langchain_ocr_lib/impl/settings/ollama_chat_settings.py,sha256=YQkgD7CfOjHN5wkpJakO0GfM7-D2GqoJLP1gB2932ms,1525
|
25
|
+
langchain_ocr_lib/impl/settings/openai_chat_settings.py,sha256=NqVfkcI8OoD8TVxyv4l0G9ycUC6LIs6Qs4kQRL24doA,1331
|
26
|
+
langchain_ocr_lib/impl/settings/vllm_chat_settings.py,sha256=Zr4L6Urp-f1JZu7Q1dwL6671EQbrIIYL0ubJSQlod3c,1281
|
26
27
|
langchain_ocr_lib/impl/tracers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
27
28
|
langchain_ocr_lib/impl/tracers/langfuse_traced_chain.py,sha256=syjwNt8HfVmaWXZ-ElFYsc-KwpnKQz2LE3K5jV7c3GE,1599
|
28
29
|
langchain_ocr_lib/language_mapping/language_mapping.py,sha256=VY7WkkZauoHNxkvgUYbig0rDmlKqDkz24cXMd6A7txM,700
|
@@ -31,7 +32,7 @@ langchain_ocr_lib/prompt_templates/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQe
|
|
31
32
|
langchain_ocr_lib/prompt_templates/ocr_prompt.py,sha256=3Be1AL-HJkxPnAP0DNH1MqvAxFWTCeM5UOKP63xkHsY,3543
|
32
33
|
langchain_ocr_lib/tracers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
33
34
|
langchain_ocr_lib/tracers/traced_chain.py,sha256=uxRkdLNn_G6dAsti_gUuF7muhIj10xrOUL7HUga40oc,3056
|
34
|
-
langchain_ocr_lib-0.
|
35
|
-
langchain_ocr_lib-0.
|
36
|
-
langchain_ocr_lib-0.
|
37
|
-
langchain_ocr_lib-0.
|
35
|
+
langchain_ocr_lib-0.3.1.dist-info/METADATA,sha256=3FLR8CPBSpusTzAslaBIC5_4sz27ofyvkDQ3oGl4Nwo,6329
|
36
|
+
langchain_ocr_lib-0.3.1.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
37
|
+
langchain_ocr_lib-0.3.1.dist-info/entry_points.txt,sha256=l4mIs0tnIgbJYuVveZySQKVBnqNMHS-8ZZtLwz8ag5k,61
|
38
|
+
langchain_ocr_lib-0.3.1.dist-info/RECORD,,
|
File without changes
|