Skip to content

Commit

Permalink
Merge pull request #14 from hwchase17/harrison/generic_prompting_docu…
Browse files Browse the repository at this point in the history
…mentation

add simple prompt example
  • Loading branch information
hwchase17 authored Oct 22, 2022
2 parents 042e9db + 6c7150f commit 8626e37
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,22 @@ llm = OpenAI(temperature=0)
llm_math = LLMMathChain(llm=llm)
llm_math.run("How many of the integers between 0 and 99 inclusive are divisible by 8?")
```
```

**Generic Prompting**

You can also use this for simple prompting pipelines, as in the below example and this [example notebook](examples/simple_prompts.ipynb).

```
from langchain import Prompt, OpenAI, LLMChain
template = """Question: {question}
Answer: Let's think step by step."""
prompt = Prompt(template=template, input_variables=["question"])
llm_chain = LLMChain(prompt=prompt, llm=OpenAI(temperature=0))
question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"
llm_chain.predict(question=question)
```
64 changes: 64 additions & 0 deletions examples/simple_prompts.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"id": "51a54c4d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"' The year Justin Beiber was born was 1994. In 1994, the Dallas Cowboys won the Super Bowl.'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from langchain import Prompt, OpenAI, LLMChain\n",
"\n",
"template = \"\"\"Question: {question}\n",
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"prompt = Prompt(template=template, input_variables=[\"question\"])\n",
"llm_chain = LLMChain(prompt=prompt, llm=OpenAI(temperature=0))\n",
"\n",
"question = \"What NFL team won the Super Bowl in the year Justin Beiber was born?\"\n",
"\n",
"llm_chain.predict(question=question)"
]
},
{
"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",
"version": "3.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 8626e37

Please sign in to comment.