You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
langchain/templates
Leonid Ganeline 163ef35dd1
docs: `templates` updated titles (#25646)
Updated titles into a consistent format. 
Fixed links to the diagrams.
Fixed typos.
Note: The Templates menu in the navbar is now sorted by the file names.
I'll try sorting the navbar menus by the page titles, not the page file
names.
4 weeks ago
..
anthropic-iterative-search docs: `templates` updated titles (#25646) 4 weeks ago
basic-critique-revise docs: `templates` updated titles (#25646) 4 weeks ago
bedrock-jcvd docs: `templates` updated titles (#25646) 4 weeks ago
cassandra-entomology-rag docs: `templates` updated titles (#25646) 4 weeks ago
cassandra-synonym-caching docs: `templates` updated titles (#25646) 4 weeks ago
chain-of-note-wiki docs: `templates` updated titles (#25646) 4 weeks ago
chat-bot-feedback docs: `templates` updated titles (#25646) 4 weeks ago
cohere-librarian docs: `templates` updated titles (#25646) 4 weeks ago
csv-agent docs: `templates` updated titles (#25646) 4 weeks ago
docs docs: `templates` updated titles (#25646) 4 weeks ago
elastic-query-generator docs: `templates` updated titles (#25646) 4 weeks ago
extraction-anthropic-functions docs: `templates` updated titles (#25646) 4 weeks ago
extraction-openai-functions docs: `templates` updated titles (#25646) 4 weeks ago
gemini-functions-agent docs: `templates` updated titles (#25646) 4 weeks ago
guardrails-output-parser docs: `templates` updated titles (#25646) 4 weeks ago
hybrid-search-weaviate docs: `templates` updated titles (#25646) 4 weeks ago
hyde docs: `templates` updated titles (#25646) 4 weeks ago
intel-rag-xeon docs: `templates` updated titles (#25646) 4 weeks ago
llama2-functions docs: `templates` updated titles (#25646) 4 weeks ago
mongo-parent-document-retrieval docs: `templates` updated titles (#25646) 4 weeks ago
neo4j-advanced-rag docs: `templates` updated titles (#25646) 4 weeks ago
neo4j-cypher docs: `templates` updated titles (#25646) 4 weeks ago
neo4j-cypher-ft docs: `templates` updated titles (#25646) 4 weeks ago
neo4j-cypher-memory docs: `templates` updated titles (#25646) 4 weeks ago
neo4j-generation docs: `templates` updated titles (#25646) 4 weeks ago
neo4j-parent docs: `templates` updated titles (#25646) 4 weeks ago
neo4j-semantic-layer docs: `templates` updated titles (#25646) 4 weeks ago
neo4j-semantic-ollama docs: `templates` updated titles (#25646) 4 weeks ago
neo4j-vector-memory docs: `templates` updated titles (#25646) 4 weeks ago
nvidia-rag-canonical docs: `templates` updated titles (#25646) 4 weeks ago
openai-functions-agent docs: `templates` updated titles (#25646) 4 weeks ago
openai-functions-agent-gmail docs: `templates` updated titles (#25646) 4 weeks ago
openai-functions-tool-retrieval-agent docs: `templates` updated titles (#25646) 4 weeks ago
pii-protected-chatbot docs: `templates` updated titles (#25646) 4 weeks ago
pirate-speak docs: `templates` updated titles (#25646) 4 weeks ago
pirate-speak-configurable docs: `templates` updated titles (#25646) 4 weeks ago
plate-chain docs: `templates` updated titles (#25646) 4 weeks ago
propositional-retrieval docs: `templates` updated titles (#25646) 4 weeks ago
python-lint docs: `templates` updated titles (#25646) 4 weeks ago
rag-astradb docs: `templates` updated titles (#25646) 4 weeks ago
rag-aws-bedrock docs: `templates` updated titles (#25646) 4 weeks ago
rag-aws-kendra docs: `templates` updated titles (#25646) 4 weeks ago
rag-azure-search docs: `templates` updated titles (#25646) 4 weeks ago
rag-chroma docs: `templates` updated titles (#25646) 4 weeks ago
rag-chroma-multi-modal docs: `templates` updated titles (#25646) 4 weeks ago
rag-chroma-multi-modal-multi-vector docs: `templates` updated titles (#25646) 4 weeks ago
rag-chroma-private docs: `templates` updated titles (#25646) 4 weeks ago
rag-codellama-fireworks docs: `templates` updated titles (#25646) 4 weeks ago
rag-conversation docs: `templates` updated titles (#25646) 4 weeks ago
rag-conversation-zep docs: `templates` updated titles (#25646) 4 weeks ago
rag-elasticsearch docs: `templates` updated titles (#25646) 4 weeks ago
rag-fusion docs: `templates` updated titles (#25646) 4 weeks ago
rag-gemini-multi-modal docs: `templates` updated titles (#25646) 4 weeks ago
rag-google-cloud-sensitive-data-protection docs: `templates` updated titles (#25646) 4 weeks ago
rag-google-cloud-vertexai-search docs: `templates` updated titles (#25646) 4 weeks ago
rag-gpt-crawler docs: `templates` updated titles (#25646) 4 weeks ago
rag-jaguardb docs: `templates` updated titles (#25646) 4 weeks ago
rag-lancedb docs: `templates` updated titles (#25646) 4 weeks ago
rag-lantern docs: `templates` updated titles (#25646) 4 weeks ago
rag-matching-engine docs: `templates` updated titles (#25646) 4 weeks ago
rag-milvus docs: `templates` updated titles (#25646) 4 weeks ago
rag-momento-vector-index docs: `templates` updated titles (#25646) 4 weeks ago
rag-mongo docs: `templates` updated titles (#25646) 4 weeks ago
rag-multi-index-fusion docs: `templates` updated titles (#25646) 4 weeks ago
rag-multi-index-router docs: `templates` updated titles (#25646) 4 weeks ago
rag-multi-modal-local docs: `templates` updated titles (#25646) 4 weeks ago
rag-multi-modal-mv-local docs: `templates` updated titles (#25646) 4 weeks ago
rag-ollama-multi-query docs: `templates` updated titles (#25646) 4 weeks ago
rag-opensearch docs: `templates` updated titles (#25646) 4 weeks ago
rag-pinecone docs: `templates` updated titles (#25646) 4 weeks ago
rag-pinecone-multi-query docs: `templates` updated titles (#25646) 4 weeks ago
rag-pinecone-rerank docs: `templates` updated titles (#25646) 4 weeks ago
rag-redis docs: `templates` updated titles (#25646) 4 weeks ago
rag-redis-multi-modal-multi-vector docs: `templates` updated titles (#25646) 4 weeks ago
rag-self-query docs: `templates` updated titles (#25646) 4 weeks ago
rag-semi-structured docs: `templates` updated titles (#25646) 4 weeks ago
rag-singlestoredb docs: `templates` updated titles (#25646) 4 weeks ago
rag-supabase docs: `templates` updated titles (#25646) 4 weeks ago
rag-timescale-conversation docs: `templates` updated titles (#25646) 4 weeks ago
rag-timescale-hybrid-search-time docs: `templates` updated titles (#25646) 4 weeks ago
rag-vectara docs: `templates` updated titles (#25646) 4 weeks ago
rag-vectara-multiquery docs: `templates` updated titles (#25646) 4 weeks ago
rag-weaviate docs: `templates` updated titles (#25646) 4 weeks ago
research-assistant docs: `templates` updated titles (#25646) 4 weeks ago
retrieval-agent docs: `templates` updated titles (#25646) 4 weeks ago
retrieval-agent-fireworks docs: `templates` updated titles (#25646) 4 weeks ago
rewrite-retrieve-read docs: `templates` updated titles (#25646) 4 weeks ago
robocorp-action-server docs: `templates` updated titles (#25646) 4 weeks ago
self-query-qdrant docs: `templates` updated titles (#25646) 4 weeks ago
self-query-supabase docs: `templates` updated titles (#25646) 4 weeks ago
shopping-assistant docs: `templates` updated titles (#25646) 4 weeks ago
skeleton-of-thought docs: `templates` updated titles (#25646) 4 weeks ago
solo-performance-prompting-agent docs: `templates` updated titles (#25646) 4 weeks ago
sql-llama2 docs: `templates` updated titles (#25646) 4 weeks ago
sql-llamacpp docs: `templates` updated titles (#25646) 4 weeks ago
sql-ollama docs: `templates` updated titles (#25646) 4 weeks ago
sql-pgvector docs: `templates` updated titles (#25646) 4 weeks ago
sql-research-assistant docs: `templates` updated titles (#25646) 4 weeks ago
stepback-qa-prompting docs: `templates` updated titles (#25646) 4 weeks ago
summarize-anthropic docs: `templates` updated titles (#25646) 4 weeks ago
vertexai-chuck-norris docs: `templates` updated titles (#25646) 4 weeks ago
xml-agent docs: `templates` updated titles (#25646) 4 weeks ago
.gitignore
Makefile
README.md docs: `templates` updated titles (#25646) 4 weeks ago
poetry.lock
pyproject.toml

README.md

LangChain Templates

LangChain Templates are the easiest and fastest way to build a production-ready LLM application. These templates serve as a set of reference architectures for a wide variety of popular LLM use cases. They are all in a standard format which make it easy to deploy them with LangServe.

🚩 We will be releasing a hosted version of LangServe for one-click deployments of LangChain applications. Sign up here to get on the waitlist.

Quick Start

To use, first install the LangChain CLI.

pip install -U langchain-cli

Next, create a new LangChain project:

langchain app new my-app

This will create a new directory called my-app with two folders:

  • app: This is where LangServe code will live
  • packages: This is where your chains or agents will live

To pull in an existing template as a package, you first need to go into your new project:

cd my-app

And you can the add a template as a project. In this getting started guide, we will add a simple pirate-speak project. All this project does is convert user input into pirate speak.

langchain app add pirate-speak

This will pull in the specified template into packages/pirate-speak

You will then be prompted if you want to install it. This is the equivalent of running pip install -e packages/pirate-speak. You should generally accept this (or run that same command afterwards). We install it with -e so that if you modify the template at all (which you likely will) the changes are updated.

After that, it will ask you if you want to generate route code for this project. This is code you need to add to your app to start using this chain. If we accept, we will see the following code generated:

from pirate_speak.chain import chain as pirate_speak_chain

add_routes(app, pirate_speak_chain, path="/pirate-speak")

You can now edit the template you pulled down. You can change the code files in packages/pirate-speak to use a different model, different prompt, different logic. Note that the above code snippet always expects the final chain to be importable as from pirate_speak.chain import chain, so you should either keep the structure of the package similar enough to respect that or be prepared to update that code snippet.

Once you have done as much of that as you want, it is In order to have LangServe use this project, you then need to modify app/server.py. Specifically, you should add the above code snippet to app/server.py so that file looks like:

from fastapi import FastAPI
from langserve import add_routes
from pirate_speak.chain import chain as pirate_speak_chain

app = FastAPI()

add_routes(app, pirate_speak_chain, path="/pirate-speak")

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. You can sign up for LangSmith here. If you don't have access, you can skip this section

export LANGCHAIN_TRACING_V2=true
export LANGCHAIN_API_KEY=<your-api-key>
export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"

For this particular application, we will use OpenAI as the LLM, so we need to export our OpenAI API key:

export OPENAI_API_KEY=sk-...

You can then spin up production-ready endpoints, along with a playground, by running:

langchain serve

This now gives a fully deployed LangServe application. For example, you get a playground out-of-the-box at http://127.0.0.1:8000/pirate-speak/playground/:

Screenshot of the LangServe Playground interface with input and output fields demonstrating pirate speak conversion. "LangServe Playground Interface"

Access API documentation at http://127.0.0.1:8000/docs

Screenshot of the API documentation interface showing available endpoints for the pirate-speak application. "API Documentation Interface"

Use the LangServe python or js SDK to interact with the API as if it were a regular Runnable.

from langserve import RemoteRunnable

api = RemoteRunnable("http://127.0.0.1:8000/pirate-speak")
api.invoke({"text": "hi"})

That's it for the quick start! You have successfully downloaded your first template and deployed it with LangServe.

Additional Resources

Index of Templates

Explore the many templates available to use - from advanced RAG to agents.

Contributing

Want to contribute your own template? It's pretty easy! These instructions walk through how to do that.

Launching LangServe from a Package

You can also launch LangServe from a package directly (without having to create a new project). These instructions cover how to do that.