A sample integrating Dapr AI bindings with langchain.
langchain
already has integrations for many different language models, so why is this needed? Each of those integrations requires very specific choices being made at application implementation time--which models to support and how to configure them--as well as imposes a set of dependencies on the application for each supported model.
With Dapr, the application can use langchain but in a way that allows those decisions to be made at deployment time, through configuration, without any changes to application code and does not impose model-specific dependencies on the application (aside from the Dapr langchain
binding and Dapr Client SDK itself).
This sample creates several custom implementations of the langchain
language model and memory classes, which redirect their calls to one of the Dapr output bindings in the dapr-ai-bindings
sample, or to a standard Dapr state store in the case of the memory implementation.
- Python 3.10 or later
- Dapr 1.10 or later
- langchain 0.0.137 or later
- Dapr AI Bindings
This bindings package has not yet been published.
-
Install the Dapr AI bindings
pip3 install daprai
-
In your Python module, import the types as needed
from daprai.langchain import ( # A chat-based LLM that uses Dapr AI bindings ChatDaprAI # A completion-based LLM that uses Dapr AI bindings DaprAI # A memory component that uses Dapr state stores DaprMemory )
This repo contains several examples of integrating Dapr with langchain.
Example | Description |
---|---|
DaprAI LLM | An example of using the Dapr AI bindings as language models in langchain. |
DaprAI Chat LLM | An example of using the Dapr AI bindings as chat language models in langchain. |
DaprAI Memory | An example of using Dapr state stores as chat history memory in langchain. |
-
Install the project in an editable mode
pip3 install -e .
-
Install required packages
pip3 install -r requirements.txt
-
Run one of the examples