mirror of
https://github.com/microsoft/autogen.git
synced 2025-07-20 15:31:29 +00:00
846 lines
34 KiB
Plaintext
846 lines
34 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"attachments": {},
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"<a href=\"https://colab.research.google.com/github/microsoft/FLAML/blob/main/notebook/autogen_agent_auto_feedback_from_code_execution.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
||
]
|
||
},
|
||
{
|
||
"attachments": {},
|
||
"cell_type": "markdown",
|
||
"metadata": {
|
||
"slideshow": {
|
||
"slide_type": "slide"
|
||
}
|
||
},
|
||
"source": [
|
||
"# Interactive LLM Agent with Auto Feedback from Code Execution\n",
|
||
"\n",
|
||
"FLAML offers an experimental feature of interactive LLM agents, which can be used to solve various tasks with human or automatic feedback, including tasks that require using tools via code.\n",
|
||
"\n",
|
||
"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 uses auto-feedback based on the result of code execution. For example, when `human_input_mode` is set to \"ALWAYS\", the `UserProxyAgent` will always prompt the user for feedback. When user feedback is provided, the `UserProxyAgent` will directly pass the feedback to `AssistantAgent` without doing any additional steps. When no user feedback is provided, the `UserProxyAgent` will execute the code written by `AssistantAgent` directly and return the execution results (success or failure and corresponding outputs) to `AssistantAgent`.\n",
|
||
"\n",
|
||
"## Requirements\n",
|
||
"\n",
|
||
"FLAML requires `Python>=3.7`. To run this notebook example, please install flaml with the [autogen] option:\n",
|
||
"```bash\n",
|
||
"pip install flaml[autogen]\n",
|
||
"```"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 1,
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2023-02-13T23:40:52.317406Z",
|
||
"iopub.status.busy": "2023-02-13T23:40:52.316561Z",
|
||
"iopub.status.idle": "2023-02-13T23:40:52.321193Z",
|
||
"shell.execute_reply": "2023-02-13T23:40:52.320628Z"
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"# %pip install flaml[autogen]==2.0.0rc1"
|
||
]
|
||
},
|
||
{
|
||
"attachments": {},
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"## Set your API Endpoint\n",
|
||
"\n",
|
||
"The [`config_list_gpt4_gpt35`](https://microsoft.github.io/FLAML/docs/reference/autogen/oai/openai_utils#config_list_gpt4_gpt35) function tries to create a list of gpt-4 and gpt-3.5 configurations using Azure OpenAI endpoints and OpenAI endpoints. It assumes the api keys and api bases are stored in the corresponding environment variables or local txt files:\n",
|
||
"\n",
|
||
"- OpenAI API key: os.environ[\"OPENAI_API_KEY\"] or `openai_api_key_file=\"key_openai.txt\"`.\n",
|
||
"- Azure OpenAI API key: os.environ[\"AZURE_OPENAI_API_KEY\"] or `aoai_api_key_file=\"key_aoai.txt\"`. Multiple keys can be stored, one per line.\n",
|
||
"- Azure OpenAI API base: os.environ[\"AZURE_OPENAI_API_BASE\"] or `aoai_api_base_file=\"base_aoai.txt\"`. Multiple bases can be stored, one per line.\n",
|
||
"\n",
|
||
"It's OK to have only the OpenAI API key, or only the Azure OpenAI API key + base.\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 2,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"from flaml import oai\n",
|
||
"\n",
|
||
"config_list = oai.config_list_from_models(model_list=[\"gpt-4\"])"
|
||
]
|
||
},
|
||
{
|
||
"attachments": {},
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"The config list looks like the following:\n",
|
||
"```python\n",
|
||
"config_list = [\n",
|
||
" {\n",
|
||
" 'model': 'gpt-4',\n",
|
||
" 'api_key': '<your OpenAI API key here>',\n",
|
||
" }, # only if OpenAI API key is found\n",
|
||
" {\n",
|
||
" 'model': 'gpt-4',\n",
|
||
" 'api_key': '<your first Azure OpenAI API key here>',\n",
|
||
" 'api_base': '<your first Azure OpenAI API base here>',\n",
|
||
" 'api_type': 'azure',\n",
|
||
" 'api_version': '2023-03-15-preview',\n",
|
||
" }, # only if the at least one Azure OpenAI API key is found\n",
|
||
" {\n",
|
||
" 'model': 'gpt-4',\n",
|
||
" 'api_key': '<your second Azure OpenAI API key here>',\n",
|
||
" 'api_base': '<your second Azure OpenAI API base here>',\n",
|
||
" 'api_type': 'azure',\n",
|
||
" 'api_version': '2023-03-15-preview',\n",
|
||
" }, # only if the second Azure OpenAI API key is found\n",
|
||
"]\n",
|
||
"```\n",
|
||
"\n",
|
||
"You can directly override it if the above function returns an empty list, i.e., it doesn't find the keys in the specified locations."
|
||
]
|
||
},
|
||
{
|
||
"attachments": {},
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"## Example Task: Write Code to Draw a Plot\n",
|
||
"\n",
|
||
"In the example below, let's see how to use the agents in FLAML 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."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 3,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"\n",
|
||
" -------------------------------------------------------------------------------- \n",
|
||
"\n",
|
||
"user (to assistant):\n",
|
||
"Draw a rocket and save to a file named 'rocket.svg'\n",
|
||
"\n",
|
||
" -------------------------------------------------------------------------------- \n",
|
||
"\n",
|
||
"assistant (to user):\n",
|
||
"```python\n",
|
||
"# filename: draw_rocket.py\n",
|
||
"import svgwrite\n",
|
||
"\n",
|
||
"def draw_rocket():\n",
|
||
" dwg = svgwrite.Drawing('rocket.svg', profile='tiny')\n",
|
||
"\n",
|
||
" rocket_body_color = \"gray\"\n",
|
||
" rocket_fire_color = \"red\"\n",
|
||
"\n",
|
||
" # Draw the rocket body\n",
|
||
" dwg.add(dwg.rect(insert=(50, 20), size=(50, 100), stroke=rocket_body_color, fill=rocket_body_color))\n",
|
||
" \n",
|
||
" # Draw the rocket top\n",
|
||
" dwg.add(dwg.polygon(points=[(75, 0), (50, 20), (100, 20)], stroke=rocket_body_color, fill=rocket_body_color))\n",
|
||
" \n",
|
||
" # Draw the fins\n",
|
||
" dwg.add(dwg.polygon(points=[(50, 60), (30, 80), (50, 100)], stroke=rocket_body_color, fill=rocket_body_color))\n",
|
||
" dwg.add(dwg.polygon(points=[(100, 60), (120, 80), (100, 100)], stroke=rocket_body_color, fill=rocket_body_color))\n",
|
||
" \n",
|
||
" # Draw the rocket fire/flame\n",
|
||
" dwg.add(dwg.polygon(points=[(50, 120), (75, 160), (100, 120)], stroke=rocket_fire_color, fill=rocket_fire_color))\n",
|
||
"\n",
|
||
" dwg.save()\n",
|
||
"\n",
|
||
"if __name__ == '__main__':\n",
|
||
" draw_rocket()\n",
|
||
"```\n",
|
||
"\n",
|
||
"1. Save the above Python code in a file named \"draw_rocket.py\".\n",
|
||
"2. Execute the script by running `python draw_rocket.py` in your terminal or command prompt.\n",
|
||
"3. The script will create a file named 'rocket.svg' in the same directory containing the rocket drawing.\n",
|
||
"\n",
|
||
">>>>>>>> NO HUMAN INPUT RECEIVED. USING AUTO REPLY FOR THE USER...\n",
|
||
"\n",
|
||
" -------------------------------------------------------------------------------- \n",
|
||
"\n",
|
||
"user (to assistant):\n",
|
||
"exitcode: 0 (execution succeeded)\n",
|
||
"Code output: \n",
|
||
"\n",
|
||
"\n",
|
||
" -------------------------------------------------------------------------------- \n",
|
||
"\n",
|
||
"assistant (to user):\n",
|
||
"Great! The script executed successfully and the rocket drawing has been saved to a file named 'rocket.svg'. You can now open the 'rocket.svg' file to view the rocket illustration. \n",
|
||
"\n",
|
||
"If you have any further questions or need additional assistance, feel free to ask.\n",
|
||
"\n",
|
||
"TERMINATE\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"from flaml.autogen.agent import AssistantAgent, UserProxyAgent\n",
|
||
"\n",
|
||
"# create an AssistantAgent named \"assistant\"\n",
|
||
"assistant = AssistantAgent(\"assistant\", request_timeout=600, seed=42, config_list=config_list)\n",
|
||
"# create a UserProxyAgent instance named \"user\"\n",
|
||
"user = UserProxyAgent(\n",
|
||
" \"user\",\n",
|
||
" human_input_mode=\"NEVER\",\n",
|
||
" max_consecutive_auto_reply=10,\n",
|
||
" is_termination_msg=lambda x: x.rstrip().endswith(\"TERMINATE\") or x.rstrip().endswith('\"TERMINATE\".'),\n",
|
||
" work_dir=\"coding\",\n",
|
||
" use_docker=False, # set to True if you are using docker\n",
|
||
")\n",
|
||
"# the assistant receives a message from the user, which contains the task description\n",
|
||
"assistant.receive(\n",
|
||
" \"\"\"Draw a rocket and save to a file named 'rocket.svg'\"\"\",\n",
|
||
" user,\n",
|
||
")"
|
||
]
|
||
},
|
||
{
|
||
"attachments": {},
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"The example above involves code execution. In FLAML, 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. This process occurs in a designated working directory, using a Docker container by default. Unless a specific directory is specified, FLAML defaults to the `flaml/autogen/extensions` directory. Users have the option to specify a different working directory by setting the `work_dir` argument when constructing a new instance of the `UserProxyAgent`.\n",
|
||
"\n",
|
||
"Let's display the generated figure."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 4,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"image/svg+xml": [
|
||
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:ev=\"http://www.w3.org/2001/xml-events\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" baseProfile=\"tiny\" height=\"100%\" version=\"1.2\" width=\"100%\"><defs/><rect fill=\"gray\" height=\"100\" stroke=\"gray\" width=\"50\" x=\"50\" y=\"20\"/><polygon fill=\"gray\" points=\"75,0 50,20 100,20\" stroke=\"gray\"/><polygon fill=\"gray\" points=\"50,60 30,80 50,100\" stroke=\"gray\"/><polygon fill=\"gray\" points=\"100,60 120,80 100,100\" stroke=\"gray\"/><polygon fill=\"red\" points=\"50,120 75,160 100,120\" stroke=\"red\"/></svg>"
|
||
],
|
||
"text/plain": [
|
||
"<IPython.core.display.SVG object>"
|
||
]
|
||
},
|
||
"metadata": {},
|
||
"output_type": "display_data"
|
||
}
|
||
],
|
||
"source": [
|
||
"# uncomment the following to render the svg file\n",
|
||
"# from IPython.display import SVG, display\n",
|
||
"\n",
|
||
"# display(SVG(\"coding/rocket.svg\"))"
|
||
]
|
||
},
|
||
{
|
||
"attachments": {},
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"## Example Task: Use Code to Check Stock Price Change"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 5,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"\n",
|
||
" -------------------------------------------------------------------------------- \n",
|
||
"\n",
|
||
"user (to assistant):\n",
|
||
"What date is today? Which big tech stock has the largest year-to-date gain this year? How much is the gain?\n",
|
||
"\n",
|
||
" -------------------------------------------------------------------------------- \n",
|
||
"\n",
|
||
"assistant (to user):\n",
|
||
"First, let's find out today's date. You can do that by running the following Python code:\n",
|
||
"\n",
|
||
"```python\n",
|
||
"from datetime import datetime\n",
|
||
"\n",
|
||
"today = datetime.now()\n",
|
||
"print(\"Today's date:\", today.strftime(\"%B %d, %Y\"))\n",
|
||
"```\n",
|
||
"\n",
|
||
"For the tech stock information, you will need to use an API or web scraping to fetch this data. I will show you how to do it using the `yfinance` library in Python. Before running the code, make sure you have the `yfinance` library installed by executing the following command:\n",
|
||
"\n",
|
||
"```sh\n",
|
||
"pip install yfinance\n",
|
||
"```\n",
|
||
"\n",
|
||
"Now, we can fetch the stock information using the following Python code:\n",
|
||
"\n",
|
||
"```python\n",
|
||
"import yfinance as yf\n",
|
||
"\n",
|
||
"def get_stock_info(ticker):\n",
|
||
" stock = yf.Ticker(ticker)\n",
|
||
" stock_info = stock.history(\"ytd\")\n",
|
||
" current_price = stock_info[\"Close\"][-1]\n",
|
||
" start_price = stock_info[\"Close\"][0]\n",
|
||
" return (current_price - start_price) / start_price * 100\n",
|
||
"\n",
|
||
"tech_stocks = {\n",
|
||
" \"Apple\": \"AAPL\",\n",
|
||
" \"Microsoft\": \"MSFT\",\n",
|
||
" \"Amazon\": \"AMZN\",\n",
|
||
" \"Google\": \"GOOGL\",\n",
|
||
" \"Facebook\": \"FB\",\n",
|
||
"}\n",
|
||
"\n",
|
||
"ytd_gains = {stock: get_stock_info(ticker) for stock, ticker in tech_stocks.items()}\n",
|
||
"largest_gain = max(ytd_gains, key=ytd_gains.get)\n",
|
||
"print(f\"{largest_gain} has the largest year-to-date gain with {ytd_gains[largest_gain]:.2f}% gain.\")\n",
|
||
"```\n",
|
||
"\n",
|
||
"This script will print out the big tech stock with the largest year-to-date gain and the gain percentage.\n",
|
||
"\n",
|
||
">>>>>>>> NO HUMAN INPUT RECEIVED. USING AUTO REPLY FOR THE USER...\n",
|
||
"\n",
|
||
" -------------------------------------------------------------------------------- \n",
|
||
"\n",
|
||
"user (to assistant):\n",
|
||
"exitcode: 1 (execution failed)\n",
|
||
"Code output: \n",
|
||
"Today's date: June 08, 2023\n",
|
||
"\n",
|
||
"Defaulting to user installation because normal site-packages is not writeable\n",
|
||
"Requirement already satisfied: yfinance in /home/vscode/.local/lib/python3.9/site-packages (0.2.18)\n",
|
||
"Requirement already satisfied: pandas>=1.3.0 in /usr/local/lib/python3.9/site-packages (from yfinance) (1.5.2)\n",
|
||
"Requirement already satisfied: numpy>=1.16.5 in /home/vscode/.local/lib/python3.9/site-packages (from yfinance) (1.23.5)\n",
|
||
"Requirement already satisfied: requests>=2.26 in /usr/local/lib/python3.9/site-packages (from yfinance) (2.28.1)\n",
|
||
"Requirement already satisfied: multitasking>=0.0.7 in /home/vscode/.local/lib/python3.9/site-packages (from yfinance) (0.0.11)\n",
|
||
"Requirement already satisfied: lxml>=4.9.1 in /home/vscode/.local/lib/python3.9/site-packages (from yfinance) (4.9.2)\n",
|
||
"Requirement already satisfied: appdirs>=1.4.4 in /home/vscode/.local/lib/python3.9/site-packages (from yfinance) (1.4.4)\n",
|
||
"Requirement already satisfied: pytz>=2022.5 in /usr/local/lib/python3.9/site-packages (from yfinance) (2022.6)\n",
|
||
"Requirement already satisfied: frozendict>=2.3.4 in /home/vscode/.local/lib/python3.9/site-packages (from yfinance) (2.3.8)\n",
|
||
"Requirement already satisfied: cryptography>=3.3.2 in /home/vscode/.local/lib/python3.9/site-packages (from yfinance) (38.0.4)\n",
|
||
"Requirement already satisfied: beautifulsoup4>=4.11.1 in /home/vscode/.local/lib/python3.9/site-packages (from yfinance) (4.11.1)\n",
|
||
"Requirement already satisfied: html5lib>=1.1 in /home/vscode/.local/lib/python3.9/site-packages (from yfinance) (1.1)\n",
|
||
"Requirement already satisfied: soupsieve>1.2 in /home/vscode/.local/lib/python3.9/site-packages (from beautifulsoup4>=4.11.1->yfinance) (2.3.2.post1)\n",
|
||
"Requirement already satisfied: cffi>=1.12 in /home/vscode/.local/lib/python3.9/site-packages (from cryptography>=3.3.2->yfinance) (1.15.1)\n",
|
||
"Requirement already satisfied: six>=1.9 in /usr/local/lib/python3.9/site-packages (from html5lib>=1.1->yfinance) (1.16.0)\n",
|
||
"Requirement already satisfied: webencodings in /home/vscode/.local/lib/python3.9/site-packages (from html5lib>=1.1->yfinance) (0.5.1)\n",
|
||
"Requirement already satisfied: python-dateutil>=2.8.1 in /usr/local/lib/python3.9/site-packages (from pandas>=1.3.0->yfinance) (2.8.2)\n",
|
||
"Requirement already satisfied: charset-normalizer<3,>=2 in /usr/local/lib/python3.9/site-packages (from requests>=2.26->yfinance) (2.1.1)\n",
|
||
"Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.9/site-packages (from requests>=2.26->yfinance) (3.4)\n",
|
||
"Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.9/site-packages (from requests>=2.26->yfinance) (1.26.13)\n",
|
||
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.9/site-packages (from requests>=2.26->yfinance) (2022.9.24)\n",
|
||
"Requirement already satisfied: pycparser in /home/vscode/.local/lib/python3.9/site-packages (from cffi>=1.12->cryptography>=3.3.2->yfinance) (2.21)\n",
|
||
"\n",
|
||
"Traceback (most recent call last):\n",
|
||
" File \"/workspaces/FLAML/notebook/coding/tmp_code_74e4297091e1a4a01622501c25dfb9db.py\", line 18, in <module>\n",
|
||
" ytd_gains = {stock: get_stock_info(ticker) for stock, ticker in tech_stocks.items()}\n",
|
||
" File \"/workspaces/FLAML/notebook/coding/tmp_code_74e4297091e1a4a01622501c25dfb9db.py\", line 18, in <dictcomp>\n",
|
||
" ytd_gains = {stock: get_stock_info(ticker) for stock, ticker in tech_stocks.items()}\n",
|
||
" File \"/workspaces/FLAML/notebook/coding/tmp_code_74e4297091e1a4a01622501c25dfb9db.py\", line 6, in get_stock_info\n",
|
||
" current_price = stock_info[\"Close\"][-1]\n",
|
||
" File \"/usr/local/lib/python3.9/site-packages/pandas/core/series.py\", line 978, in __getitem__\n",
|
||
" return self._values[key]\n",
|
||
"IndexError: index -1 is out of bounds for axis 0 with size 0\n",
|
||
"\n",
|
||
"\n",
|
||
" -------------------------------------------------------------------------------- \n",
|
||
"\n",
|
||
"assistant (to user):\n",
|
||
"Apologies for the error. It seems there might be an issue with `yfinance` fetching historical price data. To address the error, let's modify the code to include a try-except block to handle any errors when fetching stock data.\n",
|
||
"\n",
|
||
"Here's the updated code:\n",
|
||
"\n",
|
||
"```python\n",
|
||
"import yfinance as yf\n",
|
||
"\n",
|
||
"def get_stock_info(ticker):\n",
|
||
" try:\n",
|
||
" stock = yf.Ticker(ticker)\n",
|
||
" stock_info = stock.history(\"ytd\")\n",
|
||
" if stock_info.empty:\n",
|
||
" return None\n",
|
||
" current_price = stock_info[\"Close\"][-1]\n",
|
||
" start_price = stock_info[\"Close\"][0]\n",
|
||
" return (current_price - start_price) / start_price * 100\n",
|
||
" except Exception as e:\n",
|
||
" print(f\"Error fetching stock data for {ticker}: {e}\")\n",
|
||
" return None\n",
|
||
"\n",
|
||
"tech_stocks = {\n",
|
||
" \"Apple\": \"AAPL\",\n",
|
||
" \"Microsoft\": \"MSFT\",\n",
|
||
" \"Amazon\": \"AMZN\",\n",
|
||
" \"Google\": \"GOOGL\",\n",
|
||
" \"Facebook\": \"FB\",\n",
|
||
"}\n",
|
||
"\n",
|
||
"ytd_gains = {stock: get_stock_info(ticker) for stock, ticker in tech_stocks.items()}\n",
|
||
"ytd_gains = {stock: gain for stock, gain in ytd_gains.items() if gain is not None} # Remove stocks with errors\n",
|
||
"if ytd_gains:\n",
|
||
" largest_gain = max(ytd_gains, key=ytd_gains.get)\n",
|
||
" print(f\"{largest_gain} has the largest year-to-date gain with {ytd_gains[largest_gain]:.2f}% gain.\")\n",
|
||
"else:\n",
|
||
" print(\"Unable to retrieve stock information for any tech stocks.\")\n",
|
||
"```\n",
|
||
"\n",
|
||
"This code will handle any errors that may occur when fetching stock data and continue to the next one. It will also print out an error message for the stocks that failed to fetch data. Run the modified code and let me know the result.\n",
|
||
"\n",
|
||
">>>>>>>> NO HUMAN INPUT RECEIVED. USING AUTO REPLY FOR THE USER...\n",
|
||
"\n",
|
||
" -------------------------------------------------------------------------------- \n",
|
||
"\n",
|
||
"user (to assistant):\n",
|
||
"exitcode: 0 (execution succeeded)\n",
|
||
"Code output: \n",
|
||
"FB: No data found, symbol may be delisted\n",
|
||
"Apple has the largest year-to-date gain with 42.59% gain.\n",
|
||
"\n",
|
||
"\n",
|
||
" -------------------------------------------------------------------------------- \n",
|
||
"\n",
|
||
"assistant (to user):\n",
|
||
"Great! The updated code successfully fetched the stock data and determined that Apple has the largest year-to-date gain with 42.59%. Please note that the error message for Facebook stock (FB) indicates that no data was found, which may be due to the stock symbol being delisted or an issue with the `yfinance` library.\n",
|
||
"\n",
|
||
"If you have any more questions or need further assistance, feel free to ask. Otherwise, type \"TERMINATE\" to end this session.\n",
|
||
"\n",
|
||
">>>>>>>> NO HUMAN INPUT RECEIVED. USING AUTO REPLY FOR THE USER...\n",
|
||
"\n",
|
||
" -------------------------------------------------------------------------------- \n",
|
||
"\n",
|
||
"user (to assistant):\n",
|
||
"\n",
|
||
"\n",
|
||
" -------------------------------------------------------------------------------- \n",
|
||
"\n",
|
||
"assistant (to user):\n",
|
||
"TERMINATE\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"# it is suggested to reset the assistant to clear the state if the new task is not related to the previous one.\n",
|
||
"assistant.reset()\n",
|
||
"assistant.receive(\n",
|
||
" \"\"\"What date is today? Which big tech stock has the largest year-to-date gain this year? How much is the gain?\"\"\",\n",
|
||
" user,\n",
|
||
")"
|
||
]
|
||
},
|
||
{
|
||
"attachments": {},
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"All the feedback is auto generated."
|
||
]
|
||
}
|
||
],
|
||
"metadata": {
|
||
"kernelspec": {
|
||
"display_name": "Python 3",
|
||
"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.9.15"
|
||
},
|
||
"vscode": {
|
||
"interpreter": {
|
||
"hash": "949777d72b0d2535278d3dc13498b2535136f6dfe0678499012e853ee9abcab1"
|
||
}
|
||
},
|
||
"widgets": {
|
||
"application/vnd.jupyter.widget-state+json": {
|
||
"state": {
|
||
"2d910cfd2d2a4fc49fc30fbbdc5576a7": {
|
||
"model_module": "@jupyter-widgets/base",
|
||
"model_module_version": "2.0.0",
|
||
"model_name": "LayoutModel",
|
||
"state": {
|
||
"_model_module": "@jupyter-widgets/base",
|
||
"_model_module_version": "2.0.0",
|
||
"_model_name": "LayoutModel",
|
||
"_view_count": null,
|
||
"_view_module": "@jupyter-widgets/base",
|
||
"_view_module_version": "2.0.0",
|
||
"_view_name": "LayoutView",
|
||
"align_content": null,
|
||
"align_items": null,
|
||
"align_self": null,
|
||
"border_bottom": null,
|
||
"border_left": null,
|
||
"border_right": null,
|
||
"border_top": null,
|
||
"bottom": null,
|
||
"display": null,
|
||
"flex": null,
|
||
"flex_flow": null,
|
||
"grid_area": null,
|
||
"grid_auto_columns": null,
|
||
"grid_auto_flow": null,
|
||
"grid_auto_rows": null,
|
||
"grid_column": null,
|
||
"grid_gap": null,
|
||
"grid_row": null,
|
||
"grid_template_areas": null,
|
||
"grid_template_columns": null,
|
||
"grid_template_rows": null,
|
||
"height": null,
|
||
"justify_content": null,
|
||
"justify_items": null,
|
||
"left": null,
|
||
"margin": null,
|
||
"max_height": null,
|
||
"max_width": null,
|
||
"min_height": null,
|
||
"min_width": null,
|
||
"object_fit": null,
|
||
"object_position": null,
|
||
"order": null,
|
||
"overflow": null,
|
||
"padding": null,
|
||
"right": null,
|
||
"top": null,
|
||
"visibility": null,
|
||
"width": null
|
||
}
|
||
},
|
||
"454146d0f7224f038689031002906e6f": {
|
||
"model_module": "@jupyter-widgets/controls",
|
||
"model_module_version": "2.0.0",
|
||
"model_name": "HBoxModel",
|
||
"state": {
|
||
"_dom_classes": [],
|
||
"_model_module": "@jupyter-widgets/controls",
|
||
"_model_module_version": "2.0.0",
|
||
"_model_name": "HBoxModel",
|
||
"_view_count": null,
|
||
"_view_module": "@jupyter-widgets/controls",
|
||
"_view_module_version": "2.0.0",
|
||
"_view_name": "HBoxView",
|
||
"box_style": "",
|
||
"children": [
|
||
"IPY_MODEL_e4ae2b6f5a974fd4bafb6abb9d12ff26",
|
||
"IPY_MODEL_577e1e3cc4db4942b0883577b3b52755",
|
||
"IPY_MODEL_b40bdfb1ac1d4cffb7cefcb870c64d45"
|
||
],
|
||
"layout": "IPY_MODEL_dc83c7bff2f241309537a8119dfc7555",
|
||
"tabbable": null,
|
||
"tooltip": null
|
||
}
|
||
},
|
||
"577e1e3cc4db4942b0883577b3b52755": {
|
||
"model_module": "@jupyter-widgets/controls",
|
||
"model_module_version": "2.0.0",
|
||
"model_name": "FloatProgressModel",
|
||
"state": {
|
||
"_dom_classes": [],
|
||
"_model_module": "@jupyter-widgets/controls",
|
||
"_model_module_version": "2.0.0",
|
||
"_model_name": "FloatProgressModel",
|
||
"_view_count": null,
|
||
"_view_module": "@jupyter-widgets/controls",
|
||
"_view_module_version": "2.0.0",
|
||
"_view_name": "ProgressView",
|
||
"bar_style": "success",
|
||
"description": "",
|
||
"description_allow_html": false,
|
||
"layout": "IPY_MODEL_2d910cfd2d2a4fc49fc30fbbdc5576a7",
|
||
"max": 1,
|
||
"min": 0,
|
||
"orientation": "horizontal",
|
||
"style": "IPY_MODEL_74a6ba0c3cbc4051be0a83e152fe1e62",
|
||
"tabbable": null,
|
||
"tooltip": null,
|
||
"value": 1
|
||
}
|
||
},
|
||
"6086462a12d54bafa59d3c4566f06cb2": {
|
||
"model_module": "@jupyter-widgets/base",
|
||
"model_module_version": "2.0.0",
|
||
"model_name": "LayoutModel",
|
||
"state": {
|
||
"_model_module": "@jupyter-widgets/base",
|
||
"_model_module_version": "2.0.0",
|
||
"_model_name": "LayoutModel",
|
||
"_view_count": null,
|
||
"_view_module": "@jupyter-widgets/base",
|
||
"_view_module_version": "2.0.0",
|
||
"_view_name": "LayoutView",
|
||
"align_content": null,
|
||
"align_items": null,
|
||
"align_self": null,
|
||
"border_bottom": null,
|
||
"border_left": null,
|
||
"border_right": null,
|
||
"border_top": null,
|
||
"bottom": null,
|
||
"display": null,
|
||
"flex": null,
|
||
"flex_flow": null,
|
||
"grid_area": null,
|
||
"grid_auto_columns": null,
|
||
"grid_auto_flow": null,
|
||
"grid_auto_rows": null,
|
||
"grid_column": null,
|
||
"grid_gap": null,
|
||
"grid_row": null,
|
||
"grid_template_areas": null,
|
||
"grid_template_columns": null,
|
||
"grid_template_rows": null,
|
||
"height": null,
|
||
"justify_content": null,
|
||
"justify_items": null,
|
||
"left": null,
|
||
"margin": null,
|
||
"max_height": null,
|
||
"max_width": null,
|
||
"min_height": null,
|
||
"min_width": null,
|
||
"object_fit": null,
|
||
"object_position": null,
|
||
"order": null,
|
||
"overflow": null,
|
||
"padding": null,
|
||
"right": null,
|
||
"top": null,
|
||
"visibility": null,
|
||
"width": null
|
||
}
|
||
},
|
||
"74a6ba0c3cbc4051be0a83e152fe1e62": {
|
||
"model_module": "@jupyter-widgets/controls",
|
||
"model_module_version": "2.0.0",
|
||
"model_name": "ProgressStyleModel",
|
||
"state": {
|
||
"_model_module": "@jupyter-widgets/controls",
|
||
"_model_module_version": "2.0.0",
|
||
"_model_name": "ProgressStyleModel",
|
||
"_view_count": null,
|
||
"_view_module": "@jupyter-widgets/base",
|
||
"_view_module_version": "2.0.0",
|
||
"_view_name": "StyleView",
|
||
"bar_color": null,
|
||
"description_width": ""
|
||
}
|
||
},
|
||
"7d3f3d9e15894d05a4d188ff4f466554": {
|
||
"model_module": "@jupyter-widgets/controls",
|
||
"model_module_version": "2.0.0",
|
||
"model_name": "HTMLStyleModel",
|
||
"state": {
|
||
"_model_module": "@jupyter-widgets/controls",
|
||
"_model_module_version": "2.0.0",
|
||
"_model_name": "HTMLStyleModel",
|
||
"_view_count": null,
|
||
"_view_module": "@jupyter-widgets/base",
|
||
"_view_module_version": "2.0.0",
|
||
"_view_name": "StyleView",
|
||
"background": null,
|
||
"description_width": "",
|
||
"font_size": null,
|
||
"text_color": null
|
||
}
|
||
},
|
||
"b40bdfb1ac1d4cffb7cefcb870c64d45": {
|
||
"model_module": "@jupyter-widgets/controls",
|
||
"model_module_version": "2.0.0",
|
||
"model_name": "HTMLModel",
|
||
"state": {
|
||
"_dom_classes": [],
|
||
"_model_module": "@jupyter-widgets/controls",
|
||
"_model_module_version": "2.0.0",
|
||
"_model_name": "HTMLModel",
|
||
"_view_count": null,
|
||
"_view_module": "@jupyter-widgets/controls",
|
||
"_view_module_version": "2.0.0",
|
||
"_view_name": "HTMLView",
|
||
"description": "",
|
||
"description_allow_html": false,
|
||
"layout": "IPY_MODEL_f1355871cc6f4dd4b50d9df5af20e5c8",
|
||
"placeholder": "",
|
||
"style": "IPY_MODEL_ca245376fd9f4354af6b2befe4af4466",
|
||
"tabbable": null,
|
||
"tooltip": null,
|
||
"value": " 1/1 [00:00<00:00, 44.69it/s]"
|
||
}
|
||
},
|
||
"ca245376fd9f4354af6b2befe4af4466": {
|
||
"model_module": "@jupyter-widgets/controls",
|
||
"model_module_version": "2.0.0",
|
||
"model_name": "HTMLStyleModel",
|
||
"state": {
|
||
"_model_module": "@jupyter-widgets/controls",
|
||
"_model_module_version": "2.0.0",
|
||
"_model_name": "HTMLStyleModel",
|
||
"_view_count": null,
|
||
"_view_module": "@jupyter-widgets/base",
|
||
"_view_module_version": "2.0.0",
|
||
"_view_name": "StyleView",
|
||
"background": null,
|
||
"description_width": "",
|
||
"font_size": null,
|
||
"text_color": null
|
||
}
|
||
},
|
||
"dc83c7bff2f241309537a8119dfc7555": {
|
||
"model_module": "@jupyter-widgets/base",
|
||
"model_module_version": "2.0.0",
|
||
"model_name": "LayoutModel",
|
||
"state": {
|
||
"_model_module": "@jupyter-widgets/base",
|
||
"_model_module_version": "2.0.0",
|
||
"_model_name": "LayoutModel",
|
||
"_view_count": null,
|
||
"_view_module": "@jupyter-widgets/base",
|
||
"_view_module_version": "2.0.0",
|
||
"_view_name": "LayoutView",
|
||
"align_content": null,
|
||
"align_items": null,
|
||
"align_self": null,
|
||
"border_bottom": null,
|
||
"border_left": null,
|
||
"border_right": null,
|
||
"border_top": null,
|
||
"bottom": null,
|
||
"display": null,
|
||
"flex": null,
|
||
"flex_flow": null,
|
||
"grid_area": null,
|
||
"grid_auto_columns": null,
|
||
"grid_auto_flow": null,
|
||
"grid_auto_rows": null,
|
||
"grid_column": null,
|
||
"grid_gap": null,
|
||
"grid_row": null,
|
||
"grid_template_areas": null,
|
||
"grid_template_columns": null,
|
||
"grid_template_rows": null,
|
||
"height": null,
|
||
"justify_content": null,
|
||
"justify_items": null,
|
||
"left": null,
|
||
"margin": null,
|
||
"max_height": null,
|
||
"max_width": null,
|
||
"min_height": null,
|
||
"min_width": null,
|
||
"object_fit": null,
|
||
"object_position": null,
|
||
"order": null,
|
||
"overflow": null,
|
||
"padding": null,
|
||
"right": null,
|
||
"top": null,
|
||
"visibility": null,
|
||
"width": null
|
||
}
|
||
},
|
||
"e4ae2b6f5a974fd4bafb6abb9d12ff26": {
|
||
"model_module": "@jupyter-widgets/controls",
|
||
"model_module_version": "2.0.0",
|
||
"model_name": "HTMLModel",
|
||
"state": {
|
||
"_dom_classes": [],
|
||
"_model_module": "@jupyter-widgets/controls",
|
||
"_model_module_version": "2.0.0",
|
||
"_model_name": "HTMLModel",
|
||
"_view_count": null,
|
||
"_view_module": "@jupyter-widgets/controls",
|
||
"_view_module_version": "2.0.0",
|
||
"_view_name": "HTMLView",
|
||
"description": "",
|
||
"description_allow_html": false,
|
||
"layout": "IPY_MODEL_6086462a12d54bafa59d3c4566f06cb2",
|
||
"placeholder": "",
|
||
"style": "IPY_MODEL_7d3f3d9e15894d05a4d188ff4f466554",
|
||
"tabbable": null,
|
||
"tooltip": null,
|
||
"value": "100%"
|
||
}
|
||
},
|
||
"f1355871cc6f4dd4b50d9df5af20e5c8": {
|
||
"model_module": "@jupyter-widgets/base",
|
||
"model_module_version": "2.0.0",
|
||
"model_name": "LayoutModel",
|
||
"state": {
|
||
"_model_module": "@jupyter-widgets/base",
|
||
"_model_module_version": "2.0.0",
|
||
"_model_name": "LayoutModel",
|
||
"_view_count": null,
|
||
"_view_module": "@jupyter-widgets/base",
|
||
"_view_module_version": "2.0.0",
|
||
"_view_name": "LayoutView",
|
||
"align_content": null,
|
||
"align_items": null,
|
||
"align_self": null,
|
||
"border_bottom": null,
|
||
"border_left": null,
|
||
"border_right": null,
|
||
"border_top": null,
|
||
"bottom": null,
|
||
"display": null,
|
||
"flex": null,
|
||
"flex_flow": null,
|
||
"grid_area": null,
|
||
"grid_auto_columns": null,
|
||
"grid_auto_flow": null,
|
||
"grid_auto_rows": null,
|
||
"grid_column": null,
|
||
"grid_gap": null,
|
||
"grid_row": null,
|
||
"grid_template_areas": null,
|
||
"grid_template_columns": null,
|
||
"grid_template_rows": null,
|
||
"height": null,
|
||
"justify_content": null,
|
||
"justify_items": null,
|
||
"left": null,
|
||
"margin": null,
|
||
"max_height": null,
|
||
"max_width": null,
|
||
"min_height": null,
|
||
"min_width": null,
|
||
"object_fit": null,
|
||
"object_position": null,
|
||
"order": null,
|
||
"overflow": null,
|
||
"padding": null,
|
||
"right": null,
|
||
"top": null,
|
||
"visibility": null,
|
||
"width": null
|
||
}
|
||
}
|
||
},
|
||
"version_major": 2,
|
||
"version_minor": 0
|
||
}
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 2
|
||
}
|