You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* refactor(langchain): migrate imports to canonical langchain-core paths
Migrate all imports from deprecated proxy paths to canonical
langchain-core paths
to ensure compatibility with LangChain 1.x. Changes include:
- Use `from langchain_core.language_models import BaseLLM,
BaseChatModel`
- Remove proxy imports from `langchain.chat_models.base`
- Standardize submodule imports to top-level
langchain_core.language_models
This ensures forward compatibility with LangChain 1.x where proxy
imports from the main langchain package will be removed.
* refactor(langchain)!: remove deprecated Chain support from action dispatcher
Remove support for registering LangChain Chain objects as actions in
favor of
the modern Runnable interface. Chain support is deprecated in LangChain
1.x
and users should migrate to using Runnable objects instead.
- Remove Chain handling logic from action_dispatcher.py
- Remove Chain-based tests from test_runnable_rails.py
- Add deprecation warning in python-api.md documentation
* refactor(langchain)!: remove SummarizeDocument built-in action
Remove the built-in SummarizeDocument action which relied on deprecated
LangChain Chain features. Users who need document summarization should
implement custom actions using LangChain Runnable chains.
- Delete nemoguardrails/actions/summarize_document.py
- Remove related import from llm/filters.py
* feat(langchain): add LangChain 1.x compatibility with fallback patterns
Add try/except fallback patterns in examples to support both LangChain
0.x and 1.x. When using LangChain 1.x, legacy Chain features are
imported from langchain-classic package with helpful error messages.
This allows examples to work seamlessly across LangChain versions
without requiring code changes from users.
- Add fallback imports for RetrievalQA, embeddings, text splitters,
vectorstores
- Provide clear error messages directing users to install
langchain-classic
* refactor(langchain): update runtime imports to langchain-core
Update Colang runtime imports to use canonical langchain-core paths for
callbacks and runnables. Part of the broader migration to langchain-core
for LangChain 1.x compatibility.
* docs(langchain): rewrite custom LLM provider guide with BaseChatModel support
Complete rewrite of the custom LLM provider documentation with:
- Separate comprehensive guides for BaseLLM (text completion) and
BaseChatModel (chat)
- Correct method signatures (_call vs _generate)
- Proper async implementations
- Clear registration instructions (register_llm_provider vs
register_chat_provider)
- Working code examples with correct langchain-core imports
- Important notes on choosing the right base class
This addresses the gap where users were not properly guided on
implementing
custom chat models and were being directed to the wrong interface.
* feat(langchain): extend dependency constraints to support LangChain 1.x
Extend LangChain dependency constraints to support both 0.x and 1.x versions:
- langchain: >=0.2.14,<0.4.0 → >=0.2.14,<2.0.0
- langchain-core: >=0.2.14,<0.4.0 → >=0.2.14,<2.0.0
- langchain-community: >=0.2.5,<0.4.0 → >=0.2.5,<2.0.0
To register a custom LLM provider, you need to create a class that inherits from `BaseLanguageModel` and register it using `register_llm_provider`.
40
+
NeMo Guardrails supports two types of custom LLM providers:
41
+
1. **Text Completion Models** (`BaseLLM`) - For models that work with string prompts
42
+
2. **Chat Models** (`BaseChatModel`) - For models that work with message-based conversations
41
43
42
-
It is important to implement the following methods:
44
+
### Custom Text Completion LLM (BaseLLM)
43
45
44
-
**Required**:
46
+
To register a custom text completion LLM provider, create a class that inherits from `BaseLLM` and register it using `register_llm_provider`.
45
47
46
-
- `_call`
47
-
- `_llm_type`
48
+
**Required methods:**
49
+
- `_call`- Synchronous text completion
50
+
- `_llm_type`- Returns the LLM type identifier
48
51
49
-
**Optional**:
50
-
51
-
- `_acall`
52
-
- `_astream`
53
-
- `_stream`
54
-
- `_identifying_params`
55
-
56
-
In other words, to create your custom LLM provider, you need to implement the following interface methods: `_call`, `_llm_type`, and optionally `_acall`, `_astream`, `_stream`, and `_identifying_params`. Here's how you can do it:
52
+
**Optional methods:**
53
+
- `_acall`- Asynchronous text completion (recommended)
54
+
- `_stream`- Streaming text completion
55
+
- `_astream`- Async streaming text completion
56
+
- `_identifying_params`- Returns parameters for model identification
57
57
58
58
```python
59
59
from typing import Any, Iterator, List, Optional
60
60
61
-
from langchain.base_language import BaseLanguageModel
62
61
from langchain_core.callbacks.manager import (
63
-
CallbackManagerForLLMRun,
64
62
AsyncCallbackManagerForLLMRun,
63
+
CallbackManagerForLLMRun,
65
64
)
65
+
from langchain_core.language_models import BaseLLM
66
66
from langchain_core.outputs import GenerationChunk
67
67
68
68
from nemoguardrails.llm.providers import register_llm_provider
Copy file name to clipboardExpand all lines: docs/user-guides/python-api.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -132,6 +132,8 @@ For convenience, this toolkit also includes a selection of LangChain tools, wrap
132
132
133
133
### Chains as Actions
134
134
135
+
> **⚠️ DEPRECATED**: Chain support is deprecated and will be removed in a future release. Please use [Runnable](https://python.langchain.com/docs/expression_language/) instead. See the [Runnable as Action Guide](langchain/runnable-as-action/README.md) for examples.
136
+
135
137
You can register a Langchain chain as an action using the [LLMRails.register_action](../api/nemoguardrails.rails.llm.llmrails.md#method-llmrailsregister_action) method:
0 commit comments