2022-10-24 21:51:15 +00:00
|
|
|
{
|
|
|
|
"cells": [
|
2022-11-14 04:13:23 +00:00
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"id": "d8a5c5d4",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"# Simple Example\n",
|
|
|
|
"\n",
|
|
|
|
"This notebook showcases a simple chain."
|
|
|
|
]
|
|
|
|
},
|
2022-10-24 21:51:15 +00:00
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2022-11-20 04:39:35 +00:00
|
|
|
"execution_count": 1,
|
2022-10-24 21:51:15 +00:00
|
|
|
"id": "51a54c4d",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
2022-11-20 04:39:35 +00:00
|
|
|
{
|
|
|
|
"name": "stdout",
|
|
|
|
"output_type": "stream",
|
|
|
|
"text": [
|
|
|
|
"\n",
|
|
|
|
"\n",
|
|
|
|
"\u001b[1m> Entering new 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"
|
|
|
|
]
|
|
|
|
},
|
2022-10-24 21:51:15 +00:00
|
|
|
{
|
|
|
|
"data": {
|
|
|
|
"text/plain": [
|
|
|
|
"' The year Justin Beiber was born was 1994. In 1994, the Dallas Cowboys won the Super Bowl.'"
|
|
|
|
]
|
|
|
|
},
|
2022-11-20 04:39:35 +00:00
|
|
|
"execution_count": 1,
|
2022-10-24 21:51:15 +00:00
|
|
|
"metadata": {},
|
|
|
|
"output_type": "execute_result"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
2022-11-20 04:32:45 +00:00
|
|
|
"from langchain import PromptTemplate, OpenAI, LLMChain\n",
|
2022-10-24 21:51:15 +00:00
|
|
|
"\n",
|
|
|
|
"template = \"\"\"Question: {question}\n",
|
|
|
|
"\n",
|
|
|
|
"Answer: Let's think step by step.\"\"\"\n",
|
2022-11-20 04:32:45 +00:00
|
|
|
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])\n",
|
2022-11-20 04:39:35 +00:00
|
|
|
"llm_chain = LLMChain(prompt=prompt, llm=OpenAI(temperature=0), verbose=True)\n",
|
2022-10-24 21:51:15 +00:00
|
|
|
"\n",
|
|
|
|
"question = \"What NFL team won the Super Bowl in the year Justin Beiber was born?\"\n",
|
|
|
|
"\n",
|
2022-11-14 04:13:23 +00:00
|
|
|
"llm_chain.run(question)"
|
2022-10-24 21:51:15 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"id": "03dd6918",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": []
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"metadata": {
|
|
|
|
"kernelspec": {
|
|
|
|
"display_name": "Python 3 (ipykernel)",
|
|
|
|
"language": "python",
|
|
|
|
"name": "python3"
|
|
|
|
},
|
|
|
|
"language_info": {
|
|
|
|
"codemirror_mode": {
|
|
|
|
"name": "ipython",
|
|
|
|
"version": 3
|
|
|
|
},
|
|
|
|
"file_extension": ".py",
|
|
|
|
"mimetype": "text/x-python",
|
|
|
|
"name": "python",
|
|
|
|
"nbconvert_exporter": "python",
|
|
|
|
"pygments_lexer": "ipython3",
|
2022-11-20 04:32:45 +00:00
|
|
|
"version": "3.8.7"
|
2022-10-24 21:51:15 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"nbformat": 4,
|
|
|
|
"nbformat_minor": 5
|
|
|
|
}
|