langchain-ollama 0.3.2__py3-none-any.whl → 0.3.3__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.
@@ -26,6 +26,7 @@ from langchain_core.messages import (
26
26
  AIMessageChunk,
27
27
  BaseMessage,
28
28
  BaseMessageChunk,
29
+ ChatMessage,
29
30
  HumanMessage,
30
31
  SystemMessage,
31
32
  ToolCall,
@@ -435,8 +436,22 @@ class ChatOllama(BaseChatModel):
435
436
  """Base url the model is hosted under."""
436
437
 
437
438
  client_kwargs: Optional[dict] = {}
438
- """Additional kwargs to pass to the httpx Client.
439
- For a full list of the params, see [this link](https://pydoc.dev/httpx/latest/httpx.Client.html)
439
+ """Additional kwargs to pass to the httpx clients.
440
+ These arguments are passed to both synchronous and async clients.
441
+ Use sync_client_kwargs and async_client_kwargs to pass different arguments
442
+ to synchronous and asynchronous clients.
443
+ """
444
+
445
+ async_client_kwargs: Optional[dict] = {}
446
+ """Additional kwargs to merge with client_kwargs before
447
+ passing to the httpx AsyncClient.
448
+ For a full list of the params, see [this link](https://www.python-httpx.org/api/#asyncclient)
449
+ """
450
+
451
+ sync_client_kwargs: Optional[dict] = {}
452
+ """Additional kwargs to merge with client_kwargs before
453
+ passing to the httpx Client.
454
+ For a full list of the params, see [this link](https://www.python-httpx.org/api/#client)
440
455
  """
441
456
 
442
457
  _client: Client = PrivateAttr(default=None) # type: ignore
@@ -502,8 +517,17 @@ class ChatOllama(BaseChatModel):
502
517
  def _set_clients(self) -> Self:
503
518
  """Set clients to use for ollama."""
504
519
  client_kwargs = self.client_kwargs or {}
505
- self._client = Client(host=self.base_url, **client_kwargs)
506
- self._async_client = AsyncClient(host=self.base_url, **client_kwargs)
520
+
521
+ sync_client_kwargs = client_kwargs
522
+ if self.sync_client_kwargs:
523
+ sync_client_kwargs = {**sync_client_kwargs, **self.sync_client_kwargs}
524
+
525
+ async_client_kwargs = client_kwargs
526
+ if self.async_client_kwargs:
527
+ async_client_kwargs = {**async_client_kwargs, **self.async_client_kwargs}
528
+
529
+ self._client = Client(host=self.base_url, **sync_client_kwargs)
530
+ self._async_client = AsyncClient(host=self.base_url, **async_client_kwargs)
507
531
  return self
508
532
 
509
533
  def _convert_messages_to_ollama_messages(
@@ -511,7 +535,7 @@ class ChatOllama(BaseChatModel):
511
535
  ) -> Sequence[Message]:
512
536
  ollama_messages: list = []
513
537
  for message in messages:
514
- role: Literal["user", "assistant", "system", "tool"]
538
+ role: str
515
539
  tool_call_id: Optional[str] = None
516
540
  tool_calls: Optional[list[dict[str, Any]]] = None
517
541
  if isinstance(message, HumanMessage):
@@ -528,6 +552,8 @@ class ChatOllama(BaseChatModel):
528
552
  )
529
553
  elif isinstance(message, SystemMessage):
530
554
  role = "system"
555
+ elif isinstance(message, ChatMessage):
556
+ role = message.role
531
557
  elif isinstance(message, ToolMessage):
532
558
  role = "tool"
533
559
  tool_call_id = message.tool_call_id
@@ -127,8 +127,22 @@ class OllamaEmbeddings(BaseModel, Embeddings):
127
127
  """Base url the model is hosted under."""
128
128
 
129
129
  client_kwargs: Optional[dict] = {}
130
- """Additional kwargs to pass to the httpx Client.
131
- For a full list of the params, see [this link](https://pydoc.dev/httpx/latest/httpx.Client.html)
130
+ """Additional kwargs to pass to the httpx clients.
131
+ These arguments are passed to both synchronous and async clients.
132
+ Use sync_client_kwargs and async_client_kwargs to pass different arguments
133
+ to synchronous and asynchronous clients.
134
+ """
135
+
136
+ async_client_kwargs: Optional[dict] = {}
137
+ """Additional kwargs to merge with client_kwargs before
138
+ passing to the httpx AsyncClient.
139
+ For a full list of the params, see [this link](https://www.python-httpx.org/api/#asyncclient)
140
+ """
141
+
142
+ sync_client_kwargs: Optional[dict] = {}
143
+ """Additional kwargs to merge with client_kwargs before
144
+ passing to the httpx Client.
145
+ For a full list of the params, see [this link](https://www.python-httpx.org/api/#client)
132
146
  """
133
147
 
134
148
  _client: Client = PrivateAttr(default=None) # type: ignore
@@ -233,8 +247,17 @@ class OllamaEmbeddings(BaseModel, Embeddings):
233
247
  def _set_clients(self) -> Self:
234
248
  """Set clients to use for ollama."""
235
249
  client_kwargs = self.client_kwargs or {}
236
- self._client = Client(host=self.base_url, **client_kwargs)
237
- self._async_client = AsyncClient(host=self.base_url, **client_kwargs)
250
+
251
+ sync_client_kwargs = client_kwargs
252
+ if self.sync_client_kwargs:
253
+ sync_client_kwargs = {**sync_client_kwargs, **self.sync_client_kwargs}
254
+
255
+ async_client_kwargs = client_kwargs
256
+ if self.async_client_kwargs:
257
+ async_client_kwargs = {**async_client_kwargs, **self.async_client_kwargs}
258
+
259
+ self._client = Client(host=self.base_url, **sync_client_kwargs)
260
+ self._async_client = AsyncClient(host=self.base_url, **async_client_kwargs)
238
261
  return self
239
262
 
240
263
  def embed_documents(self, texts: list[str]) -> list[list[float]]:
langchain_ollama/llms.py CHANGED
@@ -113,8 +113,22 @@ class OllamaLLM(BaseLLM):
113
113
  """Base url the model is hosted under."""
114
114
 
115
115
  client_kwargs: Optional[dict] = {}
116
- """Additional kwargs to pass to the httpx Client.
117
- For a full list of the params, see [this link](https://pydoc.dev/httpx/latest/httpx.Client.html)
116
+ """Additional kwargs to pass to the httpx clients.
117
+ These arguments are passed to both synchronous and async clients.
118
+ Use sync_client_kwargs and async_client_kwargs to pass different arguments
119
+ to synchronous and asynchronous clients.
120
+ """
121
+
122
+ async_client_kwargs: Optional[dict] = {}
123
+ """Additional kwargs to merge with client_kwargs before
124
+ passing to the httpx AsyncClient.
125
+ For a full list of the params, see [this link](https://www.python-httpx.org/api/#asyncclient)
126
+ """
127
+
128
+ sync_client_kwargs: Optional[dict] = {}
129
+ """Additional kwargs to merge with client_kwargs before
130
+ passing to the httpx Client.
131
+ For a full list of the params, see [this link](https://www.python-httpx.org/api/#client)
118
132
  """
119
133
 
120
134
  _client: Client = PrivateAttr(default=None) # type: ignore
@@ -189,8 +203,17 @@ class OllamaLLM(BaseLLM):
189
203
  def _set_clients(self) -> Self:
190
204
  """Set clients to use for ollama."""
191
205
  client_kwargs = self.client_kwargs or {}
192
- self._client = Client(host=self.base_url, **client_kwargs)
193
- self._async_client = AsyncClient(host=self.base_url, **client_kwargs)
206
+
207
+ sync_client_kwargs = client_kwargs
208
+ if self.sync_client_kwargs:
209
+ sync_client_kwargs = {**sync_client_kwargs, **self.sync_client_kwargs}
210
+
211
+ async_client_kwargs = client_kwargs
212
+ if self.async_client_kwargs:
213
+ async_client_kwargs = {**async_client_kwargs, **self.async_client_kwargs}
214
+
215
+ self._client = Client(host=self.base_url, **sync_client_kwargs)
216
+ self._async_client = AsyncClient(host=self.base_url, **async_client_kwargs)
194
217
  return self
195
218
 
196
219
  async def _acreate_generate_stream(
@@ -1,14 +1,14 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langchain-ollama
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: An integration package connecting Ollama and LangChain
5
5
  License: MIT
6
6
  Project-URL: Source Code, https://github.com/langchain-ai/langchain/tree/master/libs/partners/ollama
7
7
  Project-URL: Release Notes, https://github.com/langchain-ai/langchain/releases?q=tag%3A%22langchain-ollama%3D%3D0%22&expanded=true
8
8
  Project-URL: repository, https://github.com/langchain-ai/langchain
9
- Requires-Python: <4.0,>=3.9
10
- Requires-Dist: ollama<1,>=0.4.4
11
- Requires-Dist: langchain-core<1.0.0,>=0.3.52
9
+ Requires-Python: >=3.9
10
+ Requires-Dist: ollama<1.0.0,>=0.4.8
11
+ Requires-Dist: langchain-core<1.0.0,>=0.3.60
12
12
  Description-Content-Type: text/markdown
13
13
 
14
14
  # langchain-ollama
@@ -0,0 +1,10 @@
1
+ langchain_ollama-0.3.3.dist-info/METADATA,sha256=K2QhMD3eEMIMegVdXf6ZyQ7C5fbl2wQ1CvvqtUOmyug,1462
2
+ langchain_ollama-0.3.3.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
+ langchain_ollama-0.3.3.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
+ langchain_ollama-0.3.3.dist-info/licenses/LICENSE,sha256=2btS8uNUDWD_UNjw9ba6ZJt_00aUjEw9CGyK-xIHY8c,1072
5
+ langchain_ollama/__init__.py,sha256=1f8Cyf1_bS0CT16U8-Os1P1Oa3erIDtIBTH4KVmBLvY,633
6
+ langchain_ollama/chat_models.py,sha256=Z2wzR5R568aNyH1LKN84kUdNZFOvvgY-csE626_sBVc,51723
7
+ langchain_ollama/embeddings.py,sha256=udL26XHdUMybQogY9Gj3vlJXxxkVAVZ-9He2U8wlJ3k,9547
8
+ langchain_ollama/llms.py,sha256=Rin6HVZvrH1epRsjhojSmOBFWAaU0cfOU1gV6I0bqJE,13933
9
+ langchain_ollama/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ langchain_ollama-0.3.3.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- langchain_ollama-0.3.2.dist-info/METADATA,sha256=58k8ADvokbZrjkTN5_-DRJWHYxZI6A1IbYO7rJ2DWc8,1463
2
- langchain_ollama-0.3.2.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
- langchain_ollama-0.3.2.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
- langchain_ollama-0.3.2.dist-info/licenses/LICENSE,sha256=2btS8uNUDWD_UNjw9ba6ZJt_00aUjEw9CGyK-xIHY8c,1072
5
- langchain_ollama/__init__.py,sha256=1f8Cyf1_bS0CT16U8-Os1P1Oa3erIDtIBTH4KVmBLvY,633
6
- langchain_ollama/chat_models.py,sha256=3ZvSHz-14idWKykyQgMV2i84bFrXVRjpU9dbGTz4_hs,50735
7
- langchain_ollama/embeddings.py,sha256=2G0gfnUbPBpVv9oBzL7C3z3FI_VumQ2WCYCf_-LMz-Q,8621
8
- langchain_ollama/llms.py,sha256=DiCWKLX2JPZAoVoRTKKQ2yOuoXbVStg0wkS1p6IruQU,13007
9
- langchain_ollama/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- langchain_ollama-0.3.2.dist-info/RECORD,,