langchain/templates
Bagatur 9ffca3b92a
docs[patch], templates[patch]: Import from core (#14575)
Update imports to use core for the low-hanging fruit changes. Ran
following

```bash
git grep -l 'langchain.schema.runnable' {docs,templates,cookbook}  | xargs sed -i '' 's/langchain\.schema\.runnable/langchain_core.runnables/g'
git grep -l 'langchain.schema.output_parser' {docs,templates,cookbook} | xargs sed -i '' 's/langchain\.schema\.output_parser/langchain_core.output_parsers/g'
git grep -l 'langchain.schema.messages' {docs,templates,cookbook} | xargs sed -i '' 's/langchain\.schema\.messages/langchain_core.messages/g'
git grep -l 'langchain.schema.chat_histry' {docs,templates,cookbook} | xargs sed -i '' 's/langchain\.schema\.chat_history/langchain_core.chat_history/g'
git grep -l 'langchain.schema.prompt_template' {docs,templates,cookbook} | xargs sed -i '' 's/langchain\.schema\.prompt_template/langchain_core.prompts/g'
git grep -l 'from langchain.pydantic_v1' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.pydantic_v1/from langchain_core.pydantic_v1/g'
git grep -l 'from langchain.tools.base' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.tools\.base/from langchain_core.tools/g'
git grep -l 'from langchain.chat_models.base' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.chat_models.base/from langchain_core.language_models.chat_models/g'
git grep -l 'from langchain.llms.base' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.llms\.base\ /from langchain_core.language_models.llms\ /g'
git grep -l 'from langchain.embeddings.base' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.embeddings\.base/from langchain_core.embeddings/g'
git grep -l 'from langchain.vectorstores.base' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.vectorstores\.base/from langchain_core.vectorstores/g'
git grep -l 'from langchain.agents.tools' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.agents\.tools/from langchain_core.tools/g'
git grep -l 'from langchain.schema.output' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.schema\.output\ /from langchain_core.outputs\ /g'
git grep -l 'from langchain.schema.embeddings' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.schema\.embeddings/from langchain_core.embeddings/g'
git grep -l 'from langchain.schema.document' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.schema\.document/from langchain_core.documents/g'
git grep -l 'from langchain.schema.agent' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.schema\.agent/from langchain_core.agents/g'
git grep -l 'from langchain.schema.prompt ' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.schema\.prompt\ /from langchain_core.prompt_values /g'
git grep -l 'from langchain.schema.language_model' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.schema\.language_model/from langchain_core.language_models/g'


```
2023-12-11 16:49:10 -08:00
..
anthropic-iterative-search docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
basic-critique-revise docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
cassandra-entomology-rag docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
cassandra-synonym-caching docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
chain-of-note-wiki docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
chat-bot-feedback docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
csv-agent docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
docs
elastic-query-generator docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
extraction-anthropic-functions docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
extraction-openai-functions docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
guardrails-output-parser templates[patch]: relock templates (#14149) 2023-12-01 13:35:54 -08:00
hybrid-search-weaviate docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
hyde docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
llama2-functions templates[patch]: relock templates (#14149) 2023-12-01 13:35:54 -08:00
mongo-parent-document-retrieval docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
neo4j-advanced-rag docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
neo4j-cypher docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
neo4j-cypher-ft docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
neo4j-cypher-memory docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
neo4j-generation docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
neo4j-parent docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
neo4j-vector-memory docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
openai-functions-agent docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
openai-functions-tool-retrieval-agent docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
pii-protected-chatbot docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
pirate-speak templates[patch]: relock templates (#14149) 2023-12-01 13:35:54 -08:00
pirate-speak-configurable docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
plate-chain docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-astradb docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-aws-bedrock docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-aws-kendra docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-chroma docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-chroma-multi-modal docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-chroma-private docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-codellama-fireworks docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-conversation docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-conversation-zep docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-elasticsearch docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-fusion docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-google-cloud-sensitive-data-protection docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-google-cloud-vertexai-search docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-gpt-crawler docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-matching-engine docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-momento-vector-index docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-mongo docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-multi-index-fusion docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-multi-index-router docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-ollama-multi-query docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-opensearch docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-pinecone docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-pinecone-multi-query docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-pinecone-rerank docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-redis docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-self-query docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-semi-structured docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-singlestoredb docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-supabase docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-timescale-conversation docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-timescale-hybrid-search-time docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-vectara docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-vectara-multiquery docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rag-weaviate docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
research-assistant docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
retrieval-agent docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
rewrite-retrieve-read docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
self-query-qdrant docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
self-query-supabase docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
skeleton-of-thought docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
solo-performance-prompting-agent docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
sql-llama2 docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
sql-llamacpp docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
sql-ollama docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
sql-pgvector docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
stepback-qa-prompting docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
summarize-anthropic docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
vertexai-chuck-norris templates[patch]: relock templates (#14149) 2023-12-01 13:35:54 -08:00
xml-agent docs[patch], templates[patch]: Import from core (#14575) 2023-12-11 16:49:10 -08:00
.gitignore
Makefile core[patch], langchain[patch]: fix required deps (#14373) 2023-12-07 14:24:58 -08:00
poetry.lock core[patch], langchain[patch]: fix required deps (#14373) 2023-12-07 14:24:58 -08:00
pyproject.toml core[patch], langchain[patch]: fix required deps (#14373) 2023-12-07 14:24:58 -08:00
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 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")

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. LangSmith is currently in private beta, you can sign up 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/:

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.