Skip to content

Commit

Permalink
update prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
IGiotto12 authored and alckasoc committed Apr 29, 2024
1 parent 0e81ed9 commit 3f0275b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 60 deletions.
71 changes: 35 additions & 36 deletions agential/cog/agent/tmp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {},
"outputs": [
{
Expand All @@ -25,6 +25,14 @@
"text": [
"Environment has been set up\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/opt/anaconda3/envs/agential/lib/python3.11/site-packages/langchain_core/_api/deprecation.py:119: LangChainDeprecationWarning: The class `DocstoreExplorer` was deprecated in LangChain 0.1.0 and will be removed in 0.2.0\n",
" warn_deprecated(\n"
]
}
],
"source": [
Expand All @@ -45,33 +53,23 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 2,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"API key has been activated: sk-proj-Dj3uUHXxfdyKPW0A8ATlT3BlbkFJkR8P4QRzIGqelgujExYo\n"
]
}
],
"outputs": [],
"source": [
"from dotenv import load_dotenv\n",
"\n",
"load_dotenv()\n",
"api_key = os.getenv(\"OPENAI_API_KEY\")\n",
"if not api_key:\n",
" raise ValueError(\"API key not found. Please check your .env file.\")\n",
"\n",
"print(f\"API key has been activated: {api_key}\")"
" raise ValueError(\"API key not found. Please check your .env file.\")\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand All @@ -80,44 +78,45 @@
"text": [
"agent initialized\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/opt/anaconda3/envs/agential/lib/python3.11/site-packages/langchain_core/_api/deprecation.py:119: LangChainDeprecationWarning: The class `ChatOpenAI` was deprecated in LangChain 0.0.10 and will be removed in 0.2.0. An updated version of the class exists in the langchain-openai package and should be used instead. To use it run `pip install -U langchain-openai` and import as `from langchain_openai import ChatOpenAI`.\n",
" warn_deprecated(\n"
]
}
],
"source": [
"gpt_turbo = ChatOpenAI(api_key=api_key, model=\"gpt-3.5-turbo\")\n",
"print(\"agent initialized\")\n",
"agent = ReActAgent(llm=gpt_turbo)"
"agent = ReActAgent(llm=gpt_turbo, max_steps=3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/opt/anaconda3/envs/agential/lib/python3.11/site-packages/langchain_core/_api/deprecation.py:119: LangChainDeprecationWarning: The method `BaseChatModel.__call__` was deprecated in langchain-core 0.1.7 and will be removed in 0.2.0. Use invoke instead.\n",
" warn_deprecated(\n"
]
}
],
"source": [
"question = \"American Callan Pinckney's eponymously named system became a best-selling (1980s-2000s) book/video franchise in what genre?\"\n",
"question = \"Which innovation for the car was developed by Prince Henry of Prussia in 1911?\"\n",
"outputs = agent.generate(\n",
" question=question,\n",
" examples=TRIVIAQA_FEWSHOT_EXAMPLES,\n",
" prompt=REACT_INSTRUCTION_TRIVIAQA,\n",
")\n",
"\n",
"print(f\"Question: {question}\")\n",
"\n",
"if outputs:\n",
" for output in outputs:\n",
" print(\"Thought:\", output.thought)\n",
" print(\"Action:\", output.action)\n",
" print(\"Observation:\", output.observation)\n",
"else:\n",
" print(\"No output generated.\")"
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
45 changes: 21 additions & 24 deletions agential/cog/prompts/react.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,47 +134,44 @@
Question: {question}{scratchpad}"""

TRIVIAQA_FEWSHOT_EXAMPLES = """Question: Which innovation for the car was developed by Prince Henry of Prussia in 1911?
Thought 1: I need to search Prince Henry of Prussia in 1911, then find which innovation for the car was developed in 1911.
Action 1: Search[Prince Henry of Prussia in 1911]
Observation 1: Prince Henry of Prussia (German: Albert Wilhelm Heinrich; 14 August 1862 – 20 April 1929) was a younger brother of German Emperor Wilhelm II and a Prince of Prussia. He was also a grandson of Queen Victoria.
Thought 2: It does not mention any innovation for the car. So I need to lookup car.
Action 2: Lookup[car]
Observation 2: Henry was interested in motor cars as well and supposedly invented a windshield wiper[1] and, according to other sources, the car horn.
Thought 3: According to the evidence, Prince Henry of Prussia invented a windshield wiper for the car.
Thought 1: Let's search the question in google
Action 1: Search[Which innovation for the car was developed by Prince Henry of Prussia in 1911? site: wikipedia.org]
Observation 1: [Prince Henry of Prussia (1862–1929) - Wikipedia] Henry was interested in motor cars as well and supposedly invented a windshield wiper and, according to other sources, the car horn.
Thought 2: The evidence suggests that Prince Henry of Prussia invented a windshield wiper and the car horn.
Action 2: Search[When did Prince Henry of Prussia invented a windshield wiper and the car horn?]
Observation 2: [110 years ago: windscreen wiper patent for Prince Henry of Prussia] Quite apart from a member of the German aristocracy: it was Prince Henry of Prussia (1862-1929) who was granted the first German patent about the windscreen wiper on 24. March 1908.
Thought 3: According to the evidence, Prince Henry of Prussia was granted the first German patent for the windshield wiper.
Action 3: Finish[windshield wiper]
-----
Question: When did the founder of Jehovah's Witnesses say the world would end?
Thought 1: Let's search the question in google
Action 1: Search[When did the founder of Jehovah's Witnesses say the world would end? site: wikipedia.org]
Observation 1: [Eschatology of Jehovah's Witnesses - Wikipedia] In 1911, Russell wrote that October 1914 would witness the "full end" of Babylon, or nominal Christianity, "utterly destroyed as a system". At first, the hopes ...
Thought 2: The evidence shows that the founder of Jehovah's Witnesses predicted the world would end in October 1914
Action 2: Finish[1914]
-----
Question: Three people have featured on the reverse of the £5 note, the two most recent are George Stephenson and Elizabeth Fry, who was the first?
Thought 1: I need to search the first person featured on the reverse of the £5 note before George Stephenson and Elizabeth Fry.
Action 1: Search[the first person featured on the reverse of the £5 note before George Stephenson and Elizabeth Fry]
Observation 1: [Bank of England £5 note] The Bank of England £5 note, also known as a fiver, is a sterling banknote . It is the smallest denomination of banknote currently issued by the Bank of England.
Thought 1: Let's search the question in google
Action 1: Search[Three people have featured on the reverse of the £5 note, the two most recent are George Stephenson and Elizabeth Fry, who was the first?]
Observation 1: [Bank of England £5 note - Wikipedia] The Bank of England £5 note, also known as a fiver, is a sterling banknote . It is the smallest denomination of banknote currently issued by the Bank of England.
Thought 2: The evidence is about £5 note, it has no information about the featured people we want to find out.
Action 2: Search[Who was the first person to feature on the reverse of the £5 note? site: wikipedia.org]
Observation 2: [Bank of England £5 note] The old paper note, first issued in 2002 and bearing the image of prison reformer Elizabeth Fry on the reverse, was phased out and ceased to be legal tender after 5 May 2017.
Observation 2: [Bank of England £5 note - Wikipedia] The old paper note, first issued in 2002 and bearing the image of prison reformer Elizabeth Fry on the reverse, was phased out and ceased to be legal tender after 5 May 2017.
Thought 3: The evidence only mentions Elizabeth Fry, and from the question, we know that she was not the first person to feature on the reverse of the £5 note.
Action 3: Search[People have featured on the reverse of the £5 note: George Stephenson and Elizabeth Fry and?]
Observation 3: [Historical British figures featured on banknotes (1970-2017)] £5 – The Duke of Wellington, George Stephenson, Elizabeth Fry, Sir Winston Churchill £10 – Florence Nightingale, Charles Dickens, Charles Darwin £20 – William Shakespeare, ...
Thought 4: The evidence shows that the Duke of Wellington and Sir Winston Churchill were also featured on £5.
Action 4: Finish[Duke of Wellington]
-----
Question: What state had its bi-centenary of joining the Union a year after North Carolina?
Thought 1: I need to search the states had its bi-centenary of joining the Union a year after North Carolina.
Action 1: Search[What state had its bi-centenary of joining the Union a year after North Carolina?]
Observation 1: List of U.S. states by date of admission to the Union.
Thought 2: It does not provide information about the state had its bi-centenary of joining the Union a year after North Carolina. So I need to find the state joining the Union a year after North Carolina.
Action 2: Lookup[North Carolina]
Observation 2: North Carolina November 21, 1789[14](ratified) Crown Colony of North Carolina
Thought 3: Now I know the year of North Carolina joining the Union, so I need to look for one year after it.
Action 3: Lookup[1790]
Observation 3: May 29, 1790[8] (ratified) Crown Colony of Rhode Island and Providence Plantations
Thought 4: The evidence shows Rhode Island entered Union in 1790, which is a year after North Carolina.
Thought 1: Let's search the question in google
Action 1: Search[What state had its bi-centenary of joining the Union a year after North Carolina? site: wikipedia.org]
Observation 1: [List of U.S. states by date of admission to the Union - Wikipedia] 24. Missouri, August 10, 1821 · (admitted) ; 25. Arkansas, June 15, 1836 · (admitted) ...
Thought 2: The evidence does not provide information about the state had its bi-centenary of joining the Union a year after North Carolina. To answer the question, we need to find the state joining the Union a year after North Carolina.
Action 2: Search[Which state joined the Union a year after North Carolina? site: wikipedia.org]
Observation 2: [List of U.S. states by date of admission to the Union - Wikipedia...] ^ This list does not account for the secession of 11 states (Virginia, North Carolina, South Carolina, Georgia, Florida, Alabama, Mississippi, Tennessee, ...
Thought 3: Not enough evidence, we need further search.
Action 3: Search[What state joined the Union a year after North Carolina?]
Observation 3: [States by Order of Entry into Union - Infoplease] Joining the Union | State | Entered Union | Year Settled | | North Carolina | Nov. 21, 1789 | 1660 | | Rhode Island | May 29, 1790 | 1636 | | Vermont | Mar. 4, 1791 | 1724 |
Thought 4: The evidence shows North Carolina entered Union in 1789, and Rhode Island entered Union in 1790, which is a year after North Carolina.
Action 4: Finish[Rhode Island]"""

0 comments on commit 3f0275b

Please sign in to comment.