langchain-ocr-lib 0.2.0__tar.gz → 0.3.1__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.
Files changed (37) hide show
  1. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/PKG-INFO +5 -5
  2. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/README.md +2 -2
  3. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/pyproject.toml +4 -4
  4. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/di_config.py +9 -3
  5. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/impl/converter/pdf_converter.py +9 -4
  6. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/impl/langfuse_manager/langfuse_manager.py +0 -14
  7. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/impl/llms/llm_type.py +1 -0
  8. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/impl/settings/ollama_chat_settings.py +1 -1
  9. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/impl/settings/openai_chat_settings.py +9 -6
  10. langchain_ocr_lib-0.3.1/src/langchain_ocr_lib/impl/settings/vllm_chat_settings.py +38 -0
  11. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/__init__.py +0 -0
  12. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/chains/__init__.py +0 -0
  13. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/chains/chain.py +0 -0
  14. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/converter/__init__.py +0 -0
  15. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/converter/converter.py +0 -0
  16. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/di_binding_keys/__init__.py +0 -0
  17. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/di_binding_keys/binding_keys.py +0 -0
  18. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/impl/__init__.py +0 -0
  19. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/impl/chains/__init__.py +0 -0
  20. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/impl/chains/ocr_chain.py +0 -0
  21. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/impl/converter/__init__.py +0 -0
  22. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/impl/converter/image_converter.py +0 -0
  23. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/impl/langfuse_manager/__init__.py +0 -0
  24. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/impl/llms/__init__.py +0 -0
  25. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/impl/llms/llm_factory.py +0 -0
  26. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/impl/settings/__init__.py +0 -0
  27. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/impl/settings/langfuse_settings.py +0 -0
  28. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/impl/settings/language_settings.py +0 -0
  29. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/impl/settings/llm_class_type_settings.py +0 -0
  30. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/impl/tracers/__init__.py +0 -0
  31. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/impl/tracers/langfuse_traced_chain.py +0 -0
  32. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/language_mapping/language_mapping.py +0 -0
  33. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/main.py +0 -0
  34. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/prompt_templates/__init__.py +0 -0
  35. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/prompt_templates/ocr_prompt.py +0 -0
  36. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/tracers/__init__.py +0 -0
  37. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.1}/src/langchain_ocr_lib/tracers/traced_chain.py +0 -0
@@ -1,7 +1,7 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: langchain-ocr-lib
3
- Version: 0.2.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 will be added soon.
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
@@ -27,7 +27,7 @@ This package offers the core functionality to extract text from documents using
27
27
 
28
28
  ## 2. Features
29
29
 
30
- - **Vision-Language OCR:** Supports Ollama. Other LLM providers will be added soon.
30
+ - **Vision-Language OCR:** Supports Ollama, vLLM and OpenAI (and other OpenAI conform providers). Other LLM providers can be easily integrated.
31
31
  - **CLI Interface:** Simple local execution via command line or container
32
32
  - **Highly Configurable:** Use environment variables to configure the OCR
33
33
  - **Dependency Injection:** Easily swap out components for custom implementations
@@ -43,7 +43,7 @@ This package offers the core functionality to extract text from documents using
43
43
  - **Python:** 3.11+
44
44
  - **Poetry:** [Install Poetry](https://python-poetry.org/docs/)
45
45
  - **Docker:** For containerized CLI usage (optional)
46
- - **Ollama:** Follow instructions [here](https://ollama.com)
46
+ - **Ollama:** Follow instructions [here](https://ollama.com) (other LLM providers can be used as well, see [here](#2-features))
47
47
  - **Langfuse:** Different options for self hosting, see [here](https://langfuse.com/self-hosting) (optional, for observability)
48
48
 
49
49
  ### 3.2 Environment Setup
@@ -1,5 +1,5 @@
1
1
  [build-system]
2
- requires = ["poetry-core==1.8.5"]
2
+ requires = ["poetry-core==2.1.2"]
3
3
  build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry.scripts]
@@ -7,8 +7,8 @@ langchain-ocr = "langchain_ocr_lib.main:main"
7
7
 
8
8
  [tool.poetry]
9
9
  name = "langchain-ocr-lib"
10
- version = "0.2.0"
11
- description = ""
10
+ version = "0.3.1"
11
+ description = "Modular, vision-LLM-powered chain to convert image and PDF documents into clean Markdown."
12
12
  authors = ["Andreas Klos <aklos@outlook.de>"]
13
13
  readme = "README.md"
14
14
  packages = [{ include = "langchain_ocr_lib", from = "src" }]
@@ -59,7 +59,7 @@ flake8-docstrings = "^1.7.0"
59
59
 
60
60
 
61
61
  [tool.flake8]
62
- exclude= [".eggs", ".git", ".hg", ".mypy_cache", ".tox", ".venv", ".devcontainer", "venv", "_build", "buck-out", "build", "dist", "**/__init__.py", "src/langchain_ocr_lib/prompt_templates/ocr_prompt.py"]
62
+ exclude= [".eggs", ".git", ".hg", ".mypy_cache", ".tox", ".venv", ".devcontainer", "venv", "_build", "buck-out", "build", "dist", "**/__init__.py", "src/langchain_ocr_lib/prompt_templates/ocr_prompt.py", "tests"]
63
63
  statistics = true
64
64
  show-source = false
65
65
  max-complexity = 8
@@ -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
- llm_instance = llm_provider(settings, ChatOllama)
54
+ partial_llm_provider = partial(llm_provider,settings, ChatOllama)
53
55
  elif llm_class_type_settings.llm_type == "openai":
54
56
  settings = OpenAISettings()
55
- llm_instance = llm_provider(settings, ChatOpenAI)
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
- binder.bind(LargeLanguageModelKey, llm_instance)
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, %s" % e)
52
-
53
- images = convert_from_bytes(file)
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
- images = convert_from_bytes(file)
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.
@@ -9,3 +9,4 @@ class LLMType(StrEnum):
9
9
 
10
10
  OLLAMA = "ollama"
11
11
  OPENAI = "openai"
12
+ VLLM = "vllm"
@@ -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
- vision_capable : bool
22
- Flag to enable a vision capable model.
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.7, description="What sampling temperature to use")
35
- vision_capable: bool = Field(default=False, description="Enable a vision capable model")
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
+ )