langchain-ocr-lib 0.2.0__tar.gz → 0.3.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.
Files changed (37) hide show
  1. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/PKG-INFO +3 -3
  2. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/README.md +2 -2
  3. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/pyproject.toml +2 -2
  4. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/di_config.py +4 -0
  5. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/impl/converter/pdf_converter.py +9 -4
  6. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/impl/llms/llm_type.py +1 -0
  7. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/impl/settings/openai_chat_settings.py +7 -4
  8. langchain_ocr_lib-0.3.0/src/langchain_ocr_lib/impl/settings/vllm_chat_settings.py +38 -0
  9. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/__init__.py +0 -0
  10. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/chains/__init__.py +0 -0
  11. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/chains/chain.py +0 -0
  12. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/converter/__init__.py +0 -0
  13. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/converter/converter.py +0 -0
  14. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/di_binding_keys/__init__.py +0 -0
  15. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/di_binding_keys/binding_keys.py +0 -0
  16. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/impl/__init__.py +0 -0
  17. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/impl/chains/__init__.py +0 -0
  18. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/impl/chains/ocr_chain.py +0 -0
  19. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/impl/converter/__init__.py +0 -0
  20. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/impl/converter/image_converter.py +0 -0
  21. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/impl/langfuse_manager/__init__.py +0 -0
  22. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/impl/langfuse_manager/langfuse_manager.py +0 -0
  23. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/impl/llms/__init__.py +0 -0
  24. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/impl/llms/llm_factory.py +0 -0
  25. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/impl/settings/__init__.py +0 -0
  26. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/impl/settings/langfuse_settings.py +0 -0
  27. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/impl/settings/language_settings.py +0 -0
  28. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/impl/settings/llm_class_type_settings.py +0 -0
  29. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/impl/settings/ollama_chat_settings.py +0 -0
  30. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/impl/tracers/__init__.py +0 -0
  31. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/impl/tracers/langfuse_traced_chain.py +0 -0
  32. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/language_mapping/language_mapping.py +0 -0
  33. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/main.py +0 -0
  34. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/prompt_templates/__init__.py +0 -0
  35. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/prompt_templates/ocr_prompt.py +0 -0
  36. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/tracers/__init__.py +0 -0
  37. {langchain_ocr_lib-0.2.0 → langchain_ocr_lib-0.3.0}/src/langchain_ocr_lib/tracers/traced_chain.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langchain-ocr-lib
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary:
5
5
  License: MIT
6
6
  Author: Andreas Klos
@@ -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
@@ -7,7 +7,7 @@ langchain-ocr = "langchain_ocr_lib.main:main"
7
7
 
8
8
  [tool.poetry]
9
9
  name = "langchain-ocr-lib"
10
- version = "0.2.0"
10
+ version = "0.3.0"
11
11
  description = ""
12
12
  authors = ["Andreas Klos <aklos@outlook.de>"]
13
13
  readme = "README.md"
@@ -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
@@ -17,6 +17,7 @@ from langfuse import Langfuse
17
17
 
18
18
  from langchain_ocr_lib.impl.chains.ocr_chain import OcrChain
19
19
  from langchain_ocr_lib.impl.settings.ollama_chat_settings import OllamaSettings
20
+ from langchain_ocr_lib.impl.settings.vllm_chat_settings import VllmSettings
20
21
  from langchain_ocr_lib.impl.settings.openai_chat_settings import OpenAISettings
21
22
  from langchain_ocr_lib.impl.settings.llm_class_type_settings import LlmClassTypeSettings
22
23
  from langchain_ocr_lib.impl.settings.langfuse_settings import LangfuseSettings
@@ -53,6 +54,9 @@ def lib_di_config(binder: Binder):
53
54
  elif llm_class_type_settings.llm_type == "openai":
54
55
  settings = OpenAISettings()
55
56
  llm_instance = llm_provider(settings, ChatOpenAI)
57
+ elif llm_class_type_settings.llm_type == "vllm":
58
+ settings = VllmSettings()
59
+ llm_instance = llm_provider(settings, ChatOpenAI)
56
60
  else:
57
61
  raise NotImplementedError("Configured LLM is not implemented")
58
62
  binder.bind(LargeLanguageModelKey, llm_instance)
@@ -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:
@@ -9,3 +9,4 @@ class LLMType(StrEnum):
9
9
 
10
10
  OLLAMA = "ollama"
11
11
  OPENAI = "openai"
12
+ VLLM = "vllm"
@@ -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:
@@ -31,5 +31,8 @@ class OpenAISettings(BaseSettings):
31
31
  model: str = Field(default="gpt-4o-mini-search-preview-2025-03-11", description="The model identifier")
32
32
  api_key: str = Field(default="", description="The API key for authentication")
33
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")
34
+ temperature: float = Field(default=0, description="What sampling temperature to use")
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")
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, description="What sampling temperature to use")
35
+ base_url: str = Field(
36
+ default="http://localhost:8000/v1",
37
+ description="The base URL for the Vllm API endpoint",
38
+ )