doc updates (#1639)

---------

Co-authored-by: vbarda <vadym@langchain.dev>
This commit is contained in:
Isaac Francisco
2024-09-08 16:55:52 +00:00
committed by GitHub
co-authored by vbarda
parent 38a644cf79
commit db306cd01b
98 changed files with 3227 additions and 978 deletions
+33 -23
View File
@@ -15,15 +15,9 @@
"\n",
"We will cover two approaches to the last technique here, since it is generally applicable across any LLM that supports tool calling.\n",
"\n",
"## Regular Extraction with Retries\n",
"## Setup\n",
"\n",
"Both examples here invoke a simple looping graph that takes following approach:\n",
"1. Prompt the LLM to respond.\n",
"2. If it responds with tool calls, validate those.\n",
"3. If the calls are correct, return. Otherwise, format the validation error as a new [ToolMessage](https://api.python.langchain.com/en/latest/messages/langchain_core.messages.tool.ToolMessage.html#langchain_core.messages.tool.ToolMessage) and prompt the LLM to fix the errors. Taking us back to step (1).\n",
"\n",
"\n",
"The techniques differ only on step (3). In this first step, we will prompt the original LLM to regenerate the function calls to fix the validation errors. In the next section, we will instead prompt the LLM to generate a **patch** to fix the errors, meaning it doesn't have to re-generate data that is valid."
"First, let's install the required packages and set our API keys"
]
},
{
@@ -34,16 +28,7 @@
"outputs": [],
"source": [
"%%capture --no-stderr\n",
"%pip install -U langchain-anthropic langgraph\n",
"# Or do langchain-{groq|openai|etc.} for another package with tool calling"
]
},
{
"cell_type": "markdown",
"id": "27b25a1c-f437-482a-97d3-c7f168986df5",
"metadata": {},
"source": [
"Set up your environment. If you are using groq, anthropic, etc., you will need to update different API keys."
"%pip install -U langchain-anthropic langgraph"
]
},
{
@@ -62,11 +47,36 @@
" os.environ[var] = getpass.getpass(f\"{var}: \")\n",
"\n",
"\n",
"_set_env(\"OPENAI_API_KEY\")\n",
"# Recommended to visualize the retry steps\n",
"_set_env(\"LANGCHAIN_API_KEY\")\n",
"os.environ[\"LANGCHAIN_TRACING_V2\"] = \"true\"\n",
"os.environ[\"LANGCHAIN_PROJECT\"] = \"Extraction Notebook\""
"_set_env(\"OPENAI_API_KEY\")"
]
},
{
"cell_type": "markdown",
"id": "f07bc7a6",
"metadata": {},
"source": [
"<div class=\"admonition tip\">\n",
" <p class=\"admonition-title\">Set up <a href=\"https://smith.langchain.com\">LangSmith</a> for LangGraph development</p>\n",
" <p style=\"padding-top: 5px;\">\n",
" Sign up for LangSmith to quickly spot issues and improve the performance of your LangGraph projects. LangSmith lets you use trace data to debug, test, and monitor your LLM apps built with LangGraph — read more about how to get started <a href=\"https://docs.smith.langchain.com\">here</a>. \n",
" </p>\n",
"</div> "
]
},
{
"cell_type": "markdown",
"id": "ba53b3c0",
"metadata": {},
"source": [
"## Regular Extraction with Retries\n",
"\n",
"Both examples here invoke a simple looping graph that takes following approach:\n",
"1. Prompt the LLM to respond.\n",
"2. If it responds with tool calls, validate those.\n",
"3. If the calls are correct, return. Otherwise, format the validation error as a new [ToolMessage](https://api.python.langchain.com/en/latest/messages/langchain_core.messages.tool.ToolMessage.html#langchain_core.messages.tool.ToolMessage) and prompt the LLM to fix the errors. Taking us back to step (1).\n",
"\n",
"\n",
"The techniques differ only on step (3). In this first step, we will prompt the original LLM to regenerate the function calls to fix the validation errors. In the next section, we will instead prompt the LLM to generate a **patch** to fix the errors, meaning it doesn't have to re-generate data that is valid."
]
},
{