Skip to content

Commit

Permalink
Option for normal or streaming responses on Notebook 8
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomarin committed Jul 17, 2023
1 parent 6be08b3 commit 5575292
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 389 deletions.
93 changes: 40 additions & 53 deletions 07-BingChatClone.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
{
"cell_type": "code",
"execution_count": 46,
"execution_count": 1,
"id": "c1fb79a3-4856-4721-988c-112813690a90",
"metadata": {},
"outputs": [],
Expand All @@ -51,12 +51,12 @@
"def printmd(string):\n",
" display(Markdown(string.replace(\"$\",\"USD \")))\n",
" \n",
"MODEL_DEPLOYMENT_NAME = \"gpt-4\" # GPT-4 models are necessary for this feature. GPT-35-turbo will make mistakes on following system prompt instructions."
"MODEL_DEPLOYMENT_NAME = \"gpt-4-32k\" # GPT-4 models are necessary for this feature. GPT-35-turbo will make mistakes on following system prompt instructions."
]
},
{
"cell_type": "code",
"execution_count": 47,
"execution_count": 2,
"id": "258a6e99-2d4f-4147-b8ee-c64c85296181",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -97,7 +97,7 @@
},
{
"cell_type": "code",
"execution_count": 48,
"execution_count": 3,
"id": "9d3daf03-77e2-466e-a255-2f06bee3561b",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -127,7 +127,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 4,
"id": "d3d155ae-16eb-458a-b2ed-5aa9a9b84ed8",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -159,7 +159,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 5,
"id": "2c6cf721-76bb-47b6-aeeb-9ff4ff92b1f4",
"metadata": {},
"outputs": [],
Expand All @@ -179,7 +179,7 @@
},
{
"cell_type": "code",
"execution_count": 53,
"execution_count": 6,
"id": "fa949cea-c9aa-4529-a75f-61084ffffd7e",
"metadata": {},
"outputs": [],
Expand All @@ -190,7 +190,9 @@
"# QUESTION = \"Who won the 2023 superbowl and who was the MVP?\"\n",
"# QUESTION = \"can I travel to Hawaii, Maui from Dallas, TX for 7 days with $7000 on the month of September, what are the best days to travel?\"\n",
"\n",
"\n",
"# This complex question below needs gpt-4-32k (0613 version) in order to ensure a good answer. \n",
"# ---------------\n",
"# QUESTION = \"\"\"\n",
"# compare the number of job opennings (provide the exact number), the average salary within 15 miles of Dallas, TX, for these ocupations:\n",
"\n",
Expand All @@ -202,13 +204,12 @@
"\n",
"\n",
"# Create a table with your findings. Place the sources on each cell.\n",
"# Substitute `$` for `USD` in your final answer.\n",
"# \"\"\""
]
},
{
"cell_type": "code",
"execution_count": 54,
"execution_count": 7,
"id": "ca910f71-60fb-4758-b4a9-757e37eb421f",
"metadata": {},
"outputs": [
Expand All @@ -219,12 +220,12 @@
"The user is asking for current information about the global oil supply. I will need to perform a web search to gather the most recent data and facts on this topic.\n",
"Action: @bing\n",
"Action Input: What is happening with the oil supply in the world right now?\n",
"The search results provide some information about the current state of the global oil supply. It seems that the demand for oil may be peaking and is expected to plateau by 2028. There's also mention of oil prices falling due to profit-taking, and the increase in wind and solar power generation. However, to provide a more comprehensive answer, I should perform additional searches on the first two websites from the initial search.\n",
"The search results provide some information about the current state of the global oil supply. It seems that the demand for oil may be peaking and is expected to plateau by 2028. There's also mention of a shift towards renewable energy sources, with wind and solar power expected to account for more than a third of global electricity by 2030. Additionally, Canadian oil sands production has fully recovered from the COVID-19 pandemic and has exceeded pre-pandemic levels. However, there are still challenges due to lingering COVID impacts, pipeline constraints, and uncertainties related to the energy transition. I will now perform a second search on the first two websites from the initial search to gather more information.\n",
"Action: @bing\n",
"Action Input: site:https://news.harvard.edu/ What is happening with the oil supply in the world right now?\n",
"The search on the Harvard Gazette website provides additional context. It reiterates that the global demand for oil is expected to peak around 2026 and plateau by 2028. It also mentions that Russia is a major source of oil and natural gas to Europe, and any conflict could potentially impact the global supply chain. Now, I should perform a search on the second website from the initial search to gather more information.\n",
"Action Input: What is happening with the oil supply in the world right now? site:https://news.harvard.edu/\n",
"The second search on the Harvard Gazette website provides additional information about the global oil supply. It mentions that the conflict in Ukraine, a major source of oil and natural gas to Europe, could worsen existing pandemic-related inflation, supply chain delays, and labor shortages globally. There's also mention of the oil industry's role in discouraging climate action. I will now perform a third search on the second website from the initial search to gather more information.\n",
"Action: @bing\n",
"Action Input: site:https://www.reuters.com/ What is happening with the oil supply in the world right now?\n"
"Action Input: What is happening with the oil supply in the world right now? site:https://www.reuters.com/\n"
]
}
],
Expand All @@ -241,7 +242,7 @@
},
{
"cell_type": "code",
"execution_count": 55,
"execution_count": 8,
"id": "25a410b2-9950-43f5-8f14-b333bdc24ff2",
"metadata": {},
"outputs": [
Expand All @@ -250,13 +251,14 @@
"text/markdown": [
"Here are the main facts about the current state of the global oil supply:\n",
"\n",
"1. The global demand for oil is expected to peak around 2026 and plateau by 2028<sup><a href=\"https://news.harvard.edu/gazette/story/2023/07/energy-agency-says-global-thirst-for-oil-finally-may-be-topping-out/\" target=\"_blank\">[1]</a></sup>.\n",
"2. Oil prices have been falling due to profit-taking, but they still record a weekly gain<sup><a href=\"https://www.reuters.com/markets/commodities/oil-prices-up-tighter-supply-lower-us-inflation-2023-07-14/\" target=\"_blank\">[2]</a></sup>.\n",
"3. Oil supply disruptions globally have pushed Brent crude prices above USD 81 a barrel<sup><a href=\"https://www.reuters.com/business/energy/oil-supply-disruptions-boost-prices-2023-07-14/\" target=\"_blank\">[3]</a></sup>.\n",
"4. Oil prices have edged up due to high summer fuel demand while supplies remain tight because of sanctions on Russian oil<sup><a href=\"https://www.reuters.com/business/energy/oil-rises-market-caution-over-supply-concerns-2022-06-21/\" target=\"_blank\">[4]</a></sup>.\n",
"5. Russia, a major source of oil and natural gas to Europe, has warned that oil prices could surge to USD 300 a barrel if the West halts oil imports over the invasion of Ukraine<sup><a href=\"https://www.reuters.com/world/europe/ukraine-russia-what-you-need-know-right-now-2022-03-03/\" target=\"_blank\">[5]</a></sup>.\n",
"1. The demand for global oil, particularly for transport, is predicted to peak around 2026 and plateau for all uses by 2028<sup><a href=\"https://news.harvard.edu/gazette/story/2023/07/energy-agency-says-global-thirst-for-oil-finally-may-be-topping-out/\" target=\"_blank\">[1]</a></sup>.\n",
"2. Wind and solar power generation are expected to account for more than one-third of global electricity by 2030<sup><a href=\"https://oilprice.com/Latest-Energy-News/World-News/\" target=\"_blank\">[2]</a></sup>.\n",
"3. Canadian oil sands production has fully recovered from the COVID-19 pandemic and has exceeded pre-pandemic levels<sup><a href=\"https://www.spglobal.com/commodityinsights/en/ci/topic/global-crude-oil-supply-and-demand-forecast.html\" target=\"_blank\">[3]</a></sup>.\n",
"4. The conflict in Ukraine, a major source of oil and natural gas to Europe, could worsen existing pandemic-related inflation, supply chain delays, and labor shortages globally<sup><a href=\"https://news.harvard.edu/gazette/story/2022/02/how-invasion-may-hit-u-s-global-economies/\" target=\"_blank\">[4]</a></sup>.\n",
"5. A series of oil supply disruptions across the globe has helped push Brent crude prices above USD 81 a barrel<sup><a href=\"https://www.reuters.com/business/energy/oil-supply-disruptions-boost-prices-2023-07-14/\" target=\"_blank\">[5]</a></sup>.\n",
"6. Despite a shift towards renewable energy sources, the world is still heavily dependent on oil<sup><a href=\"https://www.reuters.com/business/energy/when-it-comes-oil-global-economy-is-still-hooked-2022-03-25/\" target=\"_blank\">[6]</a></sup>.\n",
"\n",
"Please let me know if you need more information on this or any other topic."
"Is there anything else you would like to know?"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
Expand Down Expand Up @@ -287,7 +289,7 @@
},
{
"cell_type": "code",
"execution_count": 50,
"execution_count": 9,
"id": "e925ee4a-d295-4815-9e8c-bd6999f48892",
"metadata": {},
"outputs": [],
Expand All @@ -300,20 +302,26 @@
},
{
"cell_type": "code",
"execution_count": 51,
"execution_count": 10,
"id": "099830a1-b81d-4698-a458-e84ccf3989cc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The user is asking for the main points from the latest investor report from Mondelez International. I will need to perform a web search to find this information. \n",
"The user is asking for the main points from the latest investor report from Mondelez International. I will need to search for this specific report on the Mondelez International website.\n",
"Action: @bing\n",
"Action Input: latest investor report site:mondelezinternational.com\n",
"The search results provide some highlights from the latest investor report of Mondelez International. However, to provide a more comprehensive answer, I should perform a second search on the first two websites from the initial search results.\n",
"The search results provide some information about the latest investor reports from Mondelez International. However, the snippets do not provide a comprehensive list of the main points from the latest report. I will need to perform a more specific search on the Mondelez International website to find the latest investor report and its main points.\n",
"Action: @bing\n",
"Action Input: site:ir.mondelezinternational.com latest investor report\n",
"The search results provide some highlights from the Q3 2022 results, but it's not clear if this is the latest investor report. I will need to perform another search to confirm the latest report and its main points.\n",
"Action: @bing\n",
"Action Input: site:ir.mondelezinternational.com news releases\n",
"The search results indicate that the latest report available is for Q4 and FY 2022. However, the snippets do not provide a comprehensive list of the main points from this report. I will need to perform another search to find the main points from the Q4 and FY 2022 report.\n",
"Action: @bing\n",
"Action Input: latest investor report site:https://www.mondelezinternational.com\n"
"Action Input: site:ir.mondelezinternational.com Q4 and FY 2022 Results\n"
]
}
],
Expand All @@ -330,22 +338,17 @@
},
{
"cell_type": "code",
"execution_count": 52,
"execution_count": 11,
"id": "89e67095-277d-45b6-84aa-acef0eb6cf5f",
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"The main points from the latest investor report from Mondelez International are:\n",
"- Net revenues increased by 8.0%, driven by Organic Net Revenue growth of 5.2%, favorable currency, and acquisitions.\n",
"- Diluted EPS was USD 3.04, up 23.1%.\n",
"- Adjusted EPS was USD 2.87, up 9.0% on a constant-currency basis.\n",
"- Cash provided by operating activities was USD 4.1 billion, an increase of USD 0.2 billion versus the prior year.\n",
"- Free Cash Flow was USD 3.2 billion, an increase of USD 0.1 billion<sup><a href=\"https://ir.mondelezinternational.com/news-releases/news-release-details/mondelez-international-reports-q4-and-fy-2021-results\" target=\"_blank\">[1]</a></sup>.\n",
"- The company had an excellent start to 2023 with compounding top- and bottom-line growth<sup><a href=\"https://www.mondelezinternational.com/News\" target=\"_blank\">[2]</a></sup>.\n",
"- Mondelez International declared a regular quarterly dividend of USD 0.385 per share<sup><a href=\"https://www.mondelezinternational.com/en/investors\" target=\"_blank\">[3]</a></sup>.\n",
"- The company is advancing its “Snacking Made Right” ESG Goals<sup><a href=\"https://www.mondelezinternational.com/en/investors\" target=\"_blank\">[3]</a></sup>.\n",
"The main points from the latest investor report from Mondelez International for Q4 and FY 2022 are as follows:\n",
"- Net revenues for the full year increased by 9.7%\n",
"- This increase was driven by Organic Net Revenue growth of 12.3%\n",
"- The underlying Volume/Mix was 2.7%<sup><a href=\"https://ir.mondelezinternational.com/news-releases/news-release-details/mondelez-international-reports-q4-and-fy-2022-results\" target=\"_blank\">[1]</a></sup>. \n",
"\n",
"Is there anything else you would like to know?"
],
Expand All @@ -363,12 +366,12 @@
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": 12,
"id": "9782fafa-9453-46be-b9d7-b33088f61ac8",
"metadata": {},
"outputs": [],
"source": [
"# Uncomment if you want to take a look at the custom bing search prompt\n",
"# Uncomment if you want to take a look at the custom bing search prompt (This is where the magic happens: a great system promp + GPT-4)\n",
"# printmd(agent_executor.agent.llm_chain.prompt.template)"
]
},
Expand Down Expand Up @@ -399,22 +402,6 @@
"\n",
"The Next Notebook will guide you on how we stick everything together. How do we use the features of all notebooks and create a brain agent that can respond to any request accordingly."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9dd82959-da57-472c-b412-e3fc62386dab",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "f3c21f31-93a0-43c6-b2c6-a1c335055838",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 5575292

Please sign in to comment.