langchain-ollama 0.1.2__tar.gz → 0.2.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.
@@ -1,17 +1,17 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langchain-ollama
3
- Version: 0.1.2
3
+ Version: 0.2.0
4
4
  Summary: An integration package connecting Ollama and LangChain
5
5
  Home-page: https://github.com/langchain-ai/langchain
6
6
  License: MIT
7
- Requires-Python: >=3.8.1,<4.0
7
+ Requires-Python: >=3.9,<4.0
8
8
  Classifier: License :: OSI Approved :: MIT License
9
9
  Classifier: Programming Language :: Python :: 3
10
10
  Classifier: Programming Language :: Python :: 3.9
11
11
  Classifier: Programming Language :: Python :: 3.10
12
12
  Classifier: Programming Language :: Python :: 3.11
13
13
  Classifier: Programming Language :: Python :: 3.12
14
- Requires-Dist: langchain-core (==0.2.36)
14
+ Requires-Dist: langchain-core (>=0.3.0,<0.4.0)
15
15
  Requires-Dist: ollama (>=0.3.0,<1)
16
16
  Project-URL: Repository, https://github.com/langchain-ai/langchain
17
17
  Project-URL: Release Notes, https://github.com/langchain-ai/langchain/releases?q=tag%3A%22langchain-ollama%3D%3D0%22&expanded=true
