Skip to content
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

Merged
merged 8 commits into from
Jan 12, 2024

Conversation

drazvan
Copy link
Collaborator

@drazvan drazvan commented Dec 20, 2023

This PR adds a new Python interface for LangChain integration. For more details checkout the documentation.

docs/user_guides/langchain-integration.md Outdated Show resolved Hide resolved
```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.
Copy link

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!

Comment on lines +83 to +93
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
Copy link

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

Copy link
Collaborator Author

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.

@drazvan drazvan self-assigned this Jan 12, 2024
@drazvan drazvan added this to the v0.7.0 milestone Jan 12, 2024
@drazvan drazvan merged commit 368a1ce into develop Jan 12, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants