Add prompt hub for various use-cases (#9879)

Use prompt hub in our use-case docs and guides.
This commit is contained in:
Lance Martin
2023-09-03 15:32:22 -07:00
committed by GitHub
parent 00a7c31ffd
commit 16a27ab244
5 changed files with 335 additions and 478 deletions

View File

@@ -921,6 +921,48 @@
"llm(\"Question: In bash, how do I list all the text files in the current directory that have been modified in the last month? Answer:\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from langchain.chains.question_answering import load_qa_chain\n",
"\n",
"# Prompt\n",
"template = \"\"\"Use the following pieces of context to answer the question at the end. \n",
"If you don't know the answer, just say that you don't know, don't try to make up an answer. \n",
"Use three sentences maximum and keep the answer as concise as possible. \n",
"{context}\n",
"Question: {question}\n",
"Helpful Answer:\"\"\"\n",
"QA_CHAIN_PROMPT = PromptTemplate(\n",
" input_variables=[\"context\", \"question\"],\n",
" template=template,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also use the LangChain Prompt Hub to store and fetch prompts.\n",
"\n",
"This will work with your [LangSmith API key](https://docs.smith.langchain.com/).\n",
"\n",
"Let's try with a default RAG prompt, [here](https://smith.langchain.com/hub/rlm/rag-prompt)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from langchain import hub\n",
"QA_CHAIN_PROMPT = hub.pull(\"rlm/rag-prompt-default\")"
]
},
{
"cell_type": "code",
"execution_count": 29,
@@ -970,20 +1012,6 @@
}
],
"source": [
"from langchain.chains.question_answering import load_qa_chain\n",
"\n",
"# Prompt\n",
"template = \"\"\"Use the following pieces of context to answer the question at the end. \n",
"If you don't know the answer, just say that you don't know, don't try to make up an answer. \n",
"Use three sentences maximum and keep the answer as concise as possible. \n",
"{context}\n",
"Question: {question}\n",
"Helpful Answer:\"\"\"\n",
"QA_CHAIN_PROMPT = PromptTemplate(\n",
" input_variables=[\"context\", \"question\"],\n",
" template=template,\n",
")\n",
"\n",
"# Docs\n",
"question = \"How can I initialize a ReAct agent?\"\n",
"docs = retriever.get_relevant_documents(question)\n",