import CodeBlock from "@theme/CodeBlock";

# Cookbook

In this guide, we'll take a look at a few common types of sequences you can create.

## PromptTemplate + LLM

A PromptTemplate -> LLM is a core chain that is used in most other larger chains/systems.

import BasicExample from "@examples/guides/expression_language/cookbook_basic.ts";

<CodeBlock language="typescript">{BasicExample}</CodeBlock>

## PromptTemplate + LLM + OutputParser

We can also add in an output parser to easily trasform the raw LLM/ChatModel output into a consistent string format:

import OutputParserExample from "@examples/guides/expression_language/cookbook_output_parser.ts";

<CodeBlock language="typescript">{OutputParserExample}</CodeBlock>

## Passthroughs

Often times when constructing a chain you may want to pass along original input variables to future steps in the chain. How exactly you do this depends on what exactly the input is:

- If the original input was a string, then you likely just want to pass along the string. This can be done with `RunnablePassthrough`. For an example of this, see `LLMChain + Retriever`
- If the original input was an object, then you likely want to pass along specific keys. For this, you can use an arrow function that takes the object as input and extracts the desired key. For an example of this see the `Mapping multiple input keys` example below

## LLMChain + Retriever

Let's now look at adding in a retrieval step, which adds up to a "retrieval-augmented generation" chain:

import RetrieverExample from "@examples/guides/expression_language/cookbook_retriever.ts";

<CodeBlock language="typescript">{RetrieverExample}</CodeBlock>

## Binding options

Often times we want to attach kwargs to the model that's passed in. To do this, runnables contain a `.bind` method. Here's how you can use it:

### Attaching stop sequences

import StopSequenceExample from "@examples/guides/expression_language/cookbook_stop_sequence.ts";

<CodeBlock language="typescript">{StopSequenceExample}</CodeBlock>

### Attaching function call information

import FunctionCallExample from "@examples/guides/expression_language/cookbook_function_call.ts";

<CodeBlock language="typescript">{FunctionCallExample}</CodeBlock>

## Mapping multiple input keys

In the above example, we pass a string input directly into our chain. If we want our chain to take multiple inputs, we can pass a map of functions to parse the inputs:

import RetrieverMapExample from "@examples/guides/expression_language/cookbook_retriever_map.ts";

<CodeBlock language="typescript">{RetrieverMapExample}</CodeBlock>

## Conversational Retrieval Chain

Because `RunnableSequence.from` and `runnable.pipe` both accept runnable-like objects, including single-argument functions, we can add in conversation history via a formatting function.
This allows us to recreate the popular `ConversationalRetrievalQAChain` to "chat with data":

import ConversationalRetrievalExample from "@examples/guides/expression_language/cookbook_conversational_retrieval.ts";

<CodeBlock language="typescript">{ConversationalRetrievalExample}</CodeBlock>

Note that the individual chains we created are themselves `Runnables` and can therefore be piped into each other.

## Tools

You can use LangChain tools as well:

import ToolExample from "@examples/guides/expression_language/cookbook_tools.ts";

<CodeBlock language="typescript">{ToolExample}</CodeBlock>
