langchain-ollama 0.3.2__tar.gz → 0.3.4__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 (32) hide show
  1. langchain_ollama-0.3.4/PKG-INFO +68 -0
  2. langchain_ollama-0.3.4/README.md +55 -0
  3. langchain_ollama-0.3.4/langchain_ollama/_utils.py +39 -0
  4. {langchain_ollama-0.3.2 → langchain_ollama-0.3.4}/langchain_ollama/chat_models.py +218 -120
  5. {langchain_ollama-0.3.2 → langchain_ollama-0.3.4}/langchain_ollama/embeddings.py +55 -12
  6. {langchain_ollama-0.3.2 → langchain_ollama-0.3.4}/langchain_ollama/llms.py +119 -32
  7. {langchain_ollama-0.3.2 → langchain_ollama-0.3.4}/pyproject.toml +61 -7
  8. langchain_ollama-0.3.4/tests/integration_tests/chat_models/cassettes/test_chat_models_standard/TestChatOllama.test_stream_time.yaml +32 -0
  9. {langchain_ollama-0.3.2 → langchain_ollama-0.3.4}/tests/integration_tests/chat_models/test_chat_models.py +9 -5
  10. langchain_ollama-0.3.4/tests/integration_tests/chat_models/test_chat_models_reasoning.py +252 -0
  11. langchain_ollama-0.3.4/tests/integration_tests/chat_models/test_chat_models_standard.py +180 -0
  12. {langchain_ollama-0.3.2 → langchain_ollama-0.3.4}/tests/integration_tests/test_compile.py +0 -1
  13. {langchain_ollama-0.3.2 → langchain_ollama-0.3.4}/tests/integration_tests/test_embeddings.py +3 -1
  14. langchain_ollama-0.3.4/tests/integration_tests/test_llms.py +152 -0
  15. langchain_ollama-0.3.4/tests/unit_tests/test_chat_models.py +85 -0
  16. langchain_ollama-0.3.4/tests/unit_tests/test_embeddings.py +30 -0
  17. langchain_ollama-0.3.4/tests/unit_tests/test_llms.py +71 -0
  18. langchain_ollama-0.3.2/PKG-INFO +0 -57
  19. langchain_ollama-0.3.2/README.md +0 -44
  20. langchain_ollama-0.3.2/tests/integration_tests/chat_models/test_chat_models_reasoning.py +0 -162
  21. langchain_ollama-0.3.2/tests/integration_tests/chat_models/test_chat_models_standard.py +0 -42
  22. langchain_ollama-0.3.2/tests/integration_tests/test_llms.py +0 -66
  23. langchain_ollama-0.3.2/tests/unit_tests/test_chat_models.py +0 -25
  24. langchain_ollama-0.3.2/tests/unit_tests/test_embeddings.py +0 -8
  25. langchain_ollama-0.3.2/tests/unit_tests/test_llms.py +0 -28
  26. {langchain_ollama-0.3.2 → langchain_ollama-0.3.4}/LICENSE +0 -0
  27. {langchain_ollama-0.3.2 → langchain_ollama-0.3.4}/langchain_ollama/__init__.py +1 -1
  28. {langchain_ollama-0.3.2 → langchain_ollama-0.3.4}/langchain_ollama/py.typed +0 -0
  29. {langchain_ollama-0.3.2 → langchain_ollama-0.3.4}/tests/__init__.py +0 -0
  30. {langchain_ollama-0.3.2 → langchain_ollama-0.3.4}/tests/integration_tests/__init__.py +0 -0
  31. {langchain_ollama-0.3.2 → langchain_ollama-0.3.4}/tests/unit_tests/__init__.py +0 -0
  32. {langchain_ollama-0.3.2 → langchain_ollama-0.3.4}/tests/unit_tests/test_imports.py +0 -0
