seansullivan/Langchain-Docs-June-26-2024 huggingface dataset:
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# How to bind model-specific tools\n",
    "\n",
    "Providers adopt different conventions for formatting tool schemas. \n",
    "For instance, OpenAI uses a format like this:\n",
    "\n",
    "- `type`: The type of the tool. At the time of writing, this is always `\"function\"`.\n",
    "- `function`: An object containing tool parameters.\n",
    "- `function.name`: The name of the schema to output.\n",
    "- `function.description`: A high level description of the schema to output.\n",
    "- `function.parameters`: The nested details of the schema you want to extract, formatted as a [JSON schema](https://json-schema.org/) dict.\n",
    "\n",
    "We can bind this model-specific format directly to the model as well if preferred. Here's an example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_mn4ELw1NbuE0DFYhIeK0GrPe', 'function': {'arguments': '{\"a\":119,\"b\":8}', 'name': 'multiply'}, 'type': 'function'}]}, response_metadata={'token_usage': {'completion_tokens': 17, 'prompt_tokens': 62, 'total_tokens': 79}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': 'fp_c2295e73ad', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-353e8a9a-7125-4f94-8c68-4f3da4c21120-0', tool_calls=[{'name': 'multiply', 'args': {'a': 119, 'b': 8}, 'id': 'call_mn4ELw1NbuE0DFYhIeK0GrPe'}])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "\n",
    "model = ChatOpenAI()\n",
    "\n",
    "model_with_tools = model.bind(\n",
    "    tools=[\n",
    "        {\n",
    "            \"type\": \"function\",\n",
    "            \"function\": {\n",
    "                \"name\": \"multiply\",\n",
    "                \"description\": \"Multiply two integers together.\",\n",
    "                \"parameters\": {\n",
    "                    \"type\": \"object\",\n",
    "                    \"properties\": {\n",
    "                        \"a\": {\"type\": \"number\", \"description\": \"First integer\"},\n",
    "                        \"b\": {\"type\": \"number\", \"description\": \"Second integer\"},\n",
    "                    },\n",
    "                    \"required\": [\"a\", \"b\"],\n",
    "                },\n",
    "            },\n",
    "        }\n",
    "    ]\n",
    ")\n",
    "\n",
    "model_with_tools.invoke(\"Whats 119 times 8?\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is functionally equivalent to the `bind_tools()` method."
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f69d4a4c-137d-47e9-bea1-786afce9c1c0",
   "metadata": {},
   "source": [
    "# Analyze a single long document\n",
    "\n",
    "The AnalyzeDocumentChain takes in a single document, splits it up, and then runs it through a CombineDocumentsChain."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2a0707ce-6d2d-471b-bc33-64da32a7b3f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"../docs/docs/modules/state_of_the_union.txt\") as f:\n",
    "    state_of_the_union = f.read()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ca14d161-2d5b-4a6c-a296-77d8ce4b28cd",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.chains import AnalyzeDocumentChain\n",
    "from langchain_openai import ChatOpenAI\n",
    "\n",
    "llm = ChatOpenAI(model=\"gpt-3.5-turbo\", temperature=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "9f97406c-85a9-45fb-99ce-9138c0ba3731",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.chains.question_answering import load_qa_chain\n",
    "\n",
    "qa_chain = load_qa_chain(llm, chain_type=\"map_reduce\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "0871a753-f5bb-4b4f-a394-f87f2691f659",
   "metadata": {},
   "outputs": [],
   "source": [
    "qa_document_chain = AnalyzeDocumentChain(combine_docs_chain=qa_chain)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e6f86428-3c2c-46a0-a57c-e22826fdbf91",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'The President said, \"Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service.\"'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qa_document_chain.run(\n",
    "    input_document=state_of_the_union,\n",
    "    question=\"what did the president say about justice breyer?\",\n",
    ")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "052dfe58",
   "metadata": {},
   "source": [
    "# Fake LLM\n",
    "LangChain provides a fake LLM class that can be used for testing. This allows you to mock out calls to the LLM and simulate what would happen if the LLM responded in a certain way.\n",
    "\n",
    "In this notebook we go over how to use this.\n",
    "\n",
    "We start this with using the FakeLLM in an agent."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ef97ac4d",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_community.llms.fake import FakeListLLM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9a0a160f",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.agents import AgentType, initialize_agent, load_tools"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b272258c",
   "metadata": {},
   "outputs": [],
   "source": [
    "tools = load_tools([\"python_repl\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "94096c4c",
   "metadata": {},
   "outputs": [],
   "source": [
    "responses = [\"Action: Python REPL\\nAction Input: print(2 + 2)\", \"Final Answer: 4\"]\n",
    "llm = FakeListLLM(responses=responses)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "da226d02",
   "metadata": {},
   "outputs": [],
   "source": [
    "agent = initialize_agent(\n",
    "    tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "44c13426",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
      "\u001b[32;1m\u001b[1;3mAction: Python REPL\n",
      "Action Input: print(2 + 2)\u001b[0m\n",
      "Observation: \u001b[36;1m\u001b[1;3m4\n",
      "\u001b[0m\n",
      "Thought:\u001b[32;1m\u001b[1;3mFinal Answer: 4\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'4'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "agent.invoke(\"whats 2 + 2\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "814c2858",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Self-checking chain\n",
    "This notebook showcases how to use LLMCheckerChain."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001b[1m> Entering new LLMCheckerChain chain...\u001b[0m\n",
      "\n",
      "\n",
      "\u001b[1m> Entering new SequentialChain chain...\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "' No mammal lays the biggest eggs. The Elephant Bird, which was a species of giant bird, laid the largest eggs of any bird.'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from langchain.chains import LLMCheckerChain\n",
    "from langchain_openai import OpenAI\n",
    "\n",
    "llm = OpenAI(temperature=0.7)\n",
    "\n",
    "text = \"What type of mammal lays the biggest eggs?\"\n",
    "\n",
    "checker_chain = LLMCheckerChain.from_llm(llm, verbose=True)\n",
    "\n",
    "checker_chain.invoke(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e71e720f",
   "metadata": {},
   "source": [
    "# Math chain\n",
    "\n",
    "This notebook showcases using LLMs and Python REPLs to do complex word math problems."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "44e9ba31",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001b[1m> Entering new LLMMathChain chain...\u001b[0m\n",
      "What is 13 raised to the .3432 power?\u001b[32;1m\u001b[1;3m\n",
      "```text\n",
      "13 ** .3432\n",
      "```\n",
      "...numexpr.evaluate(\"13 ** .3432\")...\n",
      "\u001b[0m\n",
      "Answer: \u001b[33;1m\u001b[1;3m2.4116004626599237\u001b[0m\n",
      "\u001b[1m> Finished chain.\u001b[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'Answer: 2.4116004626599237'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from langchain.chains import LLMMathChain\n",
    "from langchain_openai import OpenAI\n",
    "\n",
    "llm = OpenAI(temperature=0)\n",
    "llm_math = LLMMathChain.from_llm(llm, verbose=True)\n",
    "\n",
    "llm_math.invoke(\"What is 13 raised to the .3432 power?\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e978bb8e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# RAG using Upstage Layout Analysis and Groundedness Check\n",
    "This example illustrates RAG using [Upstage](https://python.langchain.com/docs/integrations/providers/upstage/) Layout Analysis and Groundedness Check."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "\n",
    "from langchain_community.vectorstores import DocArrayInMemorySearch\n",
    "from langchain_core.output_parsers import StrOutputParser\n",
    "from langchain_core.prompts import ChatPromptTemplate\n",
    "from langchain_core.runnables import RunnablePassthrough\n",
    "from langchain_core.runnables.base import RunnableSerializable\n",
    "from langchain_upstage import (\n",
    "    ChatUpstage,\n",
    "    UpstageEmbeddings,\n",
    "    UpstageGroundednessCheck,\n",
    "    UpstageLayoutAnalysisLoader,\n",
    ")\n",
    "\n",
    "model = ChatUpstage()\n",
    "\n",
    "files = [\"/PATH/TO/YOUR/FILE.pdf\", \"/PATH/TO/YOUR/FILE2.pdf\"]\n",
    "\n",
    "loader = UpstageLayoutAnalysisLoader(file_path=files, split=\"element\")\n",
    "\n",
    "docs = loader.load()\n",
    "\n",
    "vectorstore = DocArrayInMemorySearch.from_documents(\n",
    "    docs, embedding=UpstageEmbeddings(model=\"solar-embedding-1-large\")\n",
    ")\n",
    "retriever = vectorstore.as_retriever()\n",
    "\n",
    "template = \"\"\"Answer the question based only on the following context:\n",
    "{context}\n",
    "\n",
    "Question: {question}\n",
    "\"\"\"\n",
    "prompt = ChatPromptTemplate.from_template(template)\n",
    "output_parser = StrOutputParser()\n",
    "\n",
    "retrieved_docs = retriever.get_relevant_documents(\"How many parameters in SOLAR model?\")\n",
    "\n",
    "groundedness_check = UpstageGroundednessCheck()\n",
    "groundedness = \"\"\n",
    "while groundedness != \"grounded\":\n",
    "    chain: RunnableSerializable = RunnablePassthrough() | prompt | model | output_parser\n",
    "\n",
    "    result = chain.invoke(\n",
    "        {\n",
    "            \"context\": retrieved_docs,\n",
    "            \"question\": \"How many parameters in SOLAR model?\",\n",
    "        }\n",
    "    )\n",
    "\n",
    "    groundedness = groundedness_check.invoke(\n",
    "        {\n",
    "            \"context\": retrieved_docs,\n",
    "            \"answer\": result,\n",
    "        }\n",
    "    )"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}return t}()||function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}(),document.documentElement.setAttribute("data-announcement-bar-initially-dismissed",function(){try{return"true"===localStorage.getItem("docusaurus.announcement.dismiss")}catch(t){}return!1}())
*   [](/v0.2/)
*   Providers

On this page

Providers
=========

LangChain integrates with many providers.

Partner Packages[​](#partner-packages "Direct link to Partner Packages")
------------------------------------------------------------------------

These providers have standalone `@langchain/{provider}` packages for improved versioning, dependency management and testing.

*   [Anthropic](https://www.npmjs.com/package/@langchain/anthropic)
*   [Cloudflare](https://www.npmjs.com/package/@langchain/cloudflare)
*   [Cohere](https://www.npmjs.com/package/@langchain/cohere)
*   [Exa](https://www.npmjs.com/package/@langchain/exa)
*   [Google GenAI](https://www.npmjs.com/package/@langchain/google-genai)
*   [Google VertexAI](https://www.npmjs.com/package/@langchain/google-vertexai)
*   [Google VertexAI Web](https://www.npmjs.com/package/@langchain/google-vertexai-web)
*   [Groq](https://www.npmjs.com/package/@langchain/groq)
*   [MistralAI](https://www.npmjs.com/package/@langchain/mistralai)
*   [MongoDB](https://www.npmjs.com/package/@langchain/mongodb)
*   [Nomic](https://www.npmjs.com/package/@langchain/nomic)
*   [OpenAI](https://www.npmjs.com/package/@langchain/openai)
*   [Pinecone](https://www.npmjs.com/package/@langchain/pinecone)
*   [Qdrant](https://www.npmjs.com/package/@langchain/qdrant)
*   [Redis](https://www.npmjs.com/package/@langchain/redis)
*   [Weaviate](https://www.npmjs.com/package/@langchain/weaviate)
*   [Yandex](https://www.npmjs.com/package/@langchain/yandex)

* * *

#### Was this page helpful?

  

#### You can also leave detailed feedback [on GitHub](https://github.com/langchain-ai/langchainjs/issues/new?assignees=&labels=03+-+Documentation&projects=&template=documentation.yml&title=DOC%3A+%3CPlease+write+a+comprehensive+title+after+the+%27DOC%3A+%27+prefix%3E).

[

Next

Providers

](/v0.2/docs/integrations/platforms/)

*   [Partner Packages](#partner-packages)
*   [](/v0.2/)
*   [How-to guides](/v0.2/docs/how_to/)
*   How to track token usage

On this page

How to track token usage
========================

Prerequisites

This guide assumes familiarity with the following concepts:

*   [LLMs](/v0.2/docs/concepts/#llms)

This notebook goes over how to track your token usage for specific LLM calls. This is only implemented by some providers, including OpenAI.

Here's an example of tracking token usage for a single LLM call via a callback:

tip

See [this section for general instructions on installing integration packages](/v0.2/docs/how_to/installation#installing-integration-packages).

*   npm
*   Yarn
*   pnpm

    npm install @langchain/openai

    yarn add @langchain/openai

    pnpm add @langchain/openai

    import { OpenAI } from "@langchain/openai";const llm = new OpenAI({  model: "gpt-3.5-turbo-instruct",  callbacks: [    {      handleLLMEnd(output) {        console.log(JSON.stringify(output, null, 2));      },    },  ],});await llm.invoke("Tell me a joke.");/*  {    "generations": [      [        {          "text": "\n\nWhy don't scientists trust atoms?\n\nBecause they make up everything.",          "generationInfo": {            "finishReason": "stop",            "logprobs": null          }        }      ]    ],    "llmOutput": {      "tokenUsage": {        "completionTokens": 14,        "promptTokens": 5,        "totalTokens": 19      }    }  }*/

#### API Reference:

*   [OpenAI](https://v02.api.js.langchain.com/classes/langchain_openai.OpenAI.html) from `@langchain/openai`

If this model is passed to a chain or agent that calls it multiple times, it will log an output each time.

Next steps[​](#next-steps "Direct link to Next steps")
------------------------------------------------------

You've now seen how to get token usage for supported LLM providers.

Next, check out the other how-to guides in this section, like [how to implement your own custom LLM](/v0.2/docs/how_to/custom_llm).

* * *

#### Was this page helpful?

  

#### You can also leave detailed feedback [on GitHub](https://github.com/langchain-ai/langchainjs/issues/new?assignees=&labels=03+-+Documentation&projects=&template=documentation.yml&title=DOC%3A+%3CPlease+write+a+comprehensive+title+after+the+%27DOC%3A+%27+prefix%3E).

[

Previous

How to track token usage

](/v0.2/docs/how_to/chat_token_usage_tracking)[

Next

How to pass through arguments from one step to the next

](/v0.2/docs/how_to/passthrough)

*   [Next steps](#next-steps)
*   [](/v0.2/)
*   [How-to guides](/v0.2/docs/how_to/)
*   How to construct filters

On this page

How to construct filters
========================

Prerequisites

This guide assumes familiarity with the following:

*   [Query analysis](/v0.2/docs/tutorials/query_analysis)

We may want to do query analysis to extract filters to pass into retrievers. One way we ask the LLM to represent these filters is as a Zod schema. There is then the issue of converting that Zod schema into a filter that can be passed into a retriever.

This can be done manually, but LangChain also provides some “Translators” that are able to translate from a common syntax into filters specific to each retriever. Here, we will cover how to use those translators.

Setup[​](#setup "Direct link to Setup")
---------------------------------------

### Install dependencies[​](#install-dependencies "Direct link to Install dependencies")

*   npm
*   yarn
*   pnpm

    npm i zod

    yarn add zod

    pnpm add zod

In this example, `year` and `author` are both attributes to filter on.

    import { z } from "zod";const searchSchema = z.object({  query: z.string(),  startYear: z.number().optional(),  author: z.string().optional(),});const searchQuery: z.infer<typeof searchSchema> = {  query: "RAG",  startYear: 2022,  author: "LangChain",};

    import { Comparison, Comparator } from "langchain/chains/query_constructor/ir";function constructComparisons(  query: z.infer<typeof searchSchema>): Comparison[] {  const comparisons: Comparison[] = [];  if (query.startYear !== undefined) {    comparisons.push(      new Comparison("gt" as Comparator, "start_year", query.startYear)    );  }  if (query.author !== undefined) {    comparisons.push(      new Comparison("eq" as Comparator, "author", query.author)    );  }  return comparisons;}const comparisons = constructComparisons(searchQuery);

    import { Operation, Operator } from "langchain/chains/query_constructor/ir";const _filter = new Operation("and" as Operator, comparisons);

    import { ChromaTranslator } from "langchain/retrievers/self_query/chroma";new ChromaTranslator().visitOperation(_filter);

    {  "$and": [    { start_year: { "$gt": 2022 } },    { author: { "$eq": "LangChain" } }  ]}

Next steps[​](#next-steps "Direct link to Next steps")
------------------------------------------------------

You’ve now learned how to create a specific filter from an arbitrary query.

Next, check out some of the other query analysis guides in this section, like [how to use few-shotting to improve performance](/v0.2/docs/how_to/query_no_queries).

* * *

#### Was this page helpful?

  

#### You can also leave detailed feedback [on GitHub](https://github.com/langchain-ai/langchainjs/issues/new?assignees=&labels=03+-+Documentation&projects=&template=documentation.yml&title=DOC%3A+%3CPlease+write+a+comprehensive+title+after+the+%27DOC%3A+%27+prefix%3E).

[

Previous

How to stream from a question-answering chain

](/v0.2/docs/how_to/qa_streaming)[

Next

How to add examples to the prompt

](/v0.2/docs/how_to/query_few_shot)

*   [Setup](#setup)
    *   [Install dependencies](#install-dependencies)
*   [Next steps](#next-steps)