This directory covers loading and uploading of chains. Each sub-directory covers a different chain, and has not only the serialized agent but also a README file describing that agent.
All chains can be loaded from LangChain by specifying the desired path, and adding the lc://
prefix. The path should be relative to the langchain-hub
repo.
For example, to load the chain at the path langchain-hub/chains/hello-world/chain.json
, the path you want to specify is lc://chains/hello-world/chain.json
Once you have that path, you can load it in the following manner:
from langchain.chains import load_chain
chain = load_chain("lc://chains/hello-world/chain.json")
Extra arguments (kwargs) may be needed depending on the type of chain.
To upload an chain to the LangChainHub, you must upload 2 files:
- The chain. There are 2 supported file formats for agents:
json
andyaml
. - Associated README file for the chain. This provides a high level description of the chain.
To get a properly formatted json file, if you have a chain in memory in Python you can run:
chain.save("file_name.json")
Replace "file_name"
with the desired name of the file.
To get a properly formatted yaml file, if you have a chain in memory in Python you can run:
chain.save("file_name.yaml")
Replace "file_name"
with the desired name of the file.