-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the new RunnableRails
interface for LangChain integration.
#235
Conversation
```python | ||
chain_with_guardrails = prompt | (guardrails | model) | output_parser | ||
``` | ||
> **NOTE**: Using the extra parenthesis is essential to enforce the order in which the `|` (pipe) operator is applied. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a sign it's not implemented properly. Ideally sequences should pass data forward, in which case nesting the sequences shouldn't matter. Will look at code in a sec!
def __or__(self, other): | ||
if isinstance(other, BaseLanguageModel): | ||
self.llm = other | ||
self.rails.update_llm(other) | ||
|
||
elif isinstance(other, Runnable): | ||
self.passthrough_runnable = other | ||
self.passthrough = True | ||
self._init_passthrough_fn() | ||
|
||
return self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see - this is why you need to wrap them in parentheses. This is not recommended. Instead, I would recommend passing in the llm
as an parameter to RunnableRails
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That also works. But I figured that supporting the "|" notation would make it easier to go from "without guardrails" to "with guardrails", by following a simple wrapping pattern.
Signed-off-by: Razvan Dinu <[email protected]>
This PR adds a new Python interface for LangChain integration. For more details checkout the documentation.