You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

agentchat_auto_feedback_from_code_execution.ipynb 141 kB

2 years ago
2 years ago
raise error when msg is invalid; fix docstr; improve ResponsiveAgent; update doc and packaging; capture ipython output; find code blocks with llm when regex fails. (#1154) * autogen.agent -> autogen.agentchat * bug fix in portfolio * notebook * timeout * timeout * infer lang; close #1150 * timeout * message context * context handling * add sender to generate_reply * clean up the receive function * move mathchat to contrib * contrib * last_message * Add OptiGuide: agent and notebook * Optiguide notebook: add figures and URL 1. figures and code points to remote URL 2. simplify the prompt for the interpreter, because all information is already in the chat history. * Update name: Agent -> GenericAgent * Update notebook * Rename: GenericAgent -> ResponsiveAgent * Rebase to autogen.agentchat * OptiGuide: Comment, sytle, and notebook updates * simplify optiguide * raise error when msg is invalid; fix docstr * allow return None for generate_reply() * update_system_message * test update_system_message * simplify optiguide * simplify optiguide * simplify optiguide * simplify optiguide * move test * add test and fix bug * doc update * doc update * doc update * color * optiguide * prompt * test danger case * packaging * docker * remove path in traceback * capture ipython output * simplify * find code blocks with llm * find code with llm * order * order * fix bug in context handling * print executing msg * print executing msg * test find code * test find code * disable find_code * default_auto_reply * default auto reply * remove optiguide * remove -e --------- Co-authored-by: Beibin Li <beibin79@gmail.com>
3 years ago
raise error when msg is invalid; fix docstr; improve ResponsiveAgent; update doc and packaging; capture ipython output; find code blocks with llm when regex fails. (#1154) * autogen.agent -> autogen.agentchat * bug fix in portfolio * notebook * timeout * timeout * infer lang; close #1150 * timeout * message context * context handling * add sender to generate_reply * clean up the receive function * move mathchat to contrib * contrib * last_message * Add OptiGuide: agent and notebook * Optiguide notebook: add figures and URL 1. figures and code points to remote URL 2. simplify the prompt for the interpreter, because all information is already in the chat history. * Update name: Agent -> GenericAgent * Update notebook * Rename: GenericAgent -> ResponsiveAgent * Rebase to autogen.agentchat * OptiGuide: Comment, sytle, and notebook updates * simplify optiguide * raise error when msg is invalid; fix docstr * allow return None for generate_reply() * update_system_message * test update_system_message * simplify optiguide * simplify optiguide * simplify optiguide * simplify optiguide * move test * add test and fix bug * doc update * doc update * doc update * color * optiguide * prompt * test danger case * packaging * docker * remove path in traceback * capture ipython output * simplify * find code blocks with llm * find code with llm * order * order * fix bug in context handling * print executing msg * print executing msg * test find code * test find code * disable find_code * default_auto_reply * default auto reply * remove optiguide * remove -e --------- Co-authored-by: Beibin Li <beibin79@gmail.com>
3 years ago
raise error when msg is invalid; fix docstr; improve ResponsiveAgent; update doc and packaging; capture ipython output; find code blocks with llm when regex fails. (#1154) * autogen.agent -> autogen.agentchat * bug fix in portfolio * notebook * timeout * timeout * infer lang; close #1150 * timeout * message context * context handling * add sender to generate_reply * clean up the receive function * move mathchat to contrib * contrib * last_message * Add OptiGuide: agent and notebook * Optiguide notebook: add figures and URL 1. figures and code points to remote URL 2. simplify the prompt for the interpreter, because all information is already in the chat history. * Update name: Agent -> GenericAgent * Update notebook * Rename: GenericAgent -> ResponsiveAgent * Rebase to autogen.agentchat * OptiGuide: Comment, sytle, and notebook updates * simplify optiguide * raise error when msg is invalid; fix docstr * allow return None for generate_reply() * update_system_message * test update_system_message * simplify optiguide * simplify optiguide * simplify optiguide * simplify optiguide * move test * add test and fix bug * doc update * doc update * doc update * color * optiguide * prompt * test danger case * packaging * docker * remove path in traceback * capture ipython output * simplify * find code blocks with llm * find code with llm * order * order * fix bug in context handling * print executing msg * print executing msg * test find code * test find code * disable find_code * default_auto_reply * default auto reply * remove optiguide * remove -e --------- Co-authored-by: Beibin Li <beibin79@gmail.com>
3 years ago
raise error when msg is invalid; fix docstr; improve ResponsiveAgent; update doc and packaging; capture ipython output; find code blocks with llm when regex fails. (#1154) * autogen.agent -> autogen.agentchat * bug fix in portfolio * notebook * timeout * timeout * infer lang; close #1150 * timeout * message context * context handling * add sender to generate_reply * clean up the receive function * move mathchat to contrib * contrib * last_message * Add OptiGuide: agent and notebook * Optiguide notebook: add figures and URL 1. figures and code points to remote URL 2. simplify the prompt for the interpreter, because all information is already in the chat history. * Update name: Agent -> GenericAgent * Update notebook * Rename: GenericAgent -> ResponsiveAgent * Rebase to autogen.agentchat * OptiGuide: Comment, sytle, and notebook updates * simplify optiguide * raise error when msg is invalid; fix docstr * allow return None for generate_reply() * update_system_message * test update_system_message * simplify optiguide * simplify optiguide * simplify optiguide * simplify optiguide * move test * add test and fix bug * doc update * doc update * doc update * color * optiguide * prompt * test danger case * packaging * docker * remove path in traceback * capture ipython output * simplify * find code blocks with llm * find code with llm * order * order * fix bug in context handling * print executing msg * print executing msg * test find code * test find code * disable find_code * default_auto_reply * default auto reply * remove optiguide * remove -e --------- Co-authored-by: Beibin Li <beibin79@gmail.com>
3 years ago
raise error when msg is invalid; fix docstr; improve ResponsiveAgent; update doc and packaging; capture ipython output; find code blocks with llm when regex fails. (#1154) * autogen.agent -> autogen.agentchat * bug fix in portfolio * notebook * timeout * timeout * infer lang; close #1150 * timeout * message context * context handling * add sender to generate_reply * clean up the receive function * move mathchat to contrib * contrib * last_message * Add OptiGuide: agent and notebook * Optiguide notebook: add figures and URL 1. figures and code points to remote URL 2. simplify the prompt for the interpreter, because all information is already in the chat history. * Update name: Agent -> GenericAgent * Update notebook * Rename: GenericAgent -> ResponsiveAgent * Rebase to autogen.agentchat * OptiGuide: Comment, sytle, and notebook updates * simplify optiguide * raise error when msg is invalid; fix docstr * allow return None for generate_reply() * update_system_message * test update_system_message * simplify optiguide * simplify optiguide * simplify optiguide * simplify optiguide * move test * add test and fix bug * doc update * doc update * doc update * color * optiguide * prompt * test danger case * packaging * docker * remove path in traceback * capture ipython output * simplify * find code blocks with llm * find code with llm * order * order * fix bug in context handling * print executing msg * print executing msg * test find code * test find code * disable find_code * default_auto_reply * default auto reply * remove optiguide * remove -e --------- Co-authored-by: Beibin Li <beibin79@gmail.com>
3 years ago
raise error when msg is invalid; fix docstr; improve ResponsiveAgent; update doc and packaging; capture ipython output; find code blocks with llm when regex fails. (#1154) * autogen.agent -> autogen.agentchat * bug fix in portfolio * notebook * timeout * timeout * infer lang; close #1150 * timeout * message context * context handling * add sender to generate_reply * clean up the receive function * move mathchat to contrib * contrib * last_message * Add OptiGuide: agent and notebook * Optiguide notebook: add figures and URL 1. figures and code points to remote URL 2. simplify the prompt for the interpreter, because all information is already in the chat history. * Update name: Agent -> GenericAgent * Update notebook * Rename: GenericAgent -> ResponsiveAgent * Rebase to autogen.agentchat * OptiGuide: Comment, sytle, and notebook updates * simplify optiguide * raise error when msg is invalid; fix docstr * allow return None for generate_reply() * update_system_message * test update_system_message * simplify optiguide * simplify optiguide * simplify optiguide * simplify optiguide * move test * add test and fix bug * doc update * doc update * doc update * color * optiguide * prompt * test danger case * packaging * docker * remove path in traceback * capture ipython output * simplify * find code blocks with llm * find code with llm * order * order * fix bug in context handling * print executing msg * print executing msg * test find code * test find code * disable find_code * default_auto_reply * default auto reply * remove optiguide * remove -e --------- Co-authored-by: Beibin Li <beibin79@gmail.com>
3 years ago
raise error when msg is invalid; fix docstr; improve ResponsiveAgent; update doc and packaging; capture ipython output; find code blocks with llm when regex fails. (#1154) * autogen.agent -> autogen.agentchat * bug fix in portfolio * notebook * timeout * timeout * infer lang; close #1150 * timeout * message context * context handling * add sender to generate_reply * clean up the receive function * move mathchat to contrib * contrib * last_message * Add OptiGuide: agent and notebook * Optiguide notebook: add figures and URL 1. figures and code points to remote URL 2. simplify the prompt for the interpreter, because all information is already in the chat history. * Update name: Agent -> GenericAgent * Update notebook * Rename: GenericAgent -> ResponsiveAgent * Rebase to autogen.agentchat * OptiGuide: Comment, sytle, and notebook updates * simplify optiguide * raise error when msg is invalid; fix docstr * allow return None for generate_reply() * update_system_message * test update_system_message * simplify optiguide * simplify optiguide * simplify optiguide * simplify optiguide * move test * add test and fix bug * doc update * doc update * doc update * color * optiguide * prompt * test danger case * packaging * docker * remove path in traceback * capture ipython output * simplify * find code blocks with llm * find code with llm * order * order * fix bug in context handling * print executing msg * print executing msg * test find code * test find code * disable find_code * default_auto_reply * default auto reply * remove optiguide * remove -e --------- Co-authored-by: Beibin Li <beibin79@gmail.com>
3 years ago
raise error when msg is invalid; fix docstr; improve ResponsiveAgent; update doc and packaging; capture ipython output; find code blocks with llm when regex fails. (#1154) * autogen.agent -> autogen.agentchat * bug fix in portfolio * notebook * timeout * timeout * infer lang; close #1150 * timeout * message context * context handling * add sender to generate_reply * clean up the receive function * move mathchat to contrib * contrib * last_message * Add OptiGuide: agent and notebook * Optiguide notebook: add figures and URL 1. figures and code points to remote URL 2. simplify the prompt for the interpreter, because all information is already in the chat history. * Update name: Agent -> GenericAgent * Update notebook * Rename: GenericAgent -> ResponsiveAgent * Rebase to autogen.agentchat * OptiGuide: Comment, sytle, and notebook updates * simplify optiguide * raise error when msg is invalid; fix docstr * allow return None for generate_reply() * update_system_message * test update_system_message * simplify optiguide * simplify optiguide * simplify optiguide * simplify optiguide * move test * add test and fix bug * doc update * doc update * doc update * color * optiguide * prompt * test danger case * packaging * docker * remove path in traceback * capture ipython output * simplify * find code blocks with llm * find code with llm * order * order * fix bug in context handling * print executing msg * print executing msg * test find code * test find code * disable find_code * default_auto_reply * default auto reply * remove optiguide * remove -e --------- Co-authored-by: Beibin Li <beibin79@gmail.com>
3 years ago
raise error when msg is invalid; fix docstr; improve ResponsiveAgent; update doc and packaging; capture ipython output; find code blocks with llm when regex fails. (#1154) * autogen.agent -> autogen.agentchat * bug fix in portfolio * notebook * timeout * timeout * infer lang; close #1150 * timeout * message context * context handling * add sender to generate_reply * clean up the receive function * move mathchat to contrib * contrib * last_message * Add OptiGuide: agent and notebook * Optiguide notebook: add figures and URL 1. figures and code points to remote URL 2. simplify the prompt for the interpreter, because all information is already in the chat history. * Update name: Agent -> GenericAgent * Update notebook * Rename: GenericAgent -> ResponsiveAgent * Rebase to autogen.agentchat * OptiGuide: Comment, sytle, and notebook updates * simplify optiguide * raise error when msg is invalid; fix docstr * allow return None for generate_reply() * update_system_message * test update_system_message * simplify optiguide * simplify optiguide * simplify optiguide * simplify optiguide * move test * add test and fix bug * doc update * doc update * doc update * color * optiguide * prompt * test danger case * packaging * docker * remove path in traceback * capture ipython output * simplify * find code blocks with llm * find code with llm * order * order * fix bug in context handling * print executing msg * print executing msg * test find code * test find code * disable find_code * default_auto_reply * default auto reply * remove optiguide * remove -e --------- Co-authored-by: Beibin Li <beibin79@gmail.com>
3 years ago
raise error when msg is invalid; fix docstr; improve ResponsiveAgent; update doc and packaging; capture ipython output; find code blocks with llm when regex fails. (#1154) * autogen.agent -> autogen.agentchat * bug fix in portfolio * notebook * timeout * timeout * infer lang; close #1150 * timeout * message context * context handling * add sender to generate_reply * clean up the receive function * move mathchat to contrib * contrib * last_message * Add OptiGuide: agent and notebook * Optiguide notebook: add figures and URL 1. figures and code points to remote URL 2. simplify the prompt for the interpreter, because all information is already in the chat history. * Update name: Agent -> GenericAgent * Update notebook * Rename: GenericAgent -> ResponsiveAgent * Rebase to autogen.agentchat * OptiGuide: Comment, sytle, and notebook updates * simplify optiguide * raise error when msg is invalid; fix docstr * allow return None for generate_reply() * update_system_message * test update_system_message * simplify optiguide * simplify optiguide * simplify optiguide * simplify optiguide * move test * add test and fix bug * doc update * doc update * doc update * color * optiguide * prompt * test danger case * packaging * docker * remove path in traceback * capture ipython output * simplify * find code blocks with llm * find code with llm * order * order * fix bug in context handling * print executing msg * print executing msg * test find code * test find code * disable find_code * default_auto_reply * default auto reply * remove optiguide * remove -e --------- Co-authored-by: Beibin Li <beibin79@gmail.com>
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {
  6. "slideshow": {
  7. "slide_type": "slide"
  8. }
  9. },
  10. "source": [
  11. "# Task Solving with Code Generation, Execution and Debugging\n",
  12. "\n",
  13. "In this notebook, we demonstrate how to use `AssistantAgent` and `UserProxyAgent` to write code and execute the code. Here `AssistantAgent` is an LLM-based agent that can write Python code (in a Python coding block) for a user to execute for a given task. `UserProxyAgent` is an agent which serves as a proxy for the human user to execute the code written by `AssistantAgent`, or automatically execute the code. Depending on the setting of `human_input_mode` and `max_consecutive_auto_reply`, the `UserProxyAgent` either solicits feedback from the human user or returns auto-feedback based on the result of code execution (success or failure and corresponding outputs) to `AssistantAgent`. `AssistantAgent` will debug the code and suggest new code if the result contains error. The two agents keep communicating to each other until the task is done.\n",
  14. "\n",
  15. "````{=mdx}\n",
  16. ":::info Requirements\n",
  17. "Install the following packages before running the code below:\n",
  18. "```bash\n",
  19. "pip install pyautogen matplotlib yfinance\n",
  20. "```\n",
  21. "\n",
  22. "For more information, please refer to the [installation guide](/docs/installation/).\n",
  23. ":::\n",
  24. "````"
  25. ]
  26. },
  27. {
  28. "cell_type": "code",
  29. "execution_count": 2,
  30. "metadata": {},
  31. "outputs": [],
  32. "source": [
  33. "from IPython.display import Image, display\n",
  34. "\n",
  35. "import autogen\n",
  36. "from autogen.coding import LocalCommandLineCodeExecutor\n",
  37. "\n",
  38. "config_list = autogen.config_list_from_json(\n",
  39. " \"OAI_CONFIG_LIST\",\n",
  40. " filter_dict={\"tags\": [\"gpt-4\"]}, # comment out to get all\n",
  41. ")\n",
  42. "# When using a single openai endpoint, you can use the following:\n",
  43. "# config_list = [{\"model\": \"gpt-4\", \"api_key\": os.getenv(\"OPENAI_API_KEY\")}]\n"
  44. ]
  45. },
  46. {
  47. "attachments": {},
  48. "cell_type": "markdown",
  49. "metadata": {},
  50. "source": [
  51. "## Example Task: Check Stock Price Change\n",
  52. "\n",
  53. "In the example below, let's see how to use the agents in AutoGen to write a python script and execute the script. This process involves constructing a `AssistantAgent` to serve as the assistant, along with a `UserProxyAgent` that acts as a proxy for the human user. In this example demonstrated below, when constructing the `UserProxyAgent`, we select the `human_input_mode` to \"NEVER\". This means that the `UserProxyAgent` will not solicit feedback from the human user. It stops replying when the limit defined by `max_consecutive_auto_reply` is reached, or when `is_termination_msg()` returns true for the received message."
  54. ]
  55. },
  56. {
  57. "cell_type": "code",
  58. "execution_count": 3,
  59. "metadata": {},
  60. "outputs": [
  61. {
  62. "name": "stdout",
  63. "output_type": "stream",
  64. "text": [
  65. "\u001b[33muser_proxy\u001b[0m (to assistant):\n",
  66. "\n",
  67. "What date is today? Compare the year-to-date gain for META and TESLA.\n",
  68. "\n",
  69. "--------------------------------------------------------------------------------\n",
  70. "\u001b[33massistant\u001b[0m (to user_proxy):\n",
  71. "\n",
  72. "First, let's get the current date using Python. \n",
  73. "\n",
  74. "```python\n",
  75. "# Python code\n",
  76. "from datetime import date\n",
  77. "\n",
  78. "# Get today's date\n",
  79. "today = date.today()\n",
  80. "\n",
  81. "# Print today's date\n",
  82. "print(\"Today's date:\", today)\n",
  83. "```\n",
  84. "\n",
  85. "Next, we need to fetch the stock prices for META (Facebook) and TESLA for the current year. We can use the `yfinance` library in Python to fetch this data. If `yfinance` is not installed, it can be installed using pip: `pip install yfinance`.\n",
  86. "\n",
  87. "Here is the Python code to fetch the stock prices and calculate the year-to-date gain:\n",
  88. "\n",
  89. "```python\n",
  90. "# Python code\n",
  91. "import yfinance as yf\n",
  92. "from datetime import datetime\n",
  93. "\n",
  94. "# Get the current year\n",
  95. "current_year = datetime.now().year\n",
  96. "\n",
  97. "# Download stock data for the current year\n",
  98. "meta_data = yf.download('FB', start=f'{current_year}-01-01', end=today)\n",
  99. "tesla_data = yf.download('TSLA', start=f'{current_year}-01-01', end=today)\n",
  100. "\n",
  101. "# Calculate the year-to-date gain for each stock\n",
  102. "meta_ytd_gain = ((meta_data['Close'][-1] - meta_data['Close'][0]) / meta_data['Close'][0]) * 100\n",
  103. "tesla_ytd_gain = ((tesla_data['Close'][-1] - tesla_data['Close'][0]) / tesla_data['Close'][0]) * 100\n",
  104. "\n",
  105. "# Print the year-to-date gain for each stock\n",
  106. "print(f'META year-to-date gain: {meta_ytd_gain}%')\n",
  107. "print(f'TESLA year-to-date gain: {tesla_ytd_gain}%')\n",
  108. "```\n",
  109. "\n",
  110. "This code fetches the closing prices for META and TESLA for the current year, calculates the year-to-date gain for each stock, and prints the results. The year-to-date gain is calculated as the percentage change in the closing price from the first trading day of the year to the most recent trading day.\n",
  111. "\n",
  112. "--------------------------------------------------------------------------------\n",
  113. "\u001b[31m\n",
  114. ">>>>>>>> EXECUTING 2 CODE BLOCKS (inferred languages are [python, python])...\u001b[0m\n",
  115. "\u001b[33muser_proxy\u001b[0m (to assistant):\n",
  116. "\n",
  117. "exitcode: 1 (execution failed)\n",
  118. "Code output: Today's date: 2024-04-12\n",
  119. "Traceback (most recent call last):\n",
  120. " File \"/Users/ekzhu/autogen/notebook/coding/tmp_code_cb9ef30baa23cf28e127198c0ebeb7e6.py\", line 9, in <module>\n",
  121. " meta_data = yf.download('FB', start=f'{current_year}-01-01', end=today)\n",
  122. " ^^^^^\n",
  123. "NameError: name 'today' is not defined\n",
  124. "\n",
  125. "\n",
  126. "--------------------------------------------------------------------------------\n",
  127. "\u001b[33massistant\u001b[0m (to user_proxy):\n",
  128. "\n",
  129. "I apologize for the oversight. The variable `today` was defined in the first code block but not in the second one. Let's correct this by defining `today` in the second code block as well. Here's the corrected code:\n",
  130. "\n",
  131. "```python\n",
  132. "# Python code\n",
  133. "import yfinance as yf\n",
  134. "from datetime import datetime, date\n",
  135. "\n",
  136. "# Get the current year and today's date\n",
  137. "current_year = datetime.now().year\n",
  138. "today = date.today()\n",
  139. "\n",
  140. "# Download stock data for the current year\n",
  141. "meta_data = yf.download('FB', start=f'{current_year}-01-01', end=today)\n",
  142. "tesla_data = yf.download('TSLA', start=f'{current_year}-01-01', end=today)\n",
  143. "\n",
  144. "# Calculate the year-to-date gain for each stock\n",
  145. "meta_ytd_gain = ((meta_data['Close'][-1] - meta_data['Close'][0]) / meta_data['Close'][0]) * 100\n",
  146. "tesla_ytd_gain = ((tesla_data['Close'][-1] - tesla_data['Close'][0]) / tesla_data['Close'][0]) * 100\n",
  147. "\n",
  148. "# Print the year-to-date gain for each stock\n",
  149. "print(f'META year-to-date gain: {meta_ytd_gain}%')\n",
  150. "print(f'TESLA year-to-date gain: {tesla_ytd_gain}%')\n",
  151. "```\n",
  152. "\n",
  153. "This code should now correctly fetch the stock prices for META and TESLA, calculate the year-to-date gain for each, and print the results.\n",
  154. "\n",
  155. "--------------------------------------------------------------------------------\n",
  156. "\u001b[31m\n",
  157. ">>>>>>>> EXECUTING CODE BLOCK (inferred language is python)...\u001b[0m\n",
  158. "\u001b[33muser_proxy\u001b[0m (to assistant):\n",
  159. "\n",
  160. "exitcode: 1 (execution failed)\n",
  161. "Code output: \n",
  162. "[*********************100%%**********************] 1 of 1 completed\n",
  163. "\n",
  164. "1 Failed download:\n",
  165. "['FB']: Exception('%ticker%: No timezone found, symbol may be delisted')\n",
  166. "/Users/ekzhu/miniconda3/envs/autogen/lib/python3.11/site-packages/yfinance/utils.py:775: FutureWarning: The 'unit' keyword in TimedeltaIndex construction is deprecated and will be removed in a future version. Use pd.to_timedelta instead.\n",
  167. " df.index += _pd.TimedeltaIndex(dst_error_hours, 'h')\n",
  168. "\n",
  169. "[*********************100%%**********************] 1 of 1 completed\n",
  170. "/Users/ekzhu/autogen/notebook/coding/tmp_code_9ca584c3d8b484c70ee49c1ce5e4b975.py:14: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
  171. " meta_ytd_gain = ((meta_data['Close'][-1] - meta_data['Close'][0]) / meta_data['Close'][0]) * 100\n",
  172. "Traceback (most recent call last):\n",
  173. " File \"/Users/ekzhu/autogen/notebook/coding/tmp_code_9ca584c3d8b484c70ee49c1ce5e4b975.py\", line 14, in <module>\n",
  174. " meta_ytd_gain = ((meta_data['Close'][-1] - meta_data['Close'][0]) / meta_data['Close'][0]) * 100\n",
  175. " ~~~~~~~~~~~~~~~~~~^^^^\n",
  176. " File \"/Users/ekzhu/miniconda3/envs/autogen/lib/python3.11/site-packages/pandas/core/series.py\", line 1109, in __getitem__\n",
  177. " return self._values[key]\n",
  178. " ~~~~~~~~~~~~^^^^^\n",
  179. "IndexError: index -1 is out of bounds for axis 0 with size 0\n",
  180. "\n",
  181. "\n",
  182. "--------------------------------------------------------------------------------\n",
  183. "\u001b[33massistant\u001b[0m (to user_proxy):\n",
  184. "\n",
  185. "I apologize for the confusion. It seems like the ticker symbol for Meta Platforms Inc. (formerly Facebook) has changed from 'FB' to 'META'. Let's correct this in the code. Also, it seems like the data for the current day might not be available yet, so let's fetch the data until the previous day. Here's the corrected code:\n",
  186. "\n",
  187. "```python\n",
  188. "# Python code\n",
  189. "import yfinance as yf\n",
  190. "from datetime import datetime, timedelta\n",
  191. "\n",
  192. "# Get the current year and yesterday's date\n",
  193. "current_year = datetime.now().year\n",
  194. "yesterday = datetime.now() - timedelta(1)\n",
  195. "\n",
  196. "# Download stock data for the current year\n",
  197. "meta_data = yf.download('META', start=f'{current_year}-01-01', end=yesterday)\n",
  198. "tesla_data = yf.download('TSLA', start=f'{current_year}-01-01', end=yesterday)\n",
  199. "\n",
  200. "# Calculate the year-to-date gain for each stock\n",
  201. "meta_ytd_gain = ((meta_data['Close'][-1] - meta_data['Close'][0]) / meta_data['Close'][0]) * 100\n",
  202. "tesla_ytd_gain = ((tesla_data['Close'][-1] - tesla_data['Close'][0]) / tesla_data['Close'][0]) * 100\n",
  203. "\n",
  204. "# Print the year-to-date gain for each stock\n",
  205. "print(f'META year-to-date gain: {meta_ytd_gain}%')\n",
  206. "print(f'TESLA year-to-date gain: {tesla_ytd_gain}%')\n",
  207. "```\n",
  208. "\n",
  209. "This code should now correctly fetch the stock prices for META and TESLA, calculate the year-to-date gain for each, and print the results.\n",
  210. "\n",
  211. "--------------------------------------------------------------------------------\n",
  212. "\u001b[31m\n",
  213. ">>>>>>>> EXECUTING CODE BLOCK (inferred language is python)...\u001b[0m\n",
  214. "\u001b[33muser_proxy\u001b[0m (to assistant):\n",
  215. "\n",
  216. "exitcode: 0 (execution succeeded)\n",
  217. "Code output: /Users/ekzhu/miniconda3/envs/autogen/lib/python3.11/site-packages/yfinance/utils.py:775: FutureWarning: The 'unit' keyword in TimedeltaIndex construction is deprecated and will be removed in a future version. Use pd.to_timedelta instead.\n",
  218. " df.index += _pd.TimedeltaIndex(dst_error_hours, 'h')\n",
  219. "\n",
  220. "[*********************100%%**********************] 1 of 1 completed\n",
  221. "/Users/ekzhu/miniconda3/envs/autogen/lib/python3.11/site-packages/yfinance/utils.py:775: FutureWarning: The 'unit' keyword in TimedeltaIndex construction is deprecated and will be removed in a future version. Use pd.to_timedelta instead.\n",
  222. " df.index += _pd.TimedeltaIndex(dst_error_hours, 'h')\n",
  223. "\n",
  224. "[*********************100%%**********************] 1 of 1 completed\n",
  225. "/Users/ekzhu/autogen/notebook/coding/tmp_code_0b52d7fcfe06d76c8b1e0ce9333cb5cf.py:14: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
  226. " meta_ytd_gain = ((meta_data['Close'][-1] - meta_data['Close'][0]) / meta_data['Close'][0]) * 100\n",
  227. "/Users/ekzhu/autogen/notebook/coding/tmp_code_0b52d7fcfe06d76c8b1e0ce9333cb5cf.py:15: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
  228. " tesla_ytd_gain = ((tesla_data['Close'][-1] - tesla_data['Close'][0]) / tesla_data['Close'][0]) * 100\n",
  229. "META year-to-date gain: 50.11406747602124%\n",
  230. "TESLA year-to-date gain: -30.85903076529873%\n",
  231. "\n",
  232. "\n",
  233. "--------------------------------------------------------------------------------\n",
  234. "\u001b[33massistant\u001b[0m (to user_proxy):\n",
  235. "\n",
  236. "The code has successfully fetched the stock prices for META and TESLA and calculated the year-to-date gain for each. \n",
  237. "\n",
  238. "As of yesterday, the year-to-date gain for META (Meta Platforms Inc.) is approximately 50.11%, and for TESLA (Tesla Inc.) it is approximately -30.86%. This means that so far this year, META's stock price has increased by about 50.11% while TESLA's stock price has decreased by about 30.86%.\n",
  239. "\n",
  240. "Please note that stock prices can fluctuate and the exact gain may vary depending on the time of checking.\n",
  241. "\n",
  242. "TERMINATE\n",
  243. "\n",
  244. "--------------------------------------------------------------------------------\n"
  245. ]
  246. }
  247. ],
  248. "source": [
  249. "# create an AssistantAgent named \"assistant\"\n",
  250. "assistant = autogen.AssistantAgent(\n",
  251. " name=\"assistant\",\n",
  252. " llm_config={\n",
  253. " \"cache_seed\": 41, # seed for caching and reproducibility\n",
  254. " \"config_list\": config_list, # a list of OpenAI API configurations\n",
  255. " \"temperature\": 0, # temperature for sampling\n",
  256. " }, # configuration for autogen's enhanced inference API which is compatible with OpenAI API\n",
  257. ")\n",
  258. "\n",
  259. "# create a UserProxyAgent instance named \"user_proxy\"\n",
  260. "user_proxy = autogen.UserProxyAgent(\n",
  261. " name=\"user_proxy\",\n",
  262. " human_input_mode=\"NEVER\",\n",
  263. " max_consecutive_auto_reply=10,\n",
  264. " is_termination_msg=lambda x: x.get(\"content\", \"\").rstrip().endswith(\"TERMINATE\"),\n",
  265. " code_execution_config={\n",
  266. " # the executor to run the generated code\n",
  267. " \"executor\": LocalCommandLineCodeExecutor(work_dir=\"coding\"),\n",
  268. " },\n",
  269. ")\n",
  270. "# the assistant receives a message from the user_proxy, which contains the task description\n",
  271. "chat_res = user_proxy.initiate_chat(\n",
  272. " assistant,\n",
  273. " message=\"\"\"What date is today? Compare the year-to-date gain for META and TESLA.\"\"\",\n",
  274. " summary_method=\"reflection_with_llm\",\n",
  275. ")"
  276. ]
  277. },
  278. {
  279. "attachments": {},
  280. "cell_type": "markdown",
  281. "metadata": {},
  282. "source": [
  283. "The example above involves code execution. In AutoGen, code execution is triggered automatically by the `UserProxyAgent` when it detects an executable code block in a received message and no human user input is provided. \n",
  284. "Users have the option to specify a different working directory by setting the `work_dir` argument when constructing a new instance of the `LocalCommandLineCodeExecutor`.\n",
  285. "For Docker-based or Jupyter kernel-based code execution, please refer to \n",
  286. "[Code Executors Tutorial](/docs/tutorial/code-executors) for more information."
  287. ]
  288. },
  289. {
  290. "cell_type": "markdown",
  291. "metadata": {},
  292. "source": [
  293. "#### Check chat results\n",
  294. "The `initiate_chat` method returns a `ChatResult` object, which is a dataclass object storing information about the chat. Currently, it includes the following attributes:\n",
  295. "\n",
  296. "- `chat_history`: a list of chat history.\n",
  297. "- `summary`: a string of chat summary. A summary is only available if a summary_method is provided when initiating the chat.\n",
  298. "- `cost`: a tuple of (total_cost, total_actual_cost), where total_cost is a dictionary of cost information, and total_actual_cost is a dictionary of information on the actual incurred cost with cache.\n",
  299. "- `human_input`: a list of strings of human inputs solicited during the chat. (Note that since we are setting `human_input_mode` to `NEVER` in this notebook, this list is always empty.)"
  300. ]
  301. },
  302. {
  303. "cell_type": "code",
  304. "execution_count": 4,
  305. "metadata": {},
  306. "outputs": [
  307. {
  308. "name": "stdout",
  309. "output_type": "stream",
  310. "text": [
  311. "Chat history: [{'content': 'What date is today? Compare the year-to-date gain for META and TESLA.', 'role': 'assistant'}, {'content': 'First, let\\'s get the current date using Python. \\n\\n```python\\n# Python code\\nfrom datetime import date\\n\\n# Get today\\'s date\\ntoday = date.today()\\n\\n# Print today\\'s date\\nprint(\"Today\\'s date:\", today)\\n```\\n\\nNext, we need to fetch the stock prices for META (Facebook) and TESLA for the current year. We can use the `yfinance` library in Python to fetch this data. If `yfinance` is not installed, it can be installed using pip: `pip install yfinance`.\\n\\nHere is the Python code to fetch the stock prices and calculate the year-to-date gain:\\n\\n```python\\n# Python code\\nimport yfinance as yf\\nfrom datetime import datetime\\n\\n# Get the current year\\ncurrent_year = datetime.now().year\\n\\n# Download stock data for the current year\\nmeta_data = yf.download(\\'FB\\', start=f\\'{current_year}-01-01\\', end=today)\\ntesla_data = yf.download(\\'TSLA\\', start=f\\'{current_year}-01-01\\', end=today)\\n\\n# Calculate the year-to-date gain for each stock\\nmeta_ytd_gain = ((meta_data[\\'Close\\'][-1] - meta_data[\\'Close\\'][0]) / meta_data[\\'Close\\'][0]) * 100\\ntesla_ytd_gain = ((tesla_data[\\'Close\\'][-1] - tesla_data[\\'Close\\'][0]) / tesla_data[\\'Close\\'][0]) * 100\\n\\n# Print the year-to-date gain for each stock\\nprint(f\\'META year-to-date gain: {meta_ytd_gain}%\\')\\nprint(f\\'TESLA year-to-date gain: {tesla_ytd_gain}%\\')\\n```\\n\\nThis code fetches the closing prices for META and TESLA for the current year, calculates the year-to-date gain for each stock, and prints the results. The year-to-date gain is calculated as the percentage change in the closing price from the first trading day of the year to the most recent trading day.', 'role': 'user'}, {'content': 'exitcode: 1 (execution failed)\\nCode output: Today\\'s date: 2024-04-12\\nTraceback (most recent call last):\\n File \"/Users/ekzhu/autogen/notebook/coding/tmp_code_cb9ef30baa23cf28e127198c0ebeb7e6.py\", line 9, in <module>\\n meta_data = yf.download(\\'FB\\', start=f\\'{current_year}-01-01\\', end=today)\\n ^^^^^\\nNameError: name \\'today\\' is not defined\\n', 'role': 'assistant'}, {'content': \"I apologize for the oversight. The variable `today` was defined in the first code block but not in the second one. Let's correct this by defining `today` in the second code block as well. Here's the corrected code:\\n\\n```python\\n# Python code\\nimport yfinance as yf\\nfrom datetime import datetime, date\\n\\n# Get the current year and today's date\\ncurrent_year = datetime.now().year\\ntoday = date.today()\\n\\n# Download stock data for the current year\\nmeta_data = yf.download('FB', start=f'{current_year}-01-01', end=today)\\ntesla_data = yf.download('TSLA', start=f'{current_year}-01-01', end=today)\\n\\n# Calculate the year-to-date gain for each stock\\nmeta_ytd_gain = ((meta_data['Close'][-1] - meta_data['Close'][0]) / meta_data['Close'][0]) * 100\\ntesla_ytd_gain = ((tesla_data['Close'][-1] - tesla_data['Close'][0]) / tesla_data['Close'][0]) * 100\\n\\n# Print the year-to-date gain for each stock\\nprint(f'META year-to-date gain: {meta_ytd_gain}%')\\nprint(f'TESLA year-to-date gain: {tesla_ytd_gain}%')\\n```\\n\\nThis code should now correctly fetch the stock prices for META and TESLA, calculate the year-to-date gain for each, and print the results.\", 'role': 'user'}, {'content': 'exitcode: 1 (execution failed)\\nCode output: \\n[*********************100%%**********************] 1 of 1 completed\\n\\n1 Failed download:\\n[\\'FB\\']: Exception(\\'%ticker%: No timezone found, symbol may be delisted\\')\\n/Users/ekzhu/miniconda3/envs/autogen/lib/python3.11/site-packages/yfinance/utils.py:775: FutureWarning: The \\'unit\\' keyword in TimedeltaIndex construction is deprecated and will be removed in a future version. Use pd.to_timedelta instead.\\n df.index += _pd.TimedeltaIndex(dst_error_hours, \\'h\\')\\n\\n[*********************100%%**********************] 1 of 1 completed\\n/Users/ekzhu/autogen/notebook/coding/tmp_code_9ca584c3d8b484c70ee49c1ce5e4b975.py:14: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\\n meta_ytd_gain = ((meta_data[\\'Close\\'][-1] - meta_data[\\'Close\\'][0]) / meta_data[\\'Close\\'][0]) * 100\\nTraceback (most recent call last):\\n File \"/Users/ekzhu/autogen/notebook/coding/tmp_code_9ca584c3d8b484c70ee49c1ce5e4b975.py\", line 14, in <module>\\n meta_ytd_gain = ((meta_data[\\'Close\\'][-1] - meta_data[\\'Close\\'][0]) / meta_data[\\'Close\\'][0]) * 100\\n ~~~~~~~~~~~~~~~~~~^^^^\\n File \"/Users/ekzhu/miniconda3/envs/autogen/lib/python3.11/site-packages/pandas/core/series.py\", line 1109, in __getitem__\\n return self._values[key]\\n ~~~~~~~~~~~~^^^^^\\nIndexError: index -1 is out of bounds for axis 0 with size 0\\n', 'role': 'assistant'}, {'content': \"I apologize for the confusion. It seems like the ticker symbol for Meta Platforms Inc. (formerly Facebook) has changed from 'FB' to 'META'. Let's correct this in the code. Also, it seems like the data for the current day might not be available yet, so let's fetch the data until the previous day. Here's the corrected code:\\n\\n```python\\n# Python code\\nimport yfinance as yf\\nfrom datetime import datetime, timedelta\\n\\n# Get the current year and yesterday's date\\ncurrent_year = datetime.now().year\\nyesterday = datetime.now() - timedelta(1)\\n\\n# Download stock data for the current year\\nmeta_data = yf.download('META', start=f'{current_year}-01-01', end=yesterday)\\ntesla_data = yf.download('TSLA', start=f'{current_year}-01-01', end=yesterday)\\n\\n# Calculate the year-to-date gain for each stock\\nmeta_ytd_gain = ((meta_data['Close'][-1] - meta_data['Close'][0]) / meta_data['Close'][0]) * 100\\ntesla_ytd_gain = ((tesla_data['Close'][-1] - tesla_data['Close'][0]) / tesla_data['Close'][0]) * 100\\n\\n# Print the year-to-date gain for each stock\\nprint(f'META year-to-date gain: {meta_ytd_gain}%')\\nprint(f'TESLA year-to-date gain: {tesla_ytd_gain}%')\\n```\\n\\nThis code should now correctly fetch the stock prices for META and TESLA, calculate the year-to-date gain for each, and print the results.\", 'role': 'user'}, {'content': \"exitcode: 0 (execution succeeded)\\nCode output: /Users/ekzhu/miniconda3/envs/autogen/lib/python3.11/site-packages/yfinance/utils.py:775: FutureWarning: The 'unit' keyword in TimedeltaIndex construction is deprecated and will be removed in a future version. Use pd.to_timedelta instead.\\n df.index += _pd.TimedeltaIndex(dst_error_hours, 'h')\\n\\n[*********************100%%**********************] 1 of 1 completed\\n/Users/ekzhu/miniconda3/envs/autogen/lib/python3.11/site-packages/yfinance/utils.py:775: FutureWarning: The 'unit' keyword in TimedeltaIndex construction is deprecated and will be removed in a future version. Use pd.to_timedelta instead.\\n df.index += _pd.TimedeltaIndex(dst_error_hours, 'h')\\n\\n[*********************100%%**********************] 1 of 1 completed\\n/Users/ekzhu/autogen/notebook/coding/tmp_code_0b52d7fcfe06d76c8b1e0ce9333cb5cf.py:14: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\\n meta_ytd_gain = ((meta_data['Close'][-1] - meta_data['Close'][0]) / meta_data['Close'][0]) * 100\\n/Users/ekzhu/autogen/notebook/coding/tmp_code_0b52d7fcfe06d76c8b1e0ce9333cb5cf.py:15: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\\n tesla_ytd_gain = ((tesla_data['Close'][-1] - tesla_data['Close'][0]) / tesla_data['Close'][0]) * 100\\nMETA year-to-date gain: 50.11406747602124%\\nTESLA year-to-date gain: -30.85903076529873%\\n\", 'role': 'assistant'}, {'content': \"The code has successfully fetched the stock prices for META and TESLA and calculated the year-to-date gain for each. \\n\\nAs of yesterday, the year-to-date gain for META (Meta Platforms Inc.) is approximately 50.11%, and for TESLA (Tesla Inc.) it is approximately -30.86%. This means that so far this year, META's stock price has increased by about 50.11% while TESLA's stock price has decreased by about 30.86%.\\n\\nPlease note that stock prices can fluctuate and the exact gain may vary depending on the time of checking.\\n\\nTERMINATE\", 'role': 'user'}]\n",
  312. "Summary: The year-to-date gain for META (Meta Platforms Inc.) is approximately 50.11%, and for TESLA (Tesla Inc.) it is approximately -30.86%. This means that so far this year, META's stock price has increased by about 50.11% while TESLA's stock price has decreased by about 30.86%.\n",
  313. "Cost info: ({'total_cost': 0.32256, 'gpt-4-0613': {'cost': 0.32256, 'prompt_tokens': 8224, 'completion_tokens': 1264, 'total_tokens': 9488}}, {'total_cost': 0.32256, 'gpt-4-0613': {'cost': 0.32256, 'prompt_tokens': 8224, 'completion_tokens': 1264, 'total_tokens': 9488}})\n"
  314. ]
  315. }
  316. ],
  317. "source": [
  318. "print(\"Chat history:\", chat_res.chat_history)\n",
  319. "\n",
  320. "print(\"Summary:\", chat_res.summary)\n",
  321. "print(\"Cost info:\", chat_res.cost)"
  322. ]
  323. },
  324. {
  325. "attachments": {},
  326. "cell_type": "markdown",
  327. "metadata": {},
  328. "source": [
  329. "## Example Task: Plot Chart"
  330. ]
  331. },
  332. {
  333. "cell_type": "code",
  334. "execution_count": 5,
  335. "metadata": {},
  336. "outputs": [
  337. {
  338. "name": "stdout",
  339. "output_type": "stream",
  340. "text": [
  341. "\u001b[33muser_proxy\u001b[0m (to assistant):\n",
  342. "\n",
  343. "Plot a chart of their stock price change YTD. Save the data to stock_price_ytd.csv, and save the plot to stock_price_ytd.png.\n",
  344. "\n",
  345. "--------------------------------------------------------------------------------\n",
  346. "\u001b[33massistant\u001b[0m (to user_proxy):\n",
  347. "\n",
  348. "To plot a chart of the stock price change year-to-date (YTD) for META and TESLA, and to save the data and the plot, we can use the `matplotlib` and `pandas` libraries in Python. If these libraries are not installed, they can be installed using pip: `pip install matplotlib pandas`.\n",
  349. "\n",
  350. "Here is the Python code to fetch the stock prices, plot the chart, and save the data and the plot:\n",
  351. "\n",
  352. "```python\n",
  353. "# Python code\n",
  354. "import yfinance as yf\n",
  355. "import matplotlib.pyplot as plt\n",
  356. "import pandas as pd\n",
  357. "from datetime import datetime, timedelta\n",
  358. "\n",
  359. "# Get the current year and yesterday's date\n",
  360. "current_year = datetime.now().year\n",
  361. "yesterday = datetime.now() - timedelta(1)\n",
  362. "\n",
  363. "# Download stock data for the current year\n",
  364. "meta_data = yf.download('META', start=f'{current_year}-01-01', end=yesterday)\n",
  365. "tesla_data = yf.download('TSLA', start=f'{current_year}-01-01', end=yesterday)\n",
  366. "\n",
  367. "# Plot the closing prices\n",
  368. "plt.figure(figsize=(14, 7))\n",
  369. "plt.plot(meta_data['Close'], label='META')\n",
  370. "plt.plot(tesla_data['Close'], label='TESLA')\n",
  371. "plt.title('META vs TESLA Stock Price YTD')\n",
  372. "plt.xlabel('Date')\n",
  373. "plt.ylabel('Closing Price')\n",
  374. "plt.legend()\n",
  375. "plt.grid(True)\n",
  376. "plt.savefig('stock_price_ytd.png')\n",
  377. "\n",
  378. "# Save the data to a CSV file\n",
  379. "data = pd.concat([meta_data['Close'], tesla_data['Close']], axis=1)\n",
  380. "data.columns = ['META', 'TESLA']\n",
  381. "data.to_csv('stock_price_ytd.csv')\n",
  382. "```\n",
  383. "\n",
  384. "This code fetches the closing prices for META and TESLA for the current year, plots the closing prices, saves the plot to 'stock_price_ytd.png', and saves the closing prices to 'stock_price_ytd.csv'.\n",
  385. "\n",
  386. "--------------------------------------------------------------------------------\n",
  387. "\u001b[31m\n",
  388. ">>>>>>>> EXECUTING CODE BLOCK (inferred language is python)...\u001b[0m\n",
  389. "\u001b[33muser_proxy\u001b[0m (to assistant):\n",
  390. "\n",
  391. "exitcode: 0 (execution succeeded)\n",
  392. "Code output: /Users/ekzhu/miniconda3/envs/autogen/lib/python3.11/site-packages/yfinance/utils.py:775: FutureWarning: The 'unit' keyword in TimedeltaIndex construction is deprecated and will be removed in a future version. Use pd.to_timedelta instead.\n",
  393. " df.index += _pd.TimedeltaIndex(dst_error_hours, 'h')\n",
  394. "\n",
  395. "[*********************100%%**********************] 1 of 1 completed\n",
  396. "/Users/ekzhu/miniconda3/envs/autogen/lib/python3.11/site-packages/yfinance/utils.py:775: FutureWarning: The 'unit' keyword in TimedeltaIndex construction is deprecated and will be removed in a future version. Use pd.to_timedelta instead.\n",
  397. " df.index += _pd.TimedeltaIndex(dst_error_hours, 'h')\n",
  398. "\n",
  399. "[*********************100%%**********************] 1 of 1 completed\n",
  400. "\n",
  401. "\n",
  402. "--------------------------------------------------------------------------------\n",
  403. "\u001b[33massistant\u001b[0m (to user_proxy):\n",
  404. "\n",
  405. "The code has successfully fetched the stock prices for META and TESLA, plotted the chart of their stock price change year-to-date (YTD), and saved the data to 'stock_price_ytd.csv' and the plot to 'stock_price_ytd.png'.\n",
  406. "\n",
  407. "You can now view the chart in the 'stock_price_ytd.png' file and the data in the 'stock_price_ytd.csv' file in your current working directory.\n",
  408. "\n",
  409. "TERMINATE\n",
  410. "\n",
  411. "--------------------------------------------------------------------------------\n"
  412. ]
  413. }
  414. ],
  415. "source": [
  416. "# followup of the previous question\n",
  417. "user_proxy.send(\n",
  418. " recipient=assistant,\n",
  419. " message=\"\"\"Plot a chart of their stock price change YTD. Save the data to stock_price_ytd.csv, and save the plot to stock_price_ytd.png.\"\"\",\n",
  420. ")"
  421. ]
  422. },
  423. {
  424. "attachments": {},
  425. "cell_type": "markdown",
  426. "metadata": {},
  427. "source": [
  428. "Let's display the generated figure."
  429. ]
  430. },
  431. {
  432. "cell_type": "code",
  433. "execution_count": 6,
  434. "metadata": {},
  435. "outputs": [
  436. {
  437. "data": {