langchain-ocr-lib 0.2.0__py3-none-any.whl → 0.3.0__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.
@@ -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
+ )
@@ -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
@@ -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=m6ZYs5dNtAKFGVmyR8uTLOlFX3l71EI4cMkNL6asxME,3316
8
+ langchain_ocr_lib/di_config.py,sha256=eYzDi_LJaYY_JhRnNqW3VYGd3N1QblaGFjWlL_6Vx9c,3537
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=ssj8DL_9wf6kMhjUhDkw0gwSwNLrvgh8nBRspwj60Vk,3510
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
16
  langchain_ocr_lib/impl/langfuse_manager/langfuse_manager.py,sha256=AEF1iFYghr-62gcPcUb4Yi3DNRYfe-JsIWd3ymsIU8I,5403
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=_Ap7yStlBn0tyOyfVLH1c2j2A9-ccsTCxAm7bgoRQnM,268
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
24
  langchain_ocr_lib/impl/settings/ollama_chat_settings.py,sha256=8RWMsaK4qDrqC6Mrxekr8IEDYwcvjYwhw9xDwZemxI4,1506
25
- langchain_ocr_lib/impl/settings/openai_chat_settings.py,sha256=cXzxe-sea8VCK2M_u9ZIL4l8AR_YdhmA-phZa9fwf8o,1233
25
+ langchain_ocr_lib/impl/settings/openai_chat_settings.py,sha256=gZqmFYDtF0l5lEAnuT2VzdqLWKnTPSK_lTeg7ERmJas,1276
26
+ langchain_ocr_lib/impl/settings/vllm_chat_settings.py,sha256=y8PPNUcce1uA4kEu6p0p5vCwCOGp9uEEvHbCoS1Ohh8,1226
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.2.0.dist-info/METADATA,sha256=ATjGYYdjA2U-TmsoUrXP_5aglABNsQybWT2_JL_zd8U,6113
35
- langchain_ocr_lib-0.2.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
36
- langchain_ocr_lib-0.2.0.dist-info/entry_points.txt,sha256=l4mIs0tnIgbJYuVveZySQKVBnqNMHS-8ZZtLwz8ag5k,61
37
- langchain_ocr_lib-0.2.0.dist-info/RECORD,,
35
+ langchain_ocr_lib-0.3.0.dist-info/METADATA,sha256=IaqIz9OXgu5WQXwEVpLmMNLmz2w3IowWmdZ7kt5O6VM,6240
36
+ langchain_ocr_lib-0.3.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
37
+ langchain_ocr_lib-0.3.0.dist-info/entry_points.txt,sha256=l4mIs0tnIgbJYuVveZySQKVBnqNMHS-8ZZtLwz8ag5k,61
38
+ langchain_ocr_lib-0.3.0.dist-info/RECORD,,