fix up notebook (#12119)

pull/11999/merge
Harrison Chase 11 months ago committed by GitHub
parent ee69116761
commit dd0374560a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "59fb0852",
"id": "260629f9",
"metadata": {},
"source": [
"# Rewrite-Retrieve-Read\n",
@ -16,7 +16,7 @@
},
{
"cell_type": "markdown",
"id": "e11473f2",
"id": "eda93712",
"metadata": {},
"source": [
"## Baseline\n",
@ -26,8 +26,8 @@
},
{
"cell_type": "code",
"execution_count": 10,
"id": "ea9022ff",
"execution_count": 1,
"id": "1d2edbd2",
"metadata": {},
"outputs": [],
"source": [
@ -42,8 +42,8 @@
},
{
"cell_type": "code",
"execution_count": 90,
"id": "75aceda8",
"execution_count": 2,
"id": "86a46aa9",
"metadata": {},
"outputs": [],
"source": [
@ -68,8 +68,8 @@
},
{
"cell_type": "code",
"execution_count": 91,
"id": "db8a2a8f",
"execution_count": 3,
"id": "8566d48e",
"metadata": {},
"outputs": [],
"source": [
@ -83,8 +83,8 @@
},
{
"cell_type": "code",
"execution_count": 92,
"id": "002efdfa",
"execution_count": 4,
"id": "5c57f9ee",
"metadata": {},
"outputs": [],
"source": [
@ -93,8 +93,8 @@
},
{
"cell_type": "code",
"execution_count": 93,
"id": "2b74cc69",
"execution_count": 5,
"id": "37c5f962",
"metadata": {
"scrolled": false
},
@ -102,10 +102,10 @@
{
"data": {
"text/plain": [
"'LangChain is a powerful framework and versatile Python library that simplifies the development of language-based applications. It offers a suite of features for artificial general intelligence, including document analysis and summarization, as well as the ability to build chatbots that interact with users naturally. It is an open-source library that enables developers and researchers to create, experiment with, and analyze language models and agents. LangChain provides a generic interface to many foundation models, prompt management, and acts as a central interface to other components like prompt templates, other language models, external data, and other tools via agents. Overall, LangChain is designed to help developers build end-to-end applications using language models and offers a range of tools, components, and interfaces to simplify the process.'"
"\"LangChain is a powerful and versatile Python library that enables developers and researchers to create, experiment with, and analyze language models and agents. It simplifies the development of language-based applications by providing a suite of features for artificial general intelligence. It can be used to build chatbots, perform document analysis and summarization, and streamline interaction with various large language model providers. LangChain's unique proposition is its ability to create logical links between one or more language models, known as Chains. It is an open-source library that offers a generic interface to foundation models and allows prompt management and integration with other components and tools.\""
]
},
"execution_count": 93,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
@ -116,7 +116,7 @@
},
{
"cell_type": "markdown",
"id": "09dedf51",
"id": "23bdb9bd",
"metadata": {},
"source": [
"While this is fine for well formatted queries, it can break down for more complicated queries"
@ -124,8 +124,8 @@
},
{
"cell_type": "code",
"execution_count": 94,
"id": "7687cbf4",
"execution_count": 6,
"id": "8df6a814",
"metadata": {},
"outputs": [],
"source": [
@ -134,17 +134,17 @@
},
{
"cell_type": "code",
"execution_count": 95,
"id": "9ef1f1aa",
"execution_count": 7,
"id": "16d7db64",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Based on the given context, there is no information about \"langchain.\"'"
"'Based on the given context, there is no information provided about \"langchain.\"'"
]
},
"execution_count": 95,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
@ -155,7 +155,7 @@
},
{
"cell_type": "markdown",
"id": "1a7df277",
"id": "0b4f8b93",
"metadata": {},
"source": [
"This is because the retriever does a bad job with these \"distracted\" queries"
@ -163,17 +163,17 @@
},
{
"cell_type": "code",
"execution_count": 96,
"id": "72df8d50",
"execution_count": 8,
"id": "3439d8dc",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Sam Bankman-Fried, FTX\\'s founder, responded with a single word: \"Oof.\". Less than a year later, Mr. Bankman-Fried, 31, is on trial in federal court in Manhattan, fighting criminal charges ... NEW YORK, Oct 18 (Reuters) - A U.S. judge on Wednesday overruled objections by Sam Bankman-Fried\\'s lawyers and allowed jurors in the FTX founder\\'s fraud trial to see a profane message he... Business FTX founder Sam Bankman-Fried\\'s trial is about to start. Here\\'s what you need to know In testimony on Tuesday and Wednesday that got tearful at times, Ellison accused... Sam Bankman-Fried, who was once hailed as a virtuoso in cryptocurrency trading, is on trial over the collapse of FTX, the financial exchange he founded. Bankman-Fried is accused of... Business Oct 2, 2023 11:29 AM The Trial of Sam Bankman-Fried, Explained White-collar defendants use three main defenses: \"It wasn\\'t me, I didn\\'t mean it, and the people that say I did are...'"
"'Business She\\'s the star witness against Sam Bankman-Fried. Her testimony was explosive Gary Wang, who co-founded both FTX and Alameda Research, said Bankman-Fried directed him to change a... The Verge, following the trial\\'s Oct. 4 kickoff: \"Is Sam Bankman-Fried\\'s Defense Even Trying to Win?\". CBS Moneywatch, from Thursday: \"Sam Bankman-Fried\\'s Lawyer Struggles to Poke ... Sam Bankman-Fried, FTX\\'s founder, responded with a single word: \"Oof.\". Less than a year later, Mr. Bankman-Fried, 31, is on trial in federal court in Manhattan, fighting criminal charges ... July 19, 2023. A U.S. judge on Wednesday overruled objections by Sam Bankman-Fried\\'s lawyers and allowed jurors in the FTX founder\\'s fraud trial to see a profane message he sent to a reporter days ... Sam Bankman-Fried, who was once hailed as a virtuoso in cryptocurrency trading, is on trial over the collapse of FTX, the financial exchange he founded. Bankman-Fried is accused of...'"
]
},
"execution_count": 96,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
@ -184,7 +184,7 @@
},
{
"cell_type": "markdown",
"id": "987fbfd1",
"id": "7eb748ac",
"metadata": {},
"source": [
"## Rewrite-Retrieve-Read Implementation\n",
@ -194,34 +194,34 @@
},
{
"cell_type": "code",
"execution_count": 107,
"id": "fbe530b7",
"execution_count": 9,
"id": "88ae702e",
"metadata": {},
"outputs": [],
"source": [
"# template = \"\"\"Provide a better search query for \\\n",
"# web search engine to answer the given question, end \\\n",
"# the queries with **. Question: \\\n",
"# {x} Answer:\"\"\"\n",
"# prompt = ChatPromptTemplate.from_template(template)"
"template = \"\"\"Provide a better search query for \\\n",
"web search engine to answer the given question, end \\\n",
"the queries with **. Question: \\\n",
"{x} Answer:\"\"\"\n",
"rewrite_prompt = ChatPromptTemplate.from_template(template)"
]
},
{
"cell_type": "code",
"execution_count": 109,
"id": "01604b7d",
"execution_count": 10,
"id": "184e1bcb",
"metadata": {},
"outputs": [],
"source": [
"from langchain import hub\n",
"\n",
"prompt = hub.pull(\"langchain-ai/rewrite\")"
"rewrite_prompt = hub.pull(\"langchain-ai/rewrite\")"
]
},
{
"cell_type": "code",
"execution_count": 110,
"id": "d4fa60fb",
"execution_count": 11,
"id": "a4c23d40",
"metadata": {},
"outputs": [
{
@ -233,13 +233,13 @@
}
],
"source": [
"print(prompt.template)"
"print(rewrite_prompt.template)"
]
},
{
"cell_type": "code",
"execution_count": 111,
"id": "3e505a44",
"execution_count": 12,
"id": "f55cd010",
"metadata": {},
"outputs": [],
"source": [
@ -251,18 +251,18 @@
},
{
"cell_type": "code",
"execution_count": 112,
"id": "4f4c12e6",
"execution_count": 13,
"id": "c9c34bef",
"metadata": {},
"outputs": [],
"source": [
"rewriter = prompt | ChatOpenAI(temperature=0) | StrOutputParser() | _parse"
"rewriter = rewrite_prompt | ChatOpenAI(temperature=0) | StrOutputParser() | _parse"
]
},
{
"cell_type": "code",
"execution_count": 113,
"id": "ddbe5ac2",
"execution_count": 14,
"id": "fb17fb3d",
"metadata": {},
"outputs": [
{
@ -271,7 +271,7 @@
"'What is the definition and purpose of Langchain?'"
]
},
"execution_count": 113,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
@ -282,8 +282,8 @@
},
{
"cell_type": "code",
"execution_count": 101,
"id": "23a4f3f0",
"execution_count": 15,
"id": "f83edb09",
"metadata": {},
"outputs": [],
"source": [
@ -299,17 +299,17 @@
},
{
"cell_type": "code",
"execution_count": 102,
"id": "3c66e5c9",
"execution_count": 16,
"id": "43096322",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Based on the given context, LangChain is an open-source framework designed to simplify the creation of applications using large language models (LLMs). It provides a standard interface for chains, integrations with other tools, and end-to-end chains for common applications. LangChain enables LLM models to generate responses based on up-to-date online information and simplifies the organization of large volumes of data for easy access by LLMs. It is an AI framework with unique features that simplify the development of language-based applications.'"
"'Based on the given context, LangChain is an open-source framework designed to simplify the creation of applications using large language models (LLMs). It enables LLM models to generate responses based on up-to-date online information and simplifies the organization of large volumes of data for easy access by LLMs. LangChain offers a standard interface for chains, integrations with other tools, and end-to-end chains for common applications. It is a robust library that streamlines interaction with various LLM providers. LangChain\\'s unique proposition is its ability to create logical links between one or more LLMs, known as Chains. It is an AI framework with features that simplify the development of language-based applications and offers a suite of features for artificial general intelligence. However, the context does not provide any information about the \"sam bankman fried trial\" mentioned in the question.'"
]
},
"execution_count": 102,
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
@ -321,7 +321,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "974a17b3",
"id": "59874b4f",
"metadata": {},
"outputs": [],
"source": []

Loading…
Cancel
Save