Skip to content

Commit

Permalink
rename human to user_proxy (#1215)
Browse files Browse the repository at this point in the history
* rename human to user_proxy

* notebook update and bug fix
  • Loading branch information
sonichi authored Sep 11, 2023
1 parent 0cb79df commit 599731c
Show file tree
Hide file tree
Showing 4 changed files with 598 additions and 363 deletions.
2 changes: 1 addition & 1 deletion flaml/autogen/agentchat/responsive_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ def generate_code_execution_reply(
return False, None
if messages is None:
messages = self._oai_messages[sender]
last_n_messages = code_execution_config.pop("last_n_messages", 1)
last_n_messages = min(len(messages), code_execution_config.pop("last_n_messages", 1))
for i in range(last_n_messages):
message = messages[-(i + 1)]
code_blocks = extract_code(message["content"])
Expand Down
168 changes: 74 additions & 94 deletions notebook/autogen_agentchat_groupchat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 105,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -50,7 +50,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 106,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -122,26 +122,27 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 107,
"metadata": {},
"outputs": [],
"source": [
"llm_config = {\"config_list\": config_list_gpt4}\n",
"human = autogen.UserProxyAgent(\n",
" name=\"Human\",\n",
"llm_config = {\"config_list\": config_list_gpt4, \"seed\": 42}\n",
"user_proxy = autogen.UserProxyAgent(\n",
" name=\"User_proxy\",\n",
" system_message=\"A human admin.\",\n",
" code_execution_config={\"last_n_messages\": 2, \"work_dir\": \"groupchat\"},\n",
" human_input_mode=\"TERMINATE\"\n",
")\n",
"alice = autogen.AssistantAgent(\n",
" name=\"Alice\",\n",
"coder = autogen.AssistantAgent(\n",
" name=\"Coder\",\n",
" llm_config=llm_config,\n",
")\n",
"bob = autogen.AssistantAgent(\n",
" name=\"Bob\",\n",
" system_message=\"Scientist. Provide expert knowledge.\",\n",
"pm = autogen.AssistantAgent(\n",
" name=\"Product_manager\",\n",
" system_message=\"Creative in software product ideas.\",\n",
" llm_config=llm_config,\n",
")\n",
"groupchat = autogen.GroupChat(agents=[human, alice, bob], messages=[], max_round=12)\n",
"groupchat = autogen.GroupChat(agents=[user_proxy, coder, pm], messages=[], max_round=12)\n",
"manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config)"
]
},
Expand All @@ -155,133 +156,112 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 108,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33mHuman\u001b[0m (to chat_manager):\n",
"\u001b[33mUser_proxy\u001b[0m (to chat_manager):\n",
"\n",
"Find a latest paper about gpt-4 on arxiv and find its potential application.\n",
"Find a latest paper about gpt-4 on arxiv and find its potential applications in software.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mAlice\u001b[0m (to chat_manager):\n",
"\u001b[33mCoder\u001b[0m (to chat_manager):\n",
"\n",
"To find the latest paper about GPT-4 on arxiv, I will use the arxiv API to query and filter the search results. First, I'll execute the following code to get the latest paper information.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mAlice\u001b[0m (to chat_manager):\n",
"To find the latest paper about GPT-4 on arxiv, I'll provide you with a Python code that fetches the most recent papers from the arxiv API and filters the results to get the most relevant paper related to GPT-4. After fetching the paper, I'll extract the information for potential applications in software. Please execute the following Python code:\n",
"\n",
"```python\n",
"import requests\n",
"from bs4 import BeautifulSoup\n",
"import re\n",
"\n",
"def fetch_arxiv_papers(query):\n",
" base_url = \"http://export.arxiv.org/api/query?\"\n",
" search_query = \"all:\" + query\n",
" response = requests.get(base_url, params={\"search_query\": search_query, \"sortBy\": \"submittedDate\", \"sortOrder\": \"descending\"})\n",
" return BeautifulSoup(response.content, \"xml\")\n",
"\n",
"def search_arxiv(query, sort_by=\"submittedDate\", order=\"descending\", max_results=1):\n",
" search_url = \"http://export.arxiv.org/api/query\"\n",
" query_string = f\"search_query=all:{query.replace(' ', '+')}&sortBy={sort_by}&sortOrder={order}&max_results={max_results}\"\n",
" url = f\"{search_url}?{query_string}\"\n",
" response = requests.get(url)\n",
" return response.text\n",
"\n",
"\n",
"def parse_paper_info(xml_response):\n",
" soup = BeautifulSoup(xml_response, \"lxml-xml\")\n",
" entry = soup.find(\"entry\")\n",
" if not entry:\n",
" return {}\n",
"\n",
" paper_info = {\n",
" \"title\": entry.find(\"title\").text.strip(),\n",
" \"authors\": [author.text for author in entry.find_all(\"author\")],\n",
" \"published\": entry.find(\"published\").text,\n",
" \"updated\": entry.find(\"updated\").text,\n",
" \"summary\": entry.find(\"summary\").text.strip(),\n",
" \"url\": entry.find(\"id\").text,\n",
" }\n",
" return paper_info\n",
"\n",
"def find_gpt4_paper():\n",
" papers = fetch_arxiv_papers(\"gpt-4\")\n",
" for entry in papers.find_all(\"entry\"):\n",
" title = entry.title.text.strip()\n",
" summary = entry.summary.text.strip()\n",
" if \"gpt-4\" in title.lower() or \"gpt-4\" in summary.lower():\n",
" return {\"title\": title, \"summary\": summary}\n",
"\n",
"query = \"gpt-4\"\n",
"arxiv_response = search_arxiv(query)\n",
"paper_info = parse_paper_info(arxiv_response)\n",
"\n",
"if paper_info:\n",
" print(f\"Title: {paper_info['title']}\")\n",
" print(f\"Authors: {', '.join(paper_info['authors'])}\")\n",
" print(f\"Published: {paper_info['published']}\")\n",
" print(f\"Updated: {paper_info['updated']}\")\n",
" print(f\"Abstract: {paper_info['summary']}\")\n",
" print(f\"URL: {paper_info['url']}\")\n",
"gpt4_paper = find_gpt4_paper()\n",
"if gpt4_paper:\n",
" print(\"Title:\", gpt4_paper[\"title\"])\n",
" print(\"Summary:\", gpt4_paper[\"summary\"])\n",
"else:\n",
" print(\"No papers about GPT-4 were found on arxiv.\")\n",
" print(\"No recent GPT-4 papers found.\")\n",
"```\n",
"\n",
"Once we have the paper details, I'll analyze the summary to identify potential applications in software development.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> NO HUMAN INPUT RECEIVED.\u001b[0m\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[31m\n",
">>>>>>>> EXECUTING CODE BLOCK 0 (inferred language is python)...\u001b[0m\n",
"\u001b[33mHuman\u001b[0m (to chat_manager):\n",
"\u001b[33mUser_proxy\u001b[0m (to chat_manager):\n",
"\n",
"exitcode: 0 (execution succeeded)\n",
"Code output: \n",
"Title: Breaking the Bank with ChatGPT: Few-Shot Text Classification for Finance\n",
"Authors: \n",
"Lefteris Loukas\n",
", \n",
"Ilias Stogiannidis\n",
", \n",
"Prodromos Malakasiotis\n",
", \n",
"Stavros Vassos\n",
"Title: FIMO: A Challenge Formal Dataset for Automated Theorem Proving\n",
"Summary: We present FIMO, an innovative dataset comprising formal mathematical problem\n",
"statements sourced from the International Mathematical Olympiad (IMO)\n",
"Shortlisted Problems. Designed to facilitate advanced automated theorem proving\n",
"at the IMO level, FIMO is currently tailored for the Lean formal language. It\n",
"comprises 149 formal problem statements, accompanied by both informal problem\n",
"descriptions and their corresponding LaTeX-based informal proofs. Through\n",
"initial experiments involving GPT-4, our findings underscore the existing\n",
"limitations in current methodologies, indicating a substantial journey ahead\n",
"before achieving satisfactory IMO-level automated theorem proving outcomes.\n",
"\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mProduct_manager\u001b[0m (to chat_manager):\n",
"\n",
"Based on the paper titled \"FIMO: A Challenge Formal Dataset for Automated Theorem Proving\" and its summary, the potential applications of GPT-4 in software development can be related to the field of automated theorem proving.\n",
"\n",
"Published: 2023-08-28T15:04:16Z\n",
"Updated: 2023-08-28T15:04:16Z\n",
"Abstract: We propose the use of conversational GPT models for easy and quick few-shot\n",
"text classification in the financial domain using the Banking77 dataset. Our\n",
"approach involves in-context learning with GPT-3.5 and GPT-4, which minimizes\n",
"the technical expertise required and eliminates the need for expensive GPU\n",
"computing while yielding quick and accurate results. Additionally, we fine-tune\n",
"other pre-trained, masked language models with SetFit, a recent contrastive\n",
"learning technique, to achieve state-of-the-art results both in full-data and\n",
"few-shot settings. Our findings show that querying GPT-3.5 and GPT-4 can\n",
"outperform fine-tuned, non-generative models even with fewer examples. However,\n",
"subscription fees associated with these solutions may be considered costly for\n",
"small organizations. Lastly, we find that generative models perform better on\n",
"the given task when shown representative samples selected by a human expert\n",
"rather than when shown random ones. We conclude that a) our proposed methods\n",
"offer a practical solution for few-shot tasks in datasets with limited label\n",
"availability, and b) our state-of-the-art results can inspire future work in\n",
"the area.\n",
"URL: http://arxiv.org/abs/2308.14634v1\n",
"1. **Automated theorem proving**: GPT-4 can be utilized in the development of automated theorem proving software that attempts to prove complex mathematical problems taken from International Mathematical Olympiad (IMO) or other challenging sources. By fine-tuning GPT-4 with a dataset like FIMO consisting of formal mathematical problems, the model can potentially better understand the problem statements and generate appropriate proofs.\n",
"\n",
"2. **Mathematical problem-solving assistants**: Software tools can be developed using GPT-4 to guide users in solving complex mathematical problems. The AI model can be integrated into educational platforms, online math tutoring services, or even standalone tools to help make solving problems easier and faster for students and professionals alike.\n",
"\n",
"3. **Formal language translation**: GPT-4 can potentially be integrated into software for translating between formal languages, assisting in the understanding and comparison of various formal systems. This would be especially useful in research communities employing different formal languages and wanting to share ideas and results.\n",
"\n",
"4. **Mathematical proof checking**: GPT-4 can be employed in proof-checking software to identify and correct inconsistencies. By improving the correctness of proofs, this application would ultimately help users save time and contribute to the overall quality of mathematical research.\n",
"\n",
"Please note that this paper highlights the current limitations of GPT-4 in the context of IMO-level theorem proving. Nevertheless, these potential applications suggest directions for further research and software development as the model and related techniques continue to improve.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mBob\u001b[0m (to chat_manager):\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mUser_proxy\u001b[0m (to chat_manager):\n",
"\n",
"The latest paper about GPT-4 on arxiv is titled \"Breaking the Bank with ChatGPT: Few-Shot Text Classification for Finance\" by Lefteris Loukas, Ilias Stogiannidis, Prodromos Malakasiotis, and Stavros Vassos. It was published on 2023-08-28.\n",
"\n",
"The potential application of GPT-4 in this paper is for few-shot text classification in the financial domain using the Banking77 dataset. The authors propose using conversational GPT models like GPT-3.5 and GPT-4 for in-context learning, which minimizes the technical expertise required and eliminates the need for expensive GPU computing while yielding quick and accurate results.\n",
"\n",
"Additionally, the paper explores fine-tuning other pre-trained, masked language models with SetFit, a recent contrastive learning technique, to achieve state-of-the-art results in both full-data and few-shot settings.\n",
"--------------------------------------------------------------------------------\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mUser_proxy\u001b[0m (to chat_manager):\n",
"\n",
"\n",
"The findings of this paper show that querying GPT-3.5 and GPT-4 can outperform fine-tuned, non-generative models even with fewer examples. However, subscription fees associated with these solutions may be considered costly for small organizations. The authors also find that generative models perform better on the given task when shown representative samples selected by a human expert rather than when shown random ones. The proposed methods offer a practical solution for few-shot tasks in datasets with limited label availability, and the state-of-the-art results can inspire future work in the area.\n",
"\n",
"You can access the full paper [here](http://arxiv.org/abs/2308.14634v1).\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mCoder\u001b[0m (to chat_manager):\n",
"\n",
"TERMINATE\n",
"\n",
"--------------------------------------------------------------------------------\n"
]
}
],
"source": [
"human.initiate_chat(manager, message=\"Find a latest paper about gpt-4 on arxiv and find its potential application.\")\n",
"user_proxy.initiate_chat(manager, message=\"Find a latest paper about gpt-4 on arxiv and find its potential applications in software.\")\n",
"# type exit to terminate the chat"
]
}
Expand Down
11 changes: 6 additions & 5 deletions notebook/autogen_agentchat_groupchat_research.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
" \"config_list\": config_list_gpt4,\n",
" \"request_timeout\": 120,\n",
"}\n",
"human = autogen.UserProxyAgent(\n",
"user_proxy = autogen.UserProxyAgent(\n",
" name=\"Admin\",\n",
" system_message=\"A human admin. Interact with the planner to discuss the plan. Plan execution needs to be approved by this admin.\",\n",
" code_execution_config=False,\n",
Expand Down Expand Up @@ -155,7 +155,7 @@
" system_message=\"Critic. Double check plan, claims, code from other agents and provide feedback. Check whether the plan includes adding verifiable info such as source URL.\",\n",
" llm_config=gpt4_config,\n",
")\n",
"groupchat = autogen.GroupChat(agents=[human, engineer, scientist, planner, executor, critic], messages=[], max_round=50)\n",
"groupchat = autogen.GroupChat(agents=[user_proxy, engineer, scientist, planner, executor, critic], messages=[], max_round=50)\n",
"manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=gpt4_config)"
]
},
Expand Down Expand Up @@ -473,7 +473,7 @@
}
],
"source": [
"human.initiate_chat(\n",
"user_proxy.initiate_chat(\n",
" manager,\n",
" message=\"\"\"\n",
"find papers on LLM applications from arxiv in the last week, create a markdown table of different domains.\n",
Expand All @@ -482,6 +482,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -527,11 +528,11 @@
}
],
"source": [
"groupchat_nocritic = autogen.GroupChat(agents=[human, engineer, scientist, planner, executor], messages=[], max_round=50)\n",
"groupchat_nocritic = autogen.GroupChat(agents=[user_proxy, engineer, scientist, planner, executor], messages=[], max_round=50)\n",
"for agent in groupchat.agents:\n",
" agent.reset()\n",
"manager_nocritic = autogen.GroupChatManager(groupchat=groupchat_nocritic, llm_config=gpt4_config)\n",
"human.initiate_chat(\n",
"user_proxy.initiate_chat(\n",
" manager_nocritic,\n",
" message=\"\"\"\n",
"find papers on LLM applications from arxiv in the last week, create a markdown table of different domains.\n",
Expand Down
Loading

0 comments on commit 599731c

Please sign in to comment.