langchain-ocr-lib 0.3.2__py3-none-any.whl → 0.4.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.
@@ -13,11 +13,13 @@ from langchain_ocr_lib.di_binding_keys.binding_keys import (
13
13
  )
14
14
  from langchain_ollama import ChatOllama
15
15
  from langchain_openai import ChatOpenAI
16
+ from langchain_together import ChatTogether
16
17
  from langfuse import Langfuse
17
18
  from functools import partial
18
19
 
19
20
  from langchain_ocr_lib.impl.chains.ocr_chain import OcrChain
20
21
  from langchain_ocr_lib.impl.settings.ollama_chat_settings import OllamaSettings
22
+ from langchain_ocr_lib.impl.settings.together_ai_chat_settings import TogetherAISettings
21
23
  from langchain_ocr_lib.impl.settings.vllm_chat_settings import VllmSettings
22
24
  from langchain_ocr_lib.impl.settings.openai_chat_settings import OpenAISettings
23
25
  from langchain_ocr_lib.impl.settings.llm_class_type_settings import LlmClassTypeSettings
@@ -48,22 +50,29 @@ def lib_di_config(binder: Binder):
48
50
  langfuse_settings = LangfuseSettings()
49
51
  llm_class_type_settings = LlmClassTypeSettings()
50
52
  language_settings = LanguageSettings()
51
-
53
+ model_name = ""
52
54
  if llm_class_type_settings.llm_type == "ollama":
53
55
  settings = OllamaSettings()
54
- partial_llm_provider = partial(llm_provider,settings, ChatOllama)
56
+ model_name = settings.model
57
+ partial_llm_provider = partial(llm_provider, settings, ChatOllama)
55
58
  elif llm_class_type_settings.llm_type == "openai":
56
59
  settings = OpenAISettings()
57
- partial_llm_provider = partial(llm_provider,settings, ChatOpenAI)
60
+ model_name = settings.model_name
61
+ partial_llm_provider = partial(llm_provider, settings, ChatOpenAI)
58
62
  elif llm_class_type_settings.llm_type == "vllm":
59
63
  settings = VllmSettings()
60
- partial_llm_provider = partial(llm_provider,settings, ChatOpenAI)
64
+ model_name = settings.model_name
65
+ partial_llm_provider = partial(llm_provider, settings, ChatOpenAI)
66
+ elif llm_class_type_settings.llm_type == "together-ai":
67
+ settings = TogetherAISettings()
68
+ model_name = settings.model_name
69
+ partial_llm_provider = partial(llm_provider, settings, ChatTogether)
61
70
  else:
62
71
  raise NotImplementedError("Configured LLM is not implemented")
63
-
72
+
64
73
  binder.bind_to_provider(LargeLanguageModelKey, partial_llm_provider)
65
74
 
66
- prompt = ocr_prompt_template_builder(language=language_settings.language, model_name=settings.model)
75
+ prompt = ocr_prompt_template_builder(language=language_settings.language, model_name=model_name)
67
76
 
