langchain/templates
2023-10-28 22:13:22 -07:00
..
anthropic-iterative-search various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
cassandra-entomology-rag various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
cassandra-synonym-caching various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
csv-agent various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
docs various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
elastic-query-generator various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
extraction-anthropic-functions various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
extraction-openai-functions Fix templates typos (#12428) 2023-10-27 09:32:57 -07:00
hyde various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
llama2-functions various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
neo4j-cypher various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
neo4j-cypher-ft various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
neo4j-generation various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
neo4j-parent various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
openai-functions-agent Format Templates (#12396) 2023-10-26 19:44:30 -07:00
pirate-speak Harrison/quick start (#12491) 2023-10-28 16:26:52 -07:00
plate-chain Sphinxbio nls/add plate chain template (#12502) 2023-10-28 21:48:17 -07:00
rag-aws-bedrock various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
rag-aws-kendra various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
rag-chroma various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
rag-chroma-private various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
rag-conversation various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
rag-elasticsearch Format Templates (#12396) 2023-10-26 19:44:30 -07:00
rag-fusion various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
rag-pinecone AWS Bedrock RAG template (#12450) 2023-10-27 13:15:54 -07:00
rag-pinecone-multi-query AWS Bedrock RAG template (#12450) 2023-10-27 13:15:54 -07:00
rag-pinecone-rerank Format Templates (#12396) 2023-10-26 19:44:30 -07:00
rag-redis Redis langserve template (#12443) 2023-10-28 08:31:12 -07:00
rag-semi-structured Format Templates (#12396) 2023-10-26 19:44:30 -07:00
rag-supabase Format Templates (#12396) 2023-10-26 19:44:30 -07:00
rag-weaviate Add Weaviate RAG template (#12460) 2023-10-27 15:19:34 -07:00
rewrite-retrieve-read various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
self-query-supabase Format Templates (#12396) 2023-10-26 19:44:30 -07:00
sql-llama2 Update SQL templates (#12464) 2023-10-27 16:34:37 -07:00
sql-llamacpp Update llama.cpp and Ollama templates (#12466) 2023-10-27 16:54:54 -07:00
sql-ollama Update llama.cpp and Ollama templates (#12466) 2023-10-27 16:54:54 -07:00
stepback-qa-prompting various templates improvements (#12500) 2023-10-28 22:13:22 -07:00
summarize-anthropic Clean-up template READMEs (#12403) 2023-10-26 22:23:03 -07:00
xml-agent Format Templates (#12396) 2023-10-26 19:44:30 -07:00
.gitignore Adds linter in templates (#12321) 2023-10-26 13:55:07 -07:00
Makefile Format Templates (#12396) 2023-10-26 19:44:30 -07:00
poetry.lock Format Templates (#12396) 2023-10-26 19:44:30 -07:00
pyproject.toml Format Templates (#12396) 2023-10-26 19:44:30 -07:00
README.md Harrison/quick start (#12491) 2023-10-28 16:26:52 -07:00

LangServe Templates

LangServe 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.

Quick Start

To use, first install the LangChain CLI.

pip install -U "langchain-cli[serve]"

Next, create a new LangChain project:

langchain serve 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 serve 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 package/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")

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

langchain start

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/:

playground.png

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

docs.png

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.