update notebook with new models (#1112)

* rerun notebook with new models

* planning agent

* link to notebook
This commit is contained in:
Chi Wang 2023-07-08 22:25:43 -07:00 committed by GitHub
parent ca10b286cc
commit 9c09090bf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 1757 additions and 270 deletions

View File

@ -8,11 +8,12 @@ class AssistantAgent(Agent):
"""(Experimental) Assistant agent, able to suggest code blocks."""
DEFAULT_SYSTEM_MESSAGE = """You are a helpful AI assistant.
In the following cases, suggest python code (in a python coding block) or shell script (in a sh coding block) for the user to execute. You must indicate the script type in the code block.
In the following cases, suggest python code (in a python coding block) or shell script (in a sh coding block) for the user to execute. You must indicate the script type in the code block. The user cannot provide any other feedback or perform any other action beyond executing the code you suggest.
1. When you need to ask the user for some info, use the code to output the info you need, for example, browse or search the web, download/read a file.
2. When you need to perform some task with code, use the code to perform the task and output the result. Finish the task smartly. Solve the task step by step if you need to.
If you want the user to save the code in a file before executing it, put # filename: <filename> inside the code block as the first line. Don't include multiple code blocks in one response. Do not ask users to copy and paste the result. Instead, use 'print' function for the output when relevant. Check the execution result returned by the user.
If the result indicates there is an error, fix the error and output the code again. Suggeset the full code instead of partial code or code changes.
If the result indicates there is an error, fix the error and output the code again. Suggest the full code instead of partial code or code changes.
Verify your answer carefully. If a function for planning is provided, call the function to make plans and verify the execution.
Reply "TERMINATE" in the end when everything is done.
"""

View File

@ -769,7 +769,7 @@ class Completion(openai_Completion):
response["pass_filter"] = pass_filter
return response
cost += response["cost"]
except (AuthenticationError, RateLimitError, Timeout):
except (AuthenticationError, RateLimitError, Timeout, InvalidRequestError):
logger.debug(f"failed with config {i}", exc_info=1)
if i == last:
raise

View File

@ -25,7 +25,7 @@
"\n",
"## Requirements\n",
"\n",
"FLAML requires `Python>=3.7`. To run this notebook example, please install flaml with the [autogen] option:\n",
"FLAML requires `Python>=3.8`. To run this notebook example, please install flaml with the [autogen] option:\n",
"```bash\n",
"pip install flaml[autogen]\n",
"```"
@ -44,7 +44,7 @@
},
"outputs": [],
"source": [
"# %pip install flaml[autogen]==2.0.0rc2"
"# %pip install flaml[autogen]==2.0.0rc3"
]
},
{
@ -125,15 +125,29 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" -------------------------------------------------------------------------------- \n",
"\n",
"user (to assistant):\n",
"\n",
"Draw a rocket and save to a file named 'rocket.svg'\n",
"\n",
" -------------------------------------------------------------------------------- \n",
"\n",
"--------------------------------------------------------------------------------\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"assistant (to user):\n",
"\n",
"Sure. Here is a python script making use of the `svgwrite` package to create a simple, abstract representation of a rocket and save it to a file named 'rocket.svg'. This package provides a set of tools for creating SVG (Scalable Vector Graphics) files.\n",
"\n",
"Firstly, you would need to install the `svgwrite` package. You can install it by running the following command in the shell:\n",
"\n",
"```shell\n",
"pip install svgwrite\n",
"```\n",
"\n",
"After you have installed `svgwrite`, you can use the following python code:\n",
"\n",
"```python\n",
"# filename: draw_rocket.py\n",
"import svgwrite\n",
@ -141,49 +155,46 @@
"def draw_rocket():\n",
" dwg = svgwrite.Drawing('rocket.svg', profile='tiny')\n",
"\n",
" rocket_body_color = \"gray\"\n",
" rocket_fire_color = \"red\"\n",
" # Draw rocket body\n",
" dwg.add(dwg.rect((50, 20), (20, 60), fill='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",
" # Draw rocket fins\n",
" dwg.add(dwg.polygon(points=[(45,80),(75,80),(60,90)], fill='blue'))\n",
"\n",
" # Draw rocket flame\n",
" dwg.add(dwg.polygon(points=[(50,80),(70,80),(60,100)], fill='orange'))\n",
" \n",
" # Save the drawing\n",
" dwg.save()\n",
"\n",
"if __name__ == '__main__':\n",
" draw_rocket()\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",
"The code above will create a new SVG file `rocket.svg` in the same directory as your python script that contains the drawn rocket. \n",
"\n",
"To run this code, save it to a file called `draw_rocket.py` and execute using python.\n",
"\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\n",
">>>>>>>> NO HUMAN INPUT RECEIVED. USING AUTO REPLY FOR THE USER...\n",
"\n",
" -------------------------------------------------------------------------------- \n",
"\n",
"user (to assistant):\n",
"\n",
"exitcode: 0 (execution succeeded)\n",
"Code output: \n",
"Defaulting to user installation because normal site-packages is not writeable\n",
"Requirement already satisfied: svgwrite in /home/vscode/.local/lib/python3.9/site-packages (1.4.3)\n",
"\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",
"Great! The `svgwrite` package has been installed successfully, and you should now have a file named `rocket.svg` in the same directory as your python script. The file contains the drawn rocket in SVG format. You can open it with an SVG viewer or image editor that supports SVG files, such as Adobe Illustrator, Inkscape, or even most modern web browsers.\n",
"\n",
"TERMINATE\n"
"TERMINATE\n",
"\n",
"--------------------------------------------------------------------------------\n"
]
}
],
@ -226,7 +237,7 @@
{
"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>"
"<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=\"red\" height=\"60\" width=\"20\" x=\"50\" y=\"20\"/><polygon fill=\"blue\" points=\"45,80 75,80 60,90\"/><polygon fill=\"orange\" points=\"50,80 70,80 60,100\"/></svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
@ -260,66 +271,147 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" -------------------------------------------------------------------------------- \n",
"\n",
"user (to assistant):\n",
"\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",
"--------------------------------------------------------------------------------\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",
"To get the current date, you can use the following Python code:\n",
"\n",
"```python\n",
"from datetime import datetime\n",
"from datetime import date\n",
"\n",
"today = datetime.now()\n",
"print(\"Today's date:\", today.strftime(\"%B %d, %Y\"))\n",
"today = date.today()\n",
"print(\"Today's date:\", today)\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",
"To find out which big tech stock has the largest year-to-date gain and the gain amount, a web scraping script is needed. Here is a script using the `requests` and `bs4` (BeautifulSoup) libraries to scrape the data from Yahoo Finance.\n",
"\n",
"First, make sure you have both libraries installed:\n",
"\n",
"```sh\n",
"pip install requests bs4\n",
"```\n",
"\n",
"Then, run the following Python code:\n",
"\n",
"```python\n",
"import requests\n",
"from bs4 import BeautifulSoup\n",
"\n",
"# Big tech stock symbols\n",
"stock_symbols = [\"AAPL\", \"GOOGL\", \"MSFT\", \"AMZN\", \"FB\"]\n",
"\n",
"def get_stock_data(stock_symbol):\n",
" url = f\"https://finance.yahoo.com/quote/{stock_symbol}\"\n",
" response = requests.get(url)\n",
" soup = BeautifulSoup(response.text, 'html.parser')\n",
" ytd_gain = soup.find(\"span\", {\"data-reactid\": \"53\"})\n",
" if ytd_gain is not None:\n",
" return float(ytd_gain.text.strip(\"%\"))\n",
" else:\n",
" return None\n",
"\n",
"largest_gain = 0\n",
"largest_gain_stock = ''\n",
"\n",
"for stock_symbol in stock_symbols:\n",
" ytd_gain = get_stock_data(stock_symbol)\n",
" if ytd_gain and ytd_gain > largest_gain:\n",
" largest_gain = ytd_gain\n",
" largest_gain_stock = stock_symbol\n",
"\n",
"print(f'{largest_gain_stock} has the largest year-to-date gain with {largest_gain}%')\n",
"```\n",
"\n",
"This code will output the stock symbol with the largest year-to-date gain and the gain percentage.\n",
"\n",
"Keep in mind that web scraping is not always reliable as websites can change their layout and structure. If the code doesn't work, please let me know so I can adjust it accordingly.\n",
"\n",
"After completing the task, please type \"TERMINATE\" to finish.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\n",
">>>>>>>> NO HUMAN INPUT RECEIVED. USING AUTO REPLY FOR THE USER...\n",
"user (to assistant):\n",
"\n",
"exitcode: 0 (execution succeeded)\n",
"Code output: \n",
"Today's date: 2023-07-08\n",
"\n",
"Defaulting to user installation because normal site-packages is not writeable\n",
"Requirement already satisfied: requests in /usr/local/lib/python3.9/site-packages (2.28.1)\n",
"Requirement already satisfied: bs4 in /home/vscode/.local/lib/python3.9/site-packages (0.0.1)\n",
"Requirement already satisfied: charset-normalizer<3,>=2 in /usr/local/lib/python3.9/site-packages (from requests) (2.1.1)\n",
"Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.9/site-packages (from requests) (3.4)\n",
"Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.9/site-packages (from requests) (1.26.13)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.9/site-packages (from requests) (2022.9.24)\n",
"Requirement already satisfied: beautifulsoup4 in /home/vscode/.local/lib/python3.9/site-packages (from bs4) (4.11.1)\n",
"Requirement already satisfied: soupsieve>1.2 in /home/vscode/.local/lib/python3.9/site-packages (from beautifulsoup4->bs4) (2.3.2.post1)\n",
"\n",
" has the largest year-to-date gain with 0%\n",
"\n",
"\n",
"--------------------------------------------------------------------------------\n",
"assistant (to user):\n",
"\n",
"Apologies, it seems that Yahoo Finance has updated their page structure. Here is an updated version of the code using the `yfinance` library as an easier and more reliable approach to fetch financial data.\n",
"\n",
"First, install the `yfinance` library:\n",
"\n",
"```sh\n",
"pip install yfinance\n",
"```\n",
"\n",
"Now, we can fetch the stock information using the following Python code:\n",
"Then, run the following Python code:\n",
"\n",
"```python\n",
"import yfinance as yf\n",
"from datetime import date, datetime, timedelta\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",
"# Get today's date\n",
"today = date.today()\n",
"print(\"Today's date:\", today)\n",
"\n",
"tech_stocks = {\n",
" \"Apple\": \"AAPL\",\n",
" \"Microsoft\": \"MSFT\",\n",
" \"Amazon\": \"AMZN\",\n",
" \"Google\": \"GOOGL\",\n",
" \"Facebook\": \"FB\",\n",
"}\n",
"# Big tech stock symbols\n",
"stock_symbols = [\"AAPL\", \"GOOGL\", \"MSFT\", \"AMZN\", \"FB\"]\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",
"# Calculate the start date of the year\n",
"start_date = date(today.year, 1, 1)\n",
"\n",
"def get_stock_data(stock_symbol):\n",
" stock = yf.Ticker(stock_symbol)\n",
" stock_history = stock.history(start=start_date.strftime(\"%Y-%m-%d\"), end=today.strftime(\"%Y-%m-%d\"))\n",
" start_price = stock_history.iloc[0][\"Close\"]\n",
" end_price = stock_history.iloc[-1][\"Close\"]\n",
" ytd_gain = ((end_price - start_price) / start_price) * 100\n",
" return ytd_gain\n",
"\n",
"largest_gain = 0\n",
"largest_gain_stock = \"\"\n",
"\n",
"for stock_symbol in stock_symbols:\n",
" ytd_gain = get_stock_data(stock_symbol)\n",
" if ytd_gain > largest_gain:\n",
" largest_gain = ytd_gain\n",
" largest_gain_stock = stock_symbol\n",
"\n",
"print(f\"{largest_gain_stock} has the largest year-to-date gain with {largest_gain:.2f}%\")\n",
"```\n",
"\n",
"This script will print out the big tech stock with the largest year-to-date gain and the gain percentage.\n",
"This code should output the stock symbol with the largest year-to-date gain and the gain percentage.\n",
"\n",
"After completing the task, please type \"TERMINATE\" to finish.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\n",
">>>>>>>> NO HUMAN INPUT RECEIVED. USING AUTO REPLY FOR THE USER...\n",
"\n",
" -------------------------------------------------------------------------------- \n",
"\n",
"user (to assistant):\n",
"\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",
@ -345,88 +437,82 @@
"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",
" File \"/workspaces/FLAML/notebook/coding/tmp_code_bbe977c38d2f588cff7b3a2bedbd4e9e.py\", line 26, in <module>\n",
" ytd_gain = get_stock_data(stock_symbol)\n",
" File \"/workspaces/FLAML/notebook/coding/tmp_code_bbe977c38d2f588cff7b3a2bedbd4e9e.py\", line 17, in get_stock_data\n",
" start_price = stock_history.iloc[0][\"Close\"]\n",
" File \"/usr/local/lib/python3.9/site-packages/pandas/core/indexing.py\", line 1073, in __getitem__\n",
" return self._getitem_axis(maybe_callable, axis=axis)\n",
" File \"/usr/local/lib/python3.9/site-packages/pandas/core/indexing.py\", line 1625, in _getitem_axis\n",
" self._validate_integer(key, axis)\n",
" File \"/usr/local/lib/python3.9/site-packages/pandas/core/indexing.py\", line 1557, in _validate_integer\n",
" raise IndexError(\"single positional indexer is out-of-bounds\")\n",
"IndexError: single positional indexer is out-of-bounds\n",
"\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",
"I apologize for the error. It seems that there is a missing data issue for some stocks. We can add a check to ensure there is data before proceeding. Here is the updated Python code:\n",
"\n",
"```python\n",
"import yfinance as yf\n",
"from datetime import date, datetime, timedelta\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",
"# Get today's date\n",
"today = date.today()\n",
"print(\"Today's date:\", today)\n",
"\n",
"# Big tech stock symbols\n",
"stock_symbols = [\"AAPL\", \"GOOGL\", \"MSFT\", \"AMZN\", \"FB\"]\n",
"\n",
"# Calculate the start date of the year\n",
"start_date = date(today.year, 1, 1)\n",
"\n",
"def get_stock_data(stock_symbol):\n",
" stock = yf.Ticker(stock_symbol)\n",
" stock_history = stock.history(start=start_date.strftime(\"%Y-%m-%d\"), end=today.strftime(\"%Y-%m-%d\"))\n",
" if not stock_history.empty:\n",
" start_price = stock_history.iloc[0][\"Close\"]\n",
" end_price = stock_history.iloc[-1][\"Close\"]\n",
" ytd_gain = ((end_price - start_price) / start_price) * 100\n",
" return ytd_gain\n",
" else:\n",
" return None\n",
"\n",
"tech_stocks = {\n",
" \"Apple\": \"AAPL\",\n",
" \"Microsoft\": \"MSFT\",\n",
" \"Amazon\": \"AMZN\",\n",
" \"Google\": \"GOOGL\",\n",
" \"Facebook\": \"FB\",\n",
"}\n",
"largest_gain = 0\n",
"largest_gain_stock = \"\"\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",
"for stock_symbol in stock_symbols:\n",
" ytd_gain = get_stock_data(stock_symbol)\n",
" if ytd_gain is not None and ytd_gain > largest_gain:\n",
" largest_gain = ytd_gain\n",
" largest_gain_stock = stock_symbol\n",
"\n",
"print(f\"{largest_gain_stock} has the largest year-to-date gain with {largest_gain:.2f}%\")\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",
"After completing the task, please type \"TERMINATE\" to finish.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\n",
">>>>>>>> NO HUMAN INPUT RECEIVED. USING AUTO REPLY FOR THE USER...\n",
"\n",
" -------------------------------------------------------------------------------- \n",
"\n",
"user (to assistant):\n",
"\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",
"Today's date: 2023-07-08\n",
"Got error from yahoo api for ticker FB, Error: {'code': 'Not Found', 'description': 'No data found, symbol may be delisted'}\n",
"- FB: No timezone found, symbol may be delisted\n",
"AAPL has the largest year-to-date gain with 52.90%\n",
"\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",
"I'm glad the updated code worked for you. Let me know if you have any other questions or tasks. To finish, please type \"TERMINATE\".\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"
"--------------------------------------------------------------------------------\n"
]
}
],
@ -464,7 +550,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.9.15"
},
"vscode": {
"interpreter": {

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,7 @@
"\n",
"## Requirements\n",
"\n",
"FLAML requires `Python>=3.7`. To run this notebook example, please install flaml with the [openai] option:\n",
"FLAML requires `Python>=3.8`. To run this notebook example, please install flaml with the [autogen] option:\n",
"```bash\n",
"pip install flaml[autogen]\n",
"```"
@ -44,7 +44,7 @@
},
"outputs": [],
"source": [
"# %pip install flaml[autogen]==2.0.0rc2"
"# %pip install flaml[autogen]==2.0.0rc3"
]
},
{
@ -120,7 +120,7 @@
"source": [
"## Perform a task\n",
"\n",
"We invoke the `receive()` method of the coding agent to start the conversation. When you run the cell below, you will be prompted to provide feedback after receving a message from the coding agent. If you don't provide any feedback (by pressing Enter directly), the user proxy agent will try to execute the code suggested by the coding agent on behalf of you, or terminate if the coding agent sends a \"TERMINATE\" signal in the end of the message."
"We invoke the `receive()` method of the coding agent to start the conversation. When you run the cell below, you will be prompted to provide feedback after the coding agent sends a \"TERMINATE\" signal in the end of the message. If you don't provide any feedback (by pressing Enter directly), the conversation will finish. Before the \"TERMINATE\" signal, the user proxy agent will try to execute the code suggested by the coding agent on behalf of the user."
]
},
{
@ -132,70 +132,65 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" -------------------------------------------------------------------------------- \n",
"\n",
"user (to assistant):\n",
"\n",
"\n",
"Who should read this paper: https://arxiv.org/abs/2306.01337\n",
"\n",
"\n",
" -------------------------------------------------------------------------------- \n",
"\n",
"--------------------------------------------------------------------------------\n",
"assistant (to user):\n",
"To determine who should read the paper, I will fetch and analyze the abstract of the paper.\n",
"\n",
"I will need to check the abstract of the paper to determine who should read it. Let me do that for you.\n",
"\n",
"```python\n",
"import requests\n",
"from bs4 import BeautifulSoup\n",
"\n",
"def get_arxiv_abstract(url):\n",
" response = requests.get(url)\n",
" soup = BeautifulSoup(response.text, 'html.parser')\n",
" abstract = soup.find('blockquote', {'class': 'abstract'}).text.strip()\n",
" return abstract.replace(\"Abstract: \", \"\")\n",
"\n",
"url = \"https://arxiv.org/abs/2306.01337\"\n",
"abstract = get_arxiv_abstract(url)\n",
"print(abstract)\n",
"response = requests.get(url)\n",
"soup = BeautifulSoup(response.text, \"html.parser\")\n",
"abstract = soup.find(\"blockquote\", {\"class\": \"abstract\"}).text.strip()\n",
"\n",
"print(\"Abstract:\", abstract)\n",
"```\n",
"\n",
"Please run this Python code to fetch and display the abstract of the paper. Based on the abstract, we can figure out who should read the paper.\n",
"Please run the above Python code to fetch the abstract of the paper. Based on the abstract, we can determine who should read it.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\n",
">>>>>>>> NO HUMAN INPUT RECEIVED. USING AUTO REPLY FOR THE USER...\n",
"\n",
" -------------------------------------------------------------------------------- \n",
"\n",
"user (to assistant):\n",
"\n",
"exitcode: 0 (execution succeeded)\n",
"Code output: \n",
" Employing Large Language Models (LLMs) to address mathematical problems is an\n",
"Abstract: Abstract: Employing Large Language Models (LLMs) to address mathematical problems is an\n",
"intriguing research endeavor, considering the abundance of math problems\n",
"expressed in natural language across numerous science and engineering fields.\n",
"While several prior works have investigated solving elementary mathematics\n",
"using LLMs, this work explores the frontier of using GPT-4 for solving more\n",
"complex and challenging math problems. We evaluate various ways of using GPT-4.\n",
"Some of them are adapted from existing work, and one is \\MathChat, a\n",
"Some of them are adapted from existing work, and one is MathChat, a\n",
"conversational problem-solving framework newly proposed in this work. We\n",
"perform the evaluation on difficult high school competition problems from the\n",
"MATH dataset, which shows the advantage of the proposed conversational\n",
"approach.\n",
"\n",
"\n",
" -------------------------------------------------------------------------------- \n",
"\n",
"--------------------------------------------------------------------------------\n",
"assistant (to user):\n",
"Based on the abstract, the following people may be interested in reading the paper:\n",
"\n",
"1. Researchers and practitioners working on large language models (LLMs)\n",
"2. Artificial intelligence (AI) and natural language processing (NLP) researchers exploring the application of LLMs in solving mathematical problems\n",
"3. Educators, mathematicians, and researchers studying advanced mathematical problem-solving techniques\n",
"4. Individuals working on conversational AI for math tutoring or educational purposes\n",
"5. Anyone interested in the development and improvement of models like GPT-4 for complex problem-solving\n",
"Based on the abstract, the paper is about using Large Language Models, specifically GPT-4, to solve complex mathematical problems. The paper introduces a conversational problem-solving framework called MathChat and evaluates its performance on challenging high school competition problems from the MATH dataset.\n",
"\n",
"If you belong to any of these categories or have an interest in these topics, you should consider reading the paper.\n",
"The paper should be of interest to the following groups:\n",
"\n",
"TERMINATE\n"
"1. Researchers and practitioners working in the field of artificial intelligence, specifically natural language processing and language models.\n",
"2. Professionals interested in the application of AI for solving mathematical problems.\n",
"3. Educators and instructors focused on teaching mathematics and incorporating AI-based solutions into teaching methodologies.\n",
"\n",
"TERMINATE\n",
"\n",
"--------------------------------------------------------------------------------\n"
]
}
],

View File

@ -71,6 +71,8 @@ Notes:
* [Using MathChat to Solve Math Problems](https://github.com/microsoft/FLAML/blob/main/notebook/autogen_agent_MathChat.ipynb)
* [Multi-Agent Communication and Planning](https://github.com/microsoft/FLAML/blob/main/notebook/autogen_agent_planning.ipynb)
## Enhanced Inference
One can use [`flaml.oai.Completion.create`](../reference/autogen/oai/completion#create) to perform inference.