"> where do frankenstein and the monster first meet\n",
"> where do frankenstein and the monster first meet\n",
" Victor retreats into the mountains and the Creature finds him and pleads for Victor to hear his tale, so they first meet in the mountains.\n",
" Victor and the Creature first meet in the mountains.\n",
"\n",
"\n",
"> who are the actors in fast and furious\n",
"> who are the actors in fast and furious\n",
" The actors in Fast and Furious are Vin Diesel as Dominic Toretto, Paul Walker as Brian O'Conner, Michelle Rodriguez as Letty Ortiz, Jordana Brewster as Mia Toretto, Tyrese Gibson as Roman Pearce, Ludacris as Tej Parker, Lucas Black as Sean Boswell, Sung Kang as Han Lue, Gal Gadot as Gisele Yashar, Dwayne Johnson as Luke Hobbs, Matt Schulze as Vince, Chad Lindberg as Jesse, Johnny Strong as Leon, Eva Mendes as Monica Fuentes, Devon Aoki as Suki, Nathalie Kelley as Neela, Bow Wow as Twinkie, Tego Calderón as Tego Leo, Don Omar as Rico Santos, Elsa Pataky as Elena Neves, and Kurt Russell as Mr. Nobody.\n",
" The actors in the Fast and Furious films are Vin Diesel, Paul Walker, Michelle Rodriguez, Jordana Brewster, Tyrese Gibson, Ludacris, Lucas Black, Sung Kang, Gal Gadot, Dwayne Johnson, Matt Schulze, Chad Lindberg, Johnny Strong, Eva Mendes, Devon Aoki, Nathalie Kelley, Bow Wow, Tego Calderón, Don Omar, Elsa Pataky, Kurt Russell, Nathalie Emmanuel, Scott Eastwood, Noel Gugliemi, Ja Rule, Thom Barry, Ted Levine, Minka Kelly, James Remar, Amaury Nolasco, Michael Ealy, MC Jin, Brian Goodman, Lynda Boyd, Jason Tobin, Neela, Liza Lapira, Alimi Ballard, Yorgo Constantine, Geoff Meed, Jeimy Osorio, Max William Crane, Charlie & Miller Kimsey, Eden Estrella, Romeo Santos, John Brotherton, Helen Mirren, Celestino Cornielle, Janmarco Santiago, Carlos De La Hoz, James Ayoub, Rick Yune, Cole Hauser, Brian Tee, John Ortiz, Luke Evans, Jason Statham, Charlize Theron, Reggie Lee, Mo Gallini, Roberto Sanchez, Leonardo\n",
"\n",
"\n",
"> properties of red black tree in data structure\n",
"> properties of red black tree in data structure\n",
" Red black trees have the following properties: each node is either red or black, the root is black, all leaves (NIL) are black, if a node is red, then both its children are black, and every path from a given node to any of its descendant NIL nodes contains the same number of black nodes.\n",
" Red black trees are a type of binary tree with a special set of properties. Each node is either red or black, the root is black, and if a node is red, then both its children are black. Every path from a given node to any of its descendant NIL nodes contains the same number of black nodes. The number of black nodes from the root to a node is the node's black depth, and the uniform number of black nodes in all paths from root to the leaves is called the black-height of the red-black tree.\n",
"\n",
"\n",
"> who designed the national coat of arms of south africa\n",
"> who designed the national coat of arms of south africa\n",
" Iaan Bekker\n",
" Iaan Bekker\n",
@ -394,11 +393,139 @@
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "markdown",
"execution_count": null,
"metadata": {},
"metadata": {},
"source": [
"### Custom prompt templates\n",
"\n",
"The `stuff` chain type in Langchain uses a specific prompt with question and context documents incorporated. This is what the default prompt looks like:\n",
"\n",
"```text\n",
"Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.\n",
"{context}\n",
"Question: {question}\n",
"Helpful Answer:\n",
"```\n",
"\n",
"We can, however, provide our prompt template and change the behaviour of the OpenAI LLM, while still using the `stuff` chain type. It is important to keep `{context}` and `{question}` as placeholders.\n",
"\n",
"#### Experimenting with custom prompts\n",
"\n",
"We can try using a different prompt template, so the model:\n",
"1. Responds with a single-sentence answer if it knows it.\n",
"2. Suggests a random song title if it doesn't know the answer to our question."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"ExecuteTime": {
"end_time": "2023-03-03T16:28:04.907231Z",
"start_time": "2023-03-03T16:28:04.898528Z"
}
},
"outputs": [],
"source": [
"from langchain.prompts import PromptTemplate"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"ExecuteTime": {
"end_time": "2023-03-03T16:45:25.130450Z",
"start_time": "2023-03-03T16:45:25.121744Z"
}
},
"outputs": [],
"source": [
"custom_prompt = \"\"\"\n",
"Use the following pieces of context to answer the question at the end. Please provide\n",
"a short single-sentence summary answer only. If you don't know the answer or if it's \n",
"not present in given context, don't try to make up an answer, but suggest me a random \n",