68
77
  binder.bind(
69
78
  LangfuseClientKey,
@@ -58,9 +58,10 @@ class LangfuseManager:
58
58
  Exception
59
59
  If an error occurs while retrieving the prompt template from Langfuse.
60
60
  """
61
+ langfuse_prompt = None
61
62
  if not self._enabled:
62
63
  logger.info("Langfuse is not enabled. Using fallback prompt.")
63
- return None
64
+ return langfuse_prompt
64
65
  try:
65
66
  langfuse_prompt = self._langfuse.get_prompt(base_prompt_name)
66
67
  except NotFoundError:
@@ -43,6 +43,7 @@ def get_configurable_fields_from(settings: BaseSettings) -> dict[str, Configurab
43
43
  settings_of_interest = settings.model_fields[field_name]
44
44
  if settings_of_interest.title is not None:
45
45
  _fields[field_name] = ConfigurableField(id=field_name, name=settings_of_interest.title)
46
+
46
47
  return _fields
47
48
 
48
49
 
@@ -10,3 +10,4 @@ class LLMType(StrEnum):
10
10
  OLLAMA = "ollama"
11
11
  OPENAI = "openai"
12
12
  VLLM = "vllm"
13
+ TOGETHER_AI = "together-ai"
@@ -10,7 +10,7 @@ class OpenAISettings(BaseSettings):
10
10
 
11
11
  Attributes
12
12
  ----------
13
- model : str
13
+ model_name : str
14
14
  The model identifier.
15
15
  api_key : str
16
16
  The API key for authentication.
@@ -28,9 +28,16 @@ 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", title="LLM Model")
31
+ model_name: str = Field(
32
+ default="gpt-4o-mini-search-preview-2025-03-11",
33
+ env="MODEL",
34
+ description="The model identifier",
35
+ title="LLM Model",
36
+ )
32
37
  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")
38
+ top_p: float = Field(
39
+ default=1.0, description="Total probability mass of tokens to consider at each step", title="Top P"
40
+ )
34
41
  temperature: float = Field(default=0, description="What sampling temperature to use", title="Temperature")
35
42
  base_url: str = Field(
36
43
  default="https://api.openai.com/v1",
@@ -0,0 +1,45 @@
1
+ """Module contains settings regarding the Together AI API."""
2
+
3
+ from pydantic import Field
4
+ from pydantic_settings import BaseSettings
5
+
6
+
7
+ class TogetherAISettings(BaseSettings):
8
+ """
9
+ Contains settings regarding the Together AI API.
10
+
11
+ Attributes
12
+ ----------
13
+ model_name : str
14
+ The Together AI model identifier.
15
+ together_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
+ together_api_base : str
22
+ The base URL for the Together AI API endpoint.
23
+ """
24
+
25
+ class Config:
26
+ """Config class for reading fields from environment variables."""
27
+
28
+ env_prefix = "TOGETHER_"
29
+ case_sensitive = False
30
+
31
+ model_name: str = Field(
32
+ default="",
33
+ description="The Together AI model identifier",
34
+ title="Together AI Model",
35
+ )
36
+ together_api_key: str = Field(default="", description="The API key for authentication")
37
+ top_p: float = Field(
38
+ default=1.0, description="Total probability mass of tokens to consider at each step", title="Top P"
39
+ )
40
+ temperature: float = Field(default=0, description="What sampling temperature to use", title="Temperature")
41
+ together_api_base: str = Field(
42
+ default="https://api.together.xyz/v1/",
43
+ env="API_BASE",
44
+ description="The base URL for the Together AI API endpoint",
45
+ )
@@ -10,7 +10,7 @@ class VllmSettings(BaseSettings):
10
10
 
11
11
  Attributes
12
12
  ----------
13
- model : str
13
+ model_name : str
14
14
  The model identifier.
15
15
  api_key : str
16
16
  The API key for authentication.
@@ -28,9 +28,16 @@ class VllmSettings(BaseSettings):
28
28
  env_prefix = "VLLM_"
29
29
  case_sensitive = False
30
30
 
31
- model: str = Field(default="", description="The model identifier", title="LLM Model")
31
+ model_name: str = Field(
32
+ default="",
33
+ env="MODEL",
34
+ description="The model identifier",
35
+ title="LLM Model",
36
+ )
32
37
  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")
38
+ top_p: float = Field(
39
+ default=1.0, description="Total probability mass of tokens to consider at each step", title="Top P"
40
+ )
34
41
  temperature: float = Field(default=0, description="What sampling temperature to use", title="Temperature")
35
42
  base_url: str = Field(
36
43
  default="http://localhost:8000/v1",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: langchain-ocr-lib
3
- Version: 0.3.2
3
+ Version: 0.4.0
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
@@ -16,6 +16,7 @@ Requires-Dist: inject (>=5.2.1,<6.0.0)
16
16
  Requires-Dist: langchain-community (>=0.3.19,<0.4.0)
17
17
  Requires-Dist: langchain-ollama (>=0.2.0,<0.3.0)
18
18
  Requires-Dist: langchain-openai (>=0.3.8,<0.4.0)
19
+ Requires-Dist: langchain-together (>=0.3.0,<0.4.0)
19
20
  Requires-Dist: langfuse (>=2.59.7,<3.0.0)
20
21
  Requires-Dist: openai (>=1.42.0,<2.0.0)
21
22
  Requires-Dist: pdf2image (>=1.17.0,<2.0.0)
@@ -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=LvRnptts1VCDa3HVP7jtBtQTyG-QEErbyplGX86uaUA,3802
8
+ langchain_ocr_lib/di_config.py,sha256=AhSZoYeaX6-sjfnM5J3N3ECAitQV5KFBvU0vAAu6dbQ,4285
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,17 +13,18 @@ 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=C2waQ1Mvqz6bECXAcaMiBsE8TLc2kLr5QUIgXqgH_cE,5311
16
+ langchain_ocr_lib/impl/langfuse_manager/langfuse_manager.py,sha256=6kvPfYObLmbYZAvtYNx7g9xz5wYz0PxohEzyctpGRto,5353
17
17
  langchain_ocr_lib/impl/llms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
- langchain_ocr_lib/impl/llms/llm_factory.py,sha256=9DsUdoYNrjeWLGA9ISDdHN2cxcQ7DquNQ5it6zSxHlg,2199
19
- langchain_ocr_lib/impl/llms/llm_type.py,sha256=_LKtdVuTRYX6gupkxJtEtIwrbtiMvZmG8WOxfzlm42M,286
18
+ langchain_ocr_lib/impl/llms/llm_factory.py,sha256=pYPwUowm8r42BwOn4W1j4-cEpL9LCCkZU_pJ4xQhshU,2200
19
+ langchain_ocr_lib/impl/llms/llm_type.py,sha256=tNyvUbgIMW7t2-lMEVo-4GyB2hk5Jw9kOaUbVtAK2LA,318
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=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
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
25
+ langchain_ocr_lib/impl/settings/openai_chat_settings.py,sha256=5OnHo8a2iRsEvohn09Lf30MNFgS1GWVvOa5kyUusHCQ,1407
26
+ langchain_ocr_lib/impl/settings/together_ai_chat_settings.py,sha256=Jr2dHPpa1VTKwbrCLrjxkHCkWv1-iY1w0DQoklD9SB8,1470
27
+ langchain_ocr_lib/impl/settings/vllm_chat_settings.py,sha256=ZnijdQBSxHh6cGcU5uYth9LHpYYQyIF0XPbsTMh1Fxk,1357
27
28
  langchain_ocr_lib/impl/tracers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
29
  langchain_ocr_lib/impl/tracers/langfuse_traced_chain.py,sha256=syjwNt8HfVmaWXZ-ElFYsc-KwpnKQz2LE3K5jV7c3GE,1599
29
30
  langchain_ocr_lib/language_mapping/language_mapping.py,sha256=VY7WkkZauoHNxkvgUYbig0rDmlKqDkz24cXMd6A7txM,700
@@ -32,7 +33,7 @@ langchain_ocr_lib/prompt_templates/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQe
32
33
  langchain_ocr_lib/prompt_templates/ocr_prompt.py,sha256=3Be1AL-HJkxPnAP0DNH1MqvAxFWTCeM5UOKP63xkHsY,3543
33
34
  langchain_ocr_lib/tracers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
35
  langchain_ocr_lib/tracers/traced_chain.py,sha256=uxRkdLNn_G6dAsti_gUuF7muhIj10xrOUL7HUga40oc,3056
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,,
36
+ langchain_ocr_lib-0.4.0.dist-info/METADATA,sha256=x5QI_KtLLjUwDbY1FO3olk1wT6K7uufa3sVCOcTYXRQ,6491
37
+ langchain_ocr_lib-0.4.0.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
38
+ langchain_ocr_lib-0.4.0.dist-info/entry_points.txt,sha256=l4mIs0tnIgbJYuVveZySQKVBnqNMHS-8ZZtLwz8ag5k,61
39
+ langchain_ocr_lib-0.4.0.dist-info/RECORD,,