@@ -35,11 +35,12 @@ from langchain_core.messages import (
35
35
  from langchain_core.messages.ai import UsageMetadata
36
36
  from langchain_core.messages.tool import tool_call
37
37
  from langchain_core.outputs import ChatGeneration, ChatGenerationChunk, ChatResult
38
- from langchain_core.pydantic_v1 import Field, root_validator
39
38
  from langchain_core.runnables import Runnable
40
39
  from langchain_core.tools import BaseTool
41
40
  from langchain_core.utils.function_calling import convert_to_openai_tool
42
41
  from ollama import AsyncClient, Client, Message, Options
42
+ from pydantic import PrivateAttr, model_validator
43
+ from typing_extensions import Self
43
44
 
44
45
 
45
46
  def _get_usage_metadata_from_generation_info(
@@ -91,7 +92,9 @@ def _lc_tool_call_to_openai_tool_call(tool_call: ToolCall) -> dict:
91
92
  class ChatOllama(BaseChatModel):
92
93
  """Ollama chat model integration.
93
94
 
94
- Setup:
95
+ .. dropdown:: Setup
96
+ :open:
97
+
95
98
  Install ``langchain-ollama`` and download any models you want to use from ollama.
96
99
 
97
100
  .. code-block:: bash
@@ -225,7 +228,7 @@ class ChatOllama(BaseChatModel):
225
228
  .. code-block:: python
226
229
 
227
230
  from langchain_ollama import ChatOllama
228
- from langchain_core.pydantic_v1 import BaseModel, Field
231
+ from pydantic import BaseModel, Field
229
232
 
230
233
  class Multiply(BaseModel):
231
234
  a: int = Field(..., description="First integer")
@@ -328,12 +331,12 @@ class ChatOllama(BaseChatModel):
328
331
  For a full list of the params, see [this link](https://pydoc.dev/httpx/latest/httpx.Client.html)
329
332
  """
330
333
 
331
- _client: Client = Field(default=None)
334
+ _client: Client = PrivateAttr(default=None)
332
335
  """
333
336
  The client to use for making requests.
334
337
  """
335
338
 
336
- _async_client: AsyncClient = Field(default=None)
339
+ _async_client: AsyncClient = PrivateAttr(default=None)
337
340
  """
338
341
  The async client to use for making requests.
339
342
  """
@@ -364,14 +367,13 @@ class ChatOllama(BaseChatModel):
364
367
  "keep_alive": self.keep_alive,
365
368
  }
366
369
 
367
- @root_validator(pre=False, skip_on_failure=True)
368
- def _set_clients(cls, values: dict) -> dict:
370
+ @model_validator(mode="after")
371
+ def _set_clients(self) -> Self:
369
372
  """Set clients to use for ollama."""
370
- values["_client"] = Client(host=values["base_url"], **values["client_kwargs"])
371
- values["_async_client"] = AsyncClient(
372
- host=values["base_url"], **values["client_kwargs"]
373
- )
374
- return values
373
+ client_kwargs = self.client_kwargs or {}
374
+ self._client = Client(host=self.base_url, **client_kwargs)
375
+ self._async_client = AsyncClient(host=self.base_url, **client_kwargs)
376
+ return self
375
377
 
376
378
  def _convert_messages_to_ollama_messages(
377
379
  self, messages: List[BaseMessage]
@@ -4,8 +4,14 @@ from typing import (
4
4
  )
5
5
 
6
6
  from langchain_core.embeddings import Embeddings
7
- from langchain_core.pydantic_v1 import BaseModel, Field, root_validator
8
7
  from ollama import AsyncClient, Client
8
+ from pydantic import (
9
+ BaseModel,
10
+ ConfigDict,
11
+ PrivateAttr,
12
+ model_validator,
13
+ )
14
+ from typing_extensions import Self
9
15
 
10
16
 
11
17
  class OllamaEmbeddings(BaseModel, Embeddings):
@@ -126,29 +132,27 @@ class OllamaEmbeddings(BaseModel, Embeddings):
126
132
  For a full list of the params, see [this link](https://pydoc.dev/httpx/latest/httpx.Client.html)
127
133
  """
128
134
 
129
- _client: Client = Field(default=None)
135
+ _client: Client = PrivateAttr(default=None)
130
136
  """
131
137
  The client to use for making requests.
132
138
  """
133
139
 
134
- _async_client: AsyncClient = Field(default=None)
140
+ _async_client: AsyncClient = PrivateAttr(default=None)
135
141
  """
136
142
  The async client to use for making requests.
137
143
  """
138
144
 
139
- class Config:
140
- """Configuration for this pydantic object."""
141
-
142
- extra = "forbid"
145
+ model_config = ConfigDict(
146
+ extra="forbid",
147
+ )
143
148
 
144
- @root_validator(pre=False, skip_on_failure=True)
145
- def _set_clients(cls, values: dict) -> dict:
149
+ @model_validator(mode="after")
150
+ def _set_clients(self) -> Self:
146
151
  """Set clients to use for ollama."""
147
- values["_client"] = Client(host=values["base_url"], **values["client_kwargs"])
148
- values["_async_client"] = AsyncClient(
149
- host=values["base_url"], **values["client_kwargs"]
150
- )
151
- return values
152
+ client_kwargs = self.client_kwargs or {}
153
+ self._client = Client(host=self.base_url, **client_kwargs)
154
+ self._async_client = AsyncClient(host=self.base_url, **client_kwargs)
155
+ return self
152
156
 
153
157
  def embed_documents(self, texts: List[str]) -> List[List[float]]:
154
158
  """Embed search docs."""
@@ -18,8 +18,9 @@ from langchain_core.callbacks import (
18
18
  )
19
19
  from langchain_core.language_models import BaseLLM, LangSmithParams
20
20
  from langchain_core.outputs import GenerationChunk, LLMResult
21
- from langchain_core.pydantic_v1 import Field, root_validator
22
21
  from ollama import AsyncClient, Client, Options
22
+ from pydantic import PrivateAttr, model_validator
23
+ from typing_extensions import Self
23
24
 
24
25
 
25
26
  class OllamaLLM(BaseLLM):
@@ -115,12 +116,12 @@ class OllamaLLM(BaseLLM):
115
116
  For a full list of the params, see [this link](https://pydoc.dev/httpx/latest/httpx.Client.html)
116
117
  """
117
118
 
118
- _client: Client = Field(default=None)
119
+ _client: Client = PrivateAttr(default=None)
119
120
  """
120
121
  The client to use for making requests.
121
122
  """
122
123
 
123
- _async_client: AsyncClient = Field(default=None)
124
+ _async_client: AsyncClient = PrivateAttr(default=None)
124
125
  """
125
126
  The async client to use for making requests.
126
127
  """
@@ -164,14 +165,13 @@ class OllamaLLM(BaseLLM):
164
165
  params["ls_max_tokens"] = max_tokens
165
166
  return params
166
167
 
167
- @root_validator(pre=False, skip_on_failure=True)
168
- def _set_clients(cls, values: dict) -> dict:
168
+ @model_validator(mode="after")
169
+ def _set_clients(self) -> Self:
169
170
  """Set clients to use for ollama."""
170
- values["_client"] = Client(host=values["base_url"], **values["client_kwargs"])
171
- values["_async_client"] = AsyncClient(
172
- host=values["base_url"], **values["client_kwargs"]
173
- )
174
- return values
171
+ client_kwargs = self.client_kwargs or {}
172
+ self._client = Client(host=self.base_url, **client_kwargs)
173
+ self._async_client = AsyncClient(host=self.base_url, **client_kwargs)
174
+ return self
175
175
 
176
176
  async def _acreate_generate_stream(
177
177
  self,
@@ -1,91 +1,86 @@
1
+ [build-system]
2
+ requires = ["poetry-core>=1.0.0"]
3
+ build-backend = "poetry.core.masonry.api"
4
+
1
5
  [tool.poetry]
2
6
  name = "langchain-ollama"
3
- version = "0.1.2"
7
+ version = "0.2.0"
4
8
  description = "An integration package connecting Ollama and LangChain"
5
9
  authors = []
6
10
  readme = "README.md"
7
11
  repository = "https://github.com/langchain-ai/langchain"
8
12
  license = "MIT"
9
13
 
14
+ [tool.mypy]
15
+ disallow_untyped_defs = "True"
16
+
10
17
  [tool.poetry.urls]
11
18
  "Source Code" = "https://github.com/langchain-ai/langchain/tree/master/libs/partners/ollama"
12
19
  "Release Notes" = "https://github.com/langchain-ai/langchain/releases?q=tag%3A%22langchain-ollama%3D%3D0%22&expanded=true"
13
20
 
14
21
  [tool.poetry.dependencies]
15
- python = ">=3.8.1,<4.0"
22
+ python = ">=3.9,<4.0"
16
23
  ollama = ">=0.3.0,<1"
17
- langchain-core = "0.2.36"
24
+ langchain-core = "^0.3.0"
25
+
26
+ [tool.ruff.lint]
27
+ select = ["E", "F", "I", "T201"]
28
+
29
+ [tool.coverage.run]
30
+ omit = ["tests/*"]
31
+
32
+ [tool.pytest.ini_options]
33
+ addopts = "--snapshot-warn-unused --strict-markers --strict-config --durations=5"
34
+ markers = [
35
+ "compile: mark placeholder test used to compile integration tests without running them",
36
+ ]
37
+ asyncio_mode = "auto"
18
38
 
19
39
  [tool.poetry.group.test]
20
40
  optional = true
21
41
 
42
+ [tool.poetry.group.codespell]
43
+ optional = true
44
+
45
+ [tool.poetry.group.test_integration]
46
+ optional = true
47
+
48
+ [tool.poetry.group.lint]
49
+ optional = true
50
+
51
+ [tool.poetry.group.dev]
52
+ optional = true
53
+
22
54
  [tool.poetry.group.test.dependencies]
23
55
  pytest = "^7.4.3"
24
56
  pytest-asyncio = "^0.23.2"
25
57
  syrupy = "^4.0.2"
26
58
  pytest-socket = "^0.7.0"
27
- langchain-core = { path = "../../core", develop = true }
28
- langchain-standard-tests = { path = "../../standard-tests", develop = true }
29
-
30
- [tool.poetry.group.codespell]
31
- optional = true
59
+ pytest-watcher = "^0.3.4"
32
60
 
33
61
  [tool.poetry.group.codespell.dependencies]
34
62
  codespell = "^2.2.6"
35
63
 
36
- [tool.poetry.group.test_integration]
37
- optional = true
38
-
39
64
  [tool.poetry.group.test_integration.dependencies]
40
65
 
41
- [tool.poetry.group.lint]
42
- optional = true
43
-
44
66
  [tool.poetry.group.lint.dependencies]
45
67
  ruff = "^0.1.8"
46
68
 
47
69
  [tool.poetry.group.typing.dependencies]
48
70
  mypy = "^1.7.1"
49
- langchain-core = { path = "../../core", develop = true }
50
71
 
51
- [tool.poetry.group.dev]
52
- optional = true
72
+ [tool.poetry.group.test.dependencies.langchain-core]
73
+ path = "../../core"
74
+ develop = true
53
75
 
54
- [tool.poetry.group.dev.dependencies]
55
- langchain-core = { path = "../../core", develop = true }
76
+ [tool.poetry.group.test.dependencies.langchain-standard-tests]
77
+ path = "../../standard-tests"
78
+ develop = true
56
79
 
57
- [tool.ruff.lint]
58
- select = [
59
- "E", # pycodestyle
60
- "F", # pyflakes
61
- "I", # isort
62
- "T201", # print
63
- ]
80
+ [tool.poetry.group.typing.dependencies.langchain-core]
81
+ path = "../../core"
82
+ develop = true
64
83
 
65
- [tool.mypy]
66
- disallow_untyped_defs = "True"
67
-
68
- [tool.coverage.run]
69
- omit = ["tests/*"]
70
-
71
- [build-system]
72
- requires = ["poetry-core>=1.0.0"]
73
- build-backend = "poetry.core.masonry.api"
74
-
75
- [tool.pytest.ini_options]
76
- # --strict-markers will raise errors on unknown marks.
77
- # https://docs.pytest.org/en/7.1.x/how-to/mark.html#raising-errors-on-unknown-marks
78
- #
79
- # https://docs.pytest.org/en/7.1.x/reference/reference.html
80
- # --strict-config any warnings encountered while parsing the `pytest`
81
- # section of the configuration file raise errors.
82
- #
83
- # https://github.com/tophat/syrupy
84
- # --snapshot-warn-unused Prints a warning on unused snapshots rather than fail the test suite.
85
- addopts = "--snapshot-warn-unused --strict-markers --strict-config --durations=5"
86
- # Registering custom markers.
87
- # https://docs.pytest.org/en/7.1.x/example/markers.html#registering-markers
88
- markers = [
89
- "compile: mark placeholder test used to compile integration tests without running them",
90
- ]
91
- asyncio_mode = "auto"
84
+ [tool.poetry.group.dev.dependencies.langchain-core]
85
+ path = "../../core"
86
+ develop = true