"# Auto Generated Agent Chat: GPTAssistant with Code Interpreter\n",
"The latest released Assistants API by OpenAI allows users to build AI assistants within their own applications. The Assistants API currently supports three types of tools: Code Interpreter, Retrieval, and Function calling. In this notebook, we demonstrate how to enable `GPTAssistantAgent` to use code interpreter. \n",
"\n",
"## Requirements\n",
"\n",
"AutoGen requires `Python>=3.8`. To run this notebook example, please install:\n",
"```bash\n",
"pip install pyautogen\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Set your API Endpoint\n",
"\n",
"The [`config_list_from_json`](https://microsoft.github.io/autogen/docs/reference/oai/openai_utils#config_list_from_json) function loads a list of configurations from an environment variable or a json file."
"It first looks for environment variable \"OAI_CONFIG_LIST\" which needs to be a valid json string. If that variable is not found, it then looks for a json file named \"OAI_CONFIG_LIST\". It filters the configs by models (you can filter by other keys as well).\n",
"\n",
"The config list looks like the following:\n",
"```python\n",
"config_list = [\n",
" {\n",
" \"model\": \"gpt-4\",\n",
" \"api_key\": \"<your OpenAI API key>\",\n",
" }, # OpenAI API endpoint for gpt-4\n",
"]\n",
"```\n",
"\n",
"Currently Azure OpenAi does not support assistant api. You can set the value of config_list in any way you prefer. Please refer to this [notebook](https://github.com/microsoft/autogen/blob/main/notebook/oai_openai_utils.ipynb) for full code examples of the different methods."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Perform Tasks Using Code Interpreter\n",
"\n",
"We demonstrate task solving using `GPTAssistantAgent` with code interpreter. Pass `code_interpreter` in `tools` parameter to enable `GPTAssistantAgent` with code interpreter. It will write code and automatically execute it in a sandbox. The agent will receive the results from the sandbox environment and act accordingly.\n",
"\n",
"### Example 1: Math Problem Solving\n",
"In this example, we demonstrate how to use code interpreter to solve math problems.\n"
" instructions=\"You are an expert at solving math questions. Write code and run it to solve math problems. Reply TERMINATE when the task is solved and there is no problem.\",\n",
")\n",
"\n",
"user_proxy = UserProxyAgent(\n",
" name=\"user_proxy\",\n",
" is_termination_msg=lambda msg: \"TERMINATE\" in msg[\"content\"],\n",
" \"use_docker\": False, # Please set use_docker=True if docker is available to run the generated code. Using docker is safer than running the generated code directly.\n",
"To draw a line chart showing the population trend in the US, we need some population data over a range of years. Normally, this data can be obtained from sources like the United States Census Bureau or other datasets available online.\n",
"Since I don't have internet access to download the latest data directly, you can provide the data if you have it. The data should ideally consist of two columns: one for the years and one for the corresponding US population for each year.\n",
"If you don't have the data, I can demonstrate how to generate the line chart with some dummy data to illustrate the process. Would you like to provide the data or should I use dummy data for the demonstration?\n",
"It seems there was no response regarding the data, so let's proceed with some dummy data to demonstrate the process. I'll create a Python script that will generate a line chart showing the hypothetical population trend in the US from the year 1900 to 2000. I'll assume a simple linear growth in population for the sake of this example.\n",
"Here is a line chart showing the hypothetical population trend of the US from the year 1900 to 2000. The data is dummy and assumes linear growth in the population.\n",
"\n",
"If you have actual data or would like to see a different representation, please let me know. Otherwise, if everything looks good with this example chart, let me know if there is anything else I can help with. \n",