From c27a6fa8a4741fd1c179287df5bc6f9bfffe9e53 Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Wed, 7 Dec 2022 08:40:08 -0800 Subject: [PATCH] update docs (#278) --- README.md | 2 +- docs/examples/chains/llm_bash.ipynb | 2 +- docs/examples/chains/llm_chain.ipynb | 83 +++++++++++++++++++++++++--- docs/index.rst | 4 +- 4 files changed, 78 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 19ea29b8..4fc020f9 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Please see [here](https://langchain.readthedocs.io/en/latest/?) for full documen ## 🚀 What can this help with? -There are three main areas (with a forth coming soon) that LangChain is designed to help with. +There are four main areas that LangChain is designed to help with. These are, in increasing order of complexity: 1. LLM and Prompts 2. Chains diff --git a/docs/examples/chains/llm_bash.ipynb b/docs/examples/chains/llm_bash.ipynb index 6e9a44f8..3bee8df1 100644 --- a/docs/examples/chains/llm_bash.ipynb +++ b/docs/examples/chains/llm_bash.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# LLM Chain\n", + "# BashChain\n", "This notebook showcases using LLMs and a bash process to do perform simple filesystem commands." ] }, diff --git a/docs/examples/chains/llm_chain.ipynb b/docs/examples/chains/llm_chain.ipynb index 88fe594d..591111a5 100644 --- a/docs/examples/chains/llm_chain.ipynb +++ b/docs/examples/chains/llm_chain.ipynb @@ -13,6 +13,26 @@ { "cell_type": "code", "execution_count": 1, + "id": "835e6978", + "metadata": {}, + "outputs": [], + "source": [ + "from langchain import PromptTemplate, OpenAI, LLMChain" + ] + }, + { + "cell_type": "markdown", + "id": "06bcb078", + "metadata": {}, + "source": [ + "### Single Input\n", + "\n", + "First, lets go over an example using a single input" + ] + }, + { + "cell_type": "code", + "execution_count": 3, "id": "51a54c4d", "metadata": {}, "outputs": [ @@ -22,29 +42,27 @@ "text": [ "\n", "\n", - "\u001b[1m> Entering new chain...\u001b[0m\n", + "\u001b[1m> Entering new LLMChain chain...\u001b[0m\n", "Prompt after formatting:\n", "\u001b[32;1m\u001b[1;3mQuestion: What NFL team won the Super Bowl in the year Justin Beiber was born?\n", "\n", "Answer: Let's think step by step.\u001b[0m\n", "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" + "\u001b[1m> Finished LLMChain chain.\u001b[0m\n" ] }, { "data": { "text/plain": [ - "' The year Justin Beiber was born was 1994. In 1994, the Dallas Cowboys won the Super Bowl.'" + "' Justin Bieber was born in 1994, so the NFL team that won the Super Bowl in 1994 was the Dallas Cowboys.'" ] }, - "execution_count": 1, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "from langchain import PromptTemplate, OpenAI, LLMChain\n", - "\n", "template = \"\"\"Question: {question}\n", "\n", "Answer: Let's think step by step.\"\"\"\n", @@ -53,14 +71,61 @@ "\n", "question = \"What NFL team won the Super Bowl in the year Justin Beiber was born?\"\n", "\n", - "llm_chain.run(question)" + "llm_chain.predict(question=question)" + ] + }, + { + "cell_type": "markdown", + "id": "79c3ec4d", + "metadata": {}, + "source": [ + "### Multiple Inputs\n", + "Now lets go over an example using multiple inputs." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "03dd6918", "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "\u001b[1m> Entering new LLMChain chain...\u001b[0m\n", + "Prompt after formatting:\n", + "\u001b[32;1m\u001b[1;3mWrite a sad poem about ducks.\u001b[0m\n", + "\n", + "\u001b[1m> Finished LLMChain chain.\u001b[0m\n" + ] + }, + { + "data": { + "text/plain": [ + "\"\\n\\nThe ducks swim in the pond,\\nTheir feathers so soft and warm,\\nBut they can't help but feel so forlorn.\\n\\nTheir quacks echo in the air,\\nBut no one is there to hear,\\nFor they have no one to share.\\n\\nThe ducks paddle around in circles,\\nTheir heads hung low in despair,\\nFor they have no one to care.\\n\\nThe ducks look up to the sky,\\nBut no one is there to see,\\nFor they have no one to be.\\n\\nThe ducks drift away in the night,\\nTheir hearts filled with sorrow and pain,\\nFor they have no one to gain.\"" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "template = \"\"\"Write a {adjective} poem about {subject}.\"\"\"\n", + "prompt = PromptTemplate(template=template, input_variables=[\"adjective\", \"subject\"])\n", + "llm_chain = LLMChain(prompt=prompt, llm=OpenAI(temperature=0), verbose=True)\n", + "\n", + "llm_chain.predict(adjective=\"sad\", subject=\"ducks\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8310cdaa", + "metadata": {}, "outputs": [], "source": [] } @@ -81,7 +146,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.10.8" } }, "nbformat": 4, diff --git a/docs/index.rst b/docs/index.rst index 7b2f8ba1..fd7b1f79 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -9,13 +9,13 @@ combine them with other sources of computation or knowledge. This library is aimed at assisting in the development of those types of applications. -There are three main areas (with a forth coming soon) that LangChain is designed to help with. +There are four main areas that LangChain is designed to help with. These are, in increasing order of complexity: 1. LLM and Prompts 2. Chains 3. Agents -4. (Coming Soon) Memory +4. Memory Let's go through these categories and for each one identify key concepts (to clarify terminology) as well as the problems in this area LangChain helps solve.