@@ -0,0 +1,68 @@
1
+ Metadata-Version: 2.1
2
+ Name: langchain-ollama
3
+ Version: 0.3.4
4
+ Summary: An integration package connecting Ollama and LangChain
5
+ License: MIT
6
+ Project-URL: Source Code, https://github.com/langchain-ai/langchain/tree/master/libs/partners/ollama
7
+ Project-URL: Release Notes, https://github.com/langchain-ai/langchain/releases?q=tag%3A%22langchain-ollama%3D%3D0%22&expanded=true
8
+ Project-URL: repository, https://github.com/langchain-ai/langchain
9
+ Requires-Python: >=3.9
10
+ Requires-Dist: ollama<1.0.0,>=0.5.1
11
+ Requires-Dist: langchain-core<1.0.0,>=0.3.68
12
+ Description-Content-Type: text/markdown
13
+
14
+ # langchain-ollama
15
+
16
+ This package contains the LangChain integration with Ollama
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ pip install -U langchain-ollama
22
+ ```
23
+
24
+ For the package to work, you will need to install and run the Ollama server locally ([download](https://ollama.com/download)).
25
+
26
+ To run integration tests (`make integration_tests`), you will need the following models installed in your Ollama server:
27
+
28
+ - `llama3.1`
29
+ - `deepseek-r1:1.5b`
30
+
31
+ Install these models by running:
32
+
33
+ ```bash
34
+ ollama pull <name-of-model>
35
+ ```
36
+
37
+ ## [Chat Models](https://python.langchain.com/api_reference/ollama/chat_models/langchain_ollama.chat_models.ChatOllama.html#chatollama)
38
+
39
+ `ChatOllama` class exposes chat models from Ollama.
40
+
41
+ ```python
42
+ from langchain_ollama import ChatOllama
43
+
44
+ llm = ChatOllama(model="llama3.1")
45
+ llm.invoke("Sing a ballad of LangChain.")
46
+ ```
47
+
48
+ ## [Embeddings](https://python.langchain.com/api_reference/ollama/embeddings/langchain_ollama.embeddings.OllamaEmbeddings.html#ollamaembeddings)
49
+
50
+ `OllamaEmbeddings` class exposes embeddings from Ollama.
51
+
52
+ ```python
53
+ from langchain_ollama import OllamaEmbeddings
54
+
55
+ embeddings = OllamaEmbeddings(model="llama3.1")
56
+ embeddings.embed_query("What is the meaning of life?")
57
+ ```
58
+
59
+ ## [LLMs](https://python.langchain.com/api_reference/ollama/llms/langchain_ollama.llms.OllamaLLM.html#ollamallm)
60
+
61
+ `OllamaLLM` class exposes traditional LLMs from Ollama.
62
+
63
+ ```python
64
+ from langchain_ollama import OllamaLLM
65
+
66
+ llm = OllamaLLM(model="llama3.1")
67
+ llm.invoke("The meaning of life is")
68
+ ```
@@ -0,0 +1,55 @@
1
+ # langchain-ollama
2
+
3
+ This package contains the LangChain integration with Ollama
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install -U langchain-ollama
9
+ ```
10
+
11
+ For the package to work, you will need to install and run the Ollama server locally ([download](https://ollama.com/download)).
12
+
13
+ To run integration tests (`make integration_tests`), you will need the following models installed in your Ollama server:
14
+
15
+ - `llama3.1`
16
+ - `deepseek-r1:1.5b`
17
+
18
+ Install these models by running:
19
+
20
+ ```bash
21
+ ollama pull <name-of-model>
22
+ ```
23
+
24
+ ## [Chat Models](https://python.langchain.com/api_reference/ollama/chat_models/langchain_ollama.chat_models.ChatOllama.html#chatollama)
25
+
26
+ `ChatOllama` class exposes chat models from Ollama.
27
+
28
+ ```python
29
+ from langchain_ollama import ChatOllama
30
+
31
+ llm = ChatOllama(model="llama3.1")
32
+ llm.invoke("Sing a ballad of LangChain.")
33
+ ```
34
+
35
+ ## [Embeddings](https://python.langchain.com/api_reference/ollama/embeddings/langchain_ollama.embeddings.OllamaEmbeddings.html#ollamaembeddings)
36
+
37
+ `OllamaEmbeddings` class exposes embeddings from Ollama.
38
+
39
+ ```python
40
+ from langchain_ollama import OllamaEmbeddings
41
+
42
+ embeddings = OllamaEmbeddings(model="llama3.1")
43
+ embeddings.embed_query("What is the meaning of life?")
44
+ ```
45
+
46
+ ## [LLMs](https://python.langchain.com/api_reference/ollama/llms/langchain_ollama.llms.OllamaLLM.html#ollamallm)
47
+
48
+ `OllamaLLM` class exposes traditional LLMs from Ollama.
49
+
50
+ ```python
51
+ from langchain_ollama import OllamaLLM
52
+
53
+ llm = OllamaLLM(model="llama3.1")
54
+ llm.invoke("The meaning of life is")
55
+ ```
@@ -0,0 +1,39 @@
1
+ """Utility functions for validating Ollama models."""
2
+
3
+ from httpx import ConnectError
4
+ from ollama import Client, ResponseError
5
+
6
+
7
+ def validate_model(client: Client, model_name: str) -> None:
8
+ """Validate that a model exists in the Ollama instance.
9
+
10
+ Args:
11
+ client: The Ollama client.
12
+ model_name: The name of the model to validate.
13
+
14
+ Raises:
15
+ ValueError: If the model is not found or if there's a connection issue.
16
+ """
17
+ try:
18
+ response = client.list()
19
+
20
+ model_names: list[str] = [model["model"] for model in response["models"]]
21
+
22
+ if not any(
23
+ model_name == m or m.startswith(f"{model_name}:") for m in model_names
24
+ ):
25
+ msg = (
26
+ f"Model `{model_name}` not found in Ollama. Please pull the "
27
+ f"model (using `ollama pull {model_name}`) or specify a valid "
28
+ f"model name. Available local models: {', '.join(model_names)}"
29
+ )
30
+ raise ValueError(msg)
31
+ except ConnectError as e:
32
+ msg = "Failed to connect to Ollama. Please check that Ollama is downloaded, running and accessible. https://ollama.com/download" # noqa: E501
33
+ raise ValueError(msg) from e
34
+ except ResponseError as e:
35
+ msg = (
36
+ "Received an error from the Ollama API. "
37
+ "Please check your Ollama server logs."
38
+ )
39
+ raise ValueError(msg) from e