speed up notebook in CI and fix CI failures (#2427)

* speed up notebook in CI

* improve notebook

* comment about filter

* bug fix for summary

* bump version to 0.2.26

* restrict openai version

* news update

* add tags in example
This commit is contained in:
Chi Wang 2024-04-18 09:43:34 -07:00 committed by GitHub
parent 442c10bd7b
commit 6636689cb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 313 additions and 306 deletions

View File

@ -5,7 +5,8 @@
[
{
"model": "gpt-4",
"api_key": "<your OpenAI API key here>"
"api_key": "<your OpenAI API key here>",
"tags": ["gpt-4", "tool"]
},
{
"model": "<your Azure OpenAI deployment name>",

View File

@ -14,7 +14,7 @@
<img src="https://github.com/microsoft/autogen/blob/main/website/static/img/flaml.svg" width=200>
<br>
</p> -->
:fire: Mar 26, 2024: Andrew Ng gave a shoutout to AutoGen in [What's next for AI agentic workflows](https://youtu.be/sal78ACtGTc?si=JduUzN_1kDnMq0vF) at Sequoia Capital's AI Ascent.
:fire: Apr 17, 2024: Andrew Ng cited AutoGen in [The Batch newsletter](https://www.deeplearning.ai/the-batch/issue-245/) and [What's next for AI agentic workflows](https://youtu.be/sal78ACtGTc?si=JduUzN_1kDnMq0vF) at Sequoia Capital's AI Ascent (Mar 26).
:fire: Mar 3, 2024: What's new in AutoGen? 📰[Blog](https://microsoft.github.io/autogen/blog/2024/03/03/AutoGen-Update); 📺[Youtube](https://www.youtube.com/watch?v=j_mtwQiaLGU).

View File

@ -1120,19 +1120,18 @@ class ConversableAgent(LLMAgent):
@staticmethod
def _last_msg_as_summary(sender, recipient, summary_args) -> str:
"""Get a chat summary from the last message of the recipient."""
summary = ""
try:
content = recipient.last_message(sender)["content"]
if isinstance(content, str):
summary = content.replace("TERMINATE", "")
elif isinstance(content, list):
# Remove the `TERMINATE` word in the content list.
summary = [
{**x, "text": x["text"].replace("TERMINATE", "")} if isinstance(x, dict) and "text" in x else x
for x in content
]
summary = "\n".join(
x["text"].replace("TERMINATE", "") for x in content if isinstance(x, dict) and "text" in x
)
except (IndexError, AttributeError) as e:
warnings.warn(f"Cannot extract summary using last_msg: {e}. Using an empty str as summary.", UserWarning)
summary = ""
return summary
@staticmethod

View File

@ -1 +1 @@
__version__ = "0.2.25"
__version__ = "0.2.26"

View File

@ -32,7 +32,7 @@
"To gather usage data for a list of agents, we provide an utility function `autogen.gather_usage_summary(agents)` where you pass in a list of agents and gather the usage summary.\n",
"\n",
"## Caution when using Azure OpenAI!\n",
"If you are using azure OpenAI, the model returned from completion doesn't have the version information. The returned model is either 'gpt-35-turbo' or 'gpt-4'. From there, we are calculating the cost based on gpt-3.5-0613: ((0.0015, 0.002) per 1k prompt and completion tokens) and gpt-4-0613: (0.03,0.06). This means the cost is wrong if you are using the 1106 version of the models from azure OpenAI.\n",
"If you are using azure OpenAI, the model returned from completion doesn't have the version information. The returned model is either 'gpt-35-turbo' or 'gpt-4'. From there, we are calculating the cost based on gpt-3.5-turbo-0125: (0.0005, 0.0015) per 1k prompt and completion tokens and gpt-4-0613: (0.03, 0.06). This means the cost can be wrong if you are using a different version from azure OpenAI.\n",
"\n",
"This will be improved in the future. However, the token count summary is accurate. You can use the token count to calculate the cost yourself.\n",
"\n",
@ -55,25 +55,18 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import autogen\n",
"from autogen import AssistantAgent, OpenAIWrapper, UserProxyAgent, gather_usage_summary\n",
"\n",
"# config_list = autogen.config_list_from_json(\n",
"# \"OAI_CONFIG_LIST\",\n",
"# filter_dict={\n",
"# \"model\": [\"gpt-3.5-turbo\", \"gpt-4-1106-preview\"],\n",
"# },\n",
"# )\n",
"\n",
"config_list = autogen.config_list_from_json(\n",
" \"OAI_CONFIG_LIST\",\n",
" # filter_dict={\n",
" # \"model\": [\"gpt-3.5-turbo\", \"gpt-35-turbo\"],\n",
" # },\n",
" filter_dict={\n",
" \"tags\": [\"gpt-3.5-turbo\", \"gpt-3.5-turbo-16k\"], # comment out to get all\n",
" },\n",
")"
]
},
@ -81,21 +74,23 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"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",
"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 tags (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",
" \"model\": \"gpt-3.5-turbo\",\n",
" \"api_key\": \"<your OpenAI API key>\",\n",
" }, # OpenAI API endpoint for gpt-4\n",
" \"tags\": [\"gpt-3.5-turbo\"],\n",
" }, # OpenAI API endpoint for gpt-3.5-turbo\n",
" {\n",
" \"model\": \"gpt-35-turbo-0613\", # 0613 or newer is needed to use functions\n",
" \"base_url\": \"<your Azure OpenAI API base>\", \n",
" \"api_type\": \"azure\", \n",
" \"api_version\": \"2024-02-15-preview\", # 2023-07-01-preview or newer is needed to use functions\n",
" \"api_key\": \"<your Azure OpenAI API key>\"\n",
" \"api_key\": \"<your Azure OpenAI API key>\",\n",
" \"tags\": [\"gpt-3.5-turbo\", \"0613\"],\n",
" }\n",
"]\n",
"```\n",
@ -112,14 +107,14 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.00861\n"
"0.00020600000000000002\n"
]
}
],
@ -128,7 +123,7 @@
"messages = [\n",
" {\"role\": \"user\", \"content\": \"Can you give me 3 useful tips on learning Python? Keep it simple and short.\"},\n",
"]\n",
"response = client.create(messages=messages, model=\"gpt-3.5-turbo\", cache_seed=None)\n",
"response = client.create(messages=messages, cache_seed=None)\n",
"print(response.cost)"
]
},
@ -143,7 +138,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 3,
"metadata": {},
"outputs": [
{
@ -164,7 +159,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 4,
"metadata": {},
"outputs": [
{
@ -172,19 +167,21 @@
"output_type": "stream",
"text": [
"----------------------------------------------------------------------------------------------------\n",
"No actual cost incurred (all completions are using cache).\n",
"Usage summary excluding cached usage: \n",
"Total cost: 0.00023\n",
"* Model 'gpt-35-turbo': cost: 0.00023, prompt_tokens: 25, completion_tokens: 142, total_tokens: 167\n",
"\n",
"Usage summary including cached usage: \n",
"Total cost: 0.01059\n",
"* Model 'gpt-4': cost: 0.01059, prompt_tokens: 25, completion_tokens: 164, total_tokens: 189\n",
"All completions are non-cached: the total cost with cached completions is the same as actual cost.\n",
"----------------------------------------------------------------------------------------------------\n",
"----------------------------------------------------------------------------------------------------\n",
"No actual cost incurred (all completions are using cache).\n",
"Usage summary excluding cached usage: \n",
"Total cost: 0.00023\n",
"* Model 'gpt-35-turbo': cost: 0.00023, prompt_tokens: 25, completion_tokens: 142, total_tokens: 167\n",
"----------------------------------------------------------------------------------------------------\n",
"----------------------------------------------------------------------------------------------------\n",
"Usage summary including cached usage: \n",
"Total cost: 0.01059\n",
"* Model 'gpt-4': cost: 0.01059, prompt_tokens: 25, completion_tokens: 164, total_tokens: 189\n",
"Total cost: 0.00023\n",
"* Model 'gpt-35-turbo': cost: 0.00023, prompt_tokens: 25, completion_tokens: 142, total_tokens: 167\n",
"----------------------------------------------------------------------------------------------------\n"
]
}
@ -192,7 +189,7 @@
"source": [
"# The first creation\n",
"# By default, cache_seed is set to 41 and enabled. If you don't want to use cache, set cache_seed to None.\n",
"response = client.create(messages=messages, model=\"gpt-35-turbo-1106\", cache_seed=41)\n",
"response = client.create(messages=messages, cache_seed=41)\n",
"client.print_usage_summary() # default to [\"actual\", \"total\"]\n",
"client.print_usage_summary(mode=\"actual\") # print actual usage summary\n",
"client.print_usage_summary(mode=\"total\") # print total usage summary"
@ -200,15 +197,15 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"None\n",
"{'total_cost': 0.01059, 'gpt-4': {'cost': 0.01059, 'prompt_tokens': 25, 'completion_tokens': 164, 'total_tokens': 189}}\n"
"{'total_cost': 0.0002255, 'gpt-35-turbo': {'cost': 0.0002255, 'prompt_tokens': 25, 'completion_tokens': 142, 'total_tokens': 167}}\n",
"{'total_cost': 0.0002255, 'gpt-35-turbo': {'cost': 0.0002255, 'prompt_tokens': 25, 'completion_tokens': 142, 'total_tokens': 167}}\n"
]
}
],
@ -220,7 +217,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 6,
"metadata": {},
"outputs": [
{
@ -228,11 +225,13 @@
"output_type": "stream",
"text": [
"----------------------------------------------------------------------------------------------------\n",
"No actual cost incurred (all completions are using cache).\n",
"Usage summary excluding cached usage: \n",
"Total cost: 0.00023\n",
"* Model 'gpt-35-turbo': cost: 0.00023, prompt_tokens: 25, completion_tokens: 142, total_tokens: 167\n",
"\n",
"Usage summary including cached usage: \n",
"Total cost: 0.02118\n",
"* Model 'gpt-4': cost: 0.02118, prompt_tokens: 50, completion_tokens: 328, total_tokens: 378\n",
"Total cost: 0.00045\n",
"* Model 'gpt-35-turbo': cost: 0.00045, prompt_tokens: 50, completion_tokens: 284, total_tokens: 334\n",
"----------------------------------------------------------------------------------------------------\n"
]
}
@ -240,13 +239,13 @@
"source": [
"# Since cache is enabled, the same completion will be returned from cache, which will not incur any actual cost.\n",
"# So actual cost doesn't change but total cost doubles.\n",
"response = client.create(messages=messages, model=\"gpt-35-turbo-1106\", cache_seed=41)\n",
"response = client.create(messages=messages, cache_seed=41)\n",
"client.print_usage_summary()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 7,
"metadata": {},
"outputs": [
{
@ -265,7 +264,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 8,
"metadata": {},
"outputs": [
{
@ -276,15 +275,15 @@
"No actual cost incurred (all completions are using cache).\n",
"\n",
"Usage summary including cached usage: \n",
"Total cost: 0.01059\n",
"* Model 'gpt-4': cost: 0.01059, prompt_tokens: 25, completion_tokens: 164, total_tokens: 189\n",
"Total cost: 0.00023\n",
"* Model 'gpt-35-turbo': cost: 0.00023, prompt_tokens: 25, completion_tokens: 142, total_tokens: 167\n",
"----------------------------------------------------------------------------------------------------\n"
]
}
],
"source": [
"# all completions are returned from cache, so no actual cost incurred.\n",
"response = client.create(messages=messages, model=\"gpt-35-turbo-1106\", cache_seed=41)\n",
"response = client.create(messages=messages, cache_seed=41)\n",
"client.print_usage_summary()"
]
},
@ -302,7 +301,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 9,
"metadata": {},
"outputs": [
{
@ -313,32 +312,22 @@
"\n",
"$x^3=125$. What is x?\n",
"\n",
"--------------------------------------------------------------------------------\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"--------------------------------------------------------------------------------\n",
"\u001b[33massistant\u001b[0m (to ai_user):\n",
"\n",
"To find the value of $x$ when $x^3 = 125$, you can find the cube root of 125. The cube root of a number is a value that, when multiplied by itself three times, gives the original number.\n",
"To find x, we need to take the cube root of 125. The cube root of a number is the number that, when multiplied by itself three times, gives the original number.\n",
"\n",
"The cube root of 125 can be written as $125^{1/3}$ or $\\sqrt[3]{125}$. Since $5 \\times 5 \\times 5 = 125$, it follows that:\n",
"\n",
"$$x = \\sqrt[3]{125} = 5$$\n",
"\n",
"Therefore, $x = 5$.\n",
"In this case, the cube root of 125 is 5 since 5 * 5 * 5 = 125. Therefore, x = 5.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mai_user\u001b[0m (to assistant):\n",
"\n",
"Your calculation is correct. The value of $x$ when $x^3 = 125$ is indeed $x = 5$. Great job!\n",
"That's correct! Well done. The value of x is indeed 5, as you correctly found by taking the cube root of 125. Keep up the good work!\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33massistant\u001b[0m (to ai_user):\n",
"\n",
"Thank you for the confirmation! I'm glad the answer was helpful. If you have any more questions or need assistance with anything else, feel free to ask!\n",
"Thank you! I'm glad I could help. If you have any more questions, feel free to ask!\n",
"\n",
"--------------------------------------------------------------------------------\n"
]
@ -346,10 +335,10 @@
{
"data": {
"text/plain": [
"ChatResult(chat_history=[{'content': '$x^3=125$. What is x?', 'role': 'assistant'}, {'content': 'To find the value of $x$ when $x^3 = 125$, you can find the cube root of 125. The cube root of a number is a value that, when multiplied by itself three times, gives the original number.\\n\\nThe cube root of 125 can be written as $125^{1/3}$ or $\\\\sqrt[3]{125}$. Since $5 \\\\times 5 \\\\times 5 = 125$, it follows that:\\n\\n$$x = \\\\sqrt[3]{125} = 5$$\\n\\nTherefore, $x = 5$.', 'role': 'user'}, {'content': 'Your calculation is correct. The value of $x$ when $x^3 = 125$ is indeed $x = 5$. Great job!', 'role': 'assistant'}, {'content': \"Thank you for the confirmation! I'm glad the answer was helpful. If you have any more questions or need assistance with anything else, feel free to ask!\", 'role': 'user'}], summary=\"Thank you for the confirmation! I'm glad the answer was helpful. If you have any more questions or need assistance with anything else, feel free to ask!\", cost=({'total_cost': 0.022019999999999998, 'gpt-4': {'cost': 0.022019999999999998, 'prompt_tokens': 372, 'completion_tokens': 181, 'total_tokens': 553}}, {'total_cost': 0.022019999999999998, 'gpt-4': {'cost': 0.022019999999999998, 'prompt_tokens': 372, 'completion_tokens': 181, 'total_tokens': 553}}), human_input=[])"
"ChatResult(chat_id=None, chat_history=[{'content': '$x^3=125$. What is x?', 'role': 'assistant'}, {'content': 'To find x, we need to take the cube root of 125. The cube root of a number is the number that, when multiplied by itself three times, gives the original number.\\n\\nIn this case, the cube root of 125 is 5 since 5 * 5 * 5 = 125. Therefore, x = 5.', 'role': 'user'}, {'content': \"That's correct! Well done. The value of x is indeed 5, as you correctly found by taking the cube root of 125. Keep up the good work!\", 'role': 'assistant'}, {'content': \"Thank you! I'm glad I could help. If you have any more questions, feel free to ask!\", 'role': 'user'}], summary=\"Thank you! I'm glad I could help. If you have any more questions, feel free to ask!\", cost={'usage_including_cached_inference': {'total_cost': 0.000333, 'gpt-35-turbo': {'cost': 0.000333, 'prompt_tokens': 282, 'completion_tokens': 128, 'total_tokens': 410}}, 'usage_excluding_cached_inference': {'total_cost': 0.000333, 'gpt-35-turbo': {'cost': 0.000333, 'prompt_tokens': 282, 'completion_tokens': 128, 'total_tokens': 410}}}, human_input=[])"
]
},
"execution_count": 22,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
@ -387,7 +376,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 10,
"metadata": {},
"outputs": [
{
@ -397,8 +386,8 @@
"Agent 'ai_user':\n",
"----------------------------------------------------------------------------------------------------\n",
"Usage summary excluding cached usage: \n",
"Total cost: 0.00669\n",
"* Model 'gpt-4': cost: 0.00669, prompt_tokens: 161, completion_tokens: 31, total_tokens: 192\n",
"Total cost: 0.00011\n",
"* Model 'gpt-35-turbo': cost: 0.00011, prompt_tokens: 114, completion_tokens: 35, total_tokens: 149\n",
"\n",
"All completions are non-cached: the total cost with cached completions is the same as actual cost.\n",
"----------------------------------------------------------------------------------------------------\n",
@ -406,8 +395,8 @@
"Agent 'assistant':\n",
"----------------------------------------------------------------------------------------------------\n",
"Usage summary excluding cached usage: \n",
"Total cost: 0.01533\n",
"* Model 'gpt-4': cost: 0.01533, prompt_tokens: 211, completion_tokens: 150, total_tokens: 361\n",
"Total cost: 0.00022\n",
"* Model 'gpt-35-turbo': cost: 0.00022, prompt_tokens: 168, completion_tokens: 93, total_tokens: 261\n",
"\n",
"All completions are non-cached: the total cost with cached completions is the same as actual cost.\n",
"----------------------------------------------------------------------------------------------------\n"
@ -422,7 +411,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 11,
"metadata": {},
"outputs": [
{
@ -446,17 +435,17 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Actual usage summary for assistant (excluding completion from cache): {'total_cost': 0.01533, 'gpt-4': {'cost': 0.01533, 'prompt_tokens': 211, 'completion_tokens': 150, 'total_tokens': 361}}\n",
"Total usage summary for assistant (including completion from cache): {'total_cost': 0.01533, 'gpt-4': {'cost': 0.01533, 'prompt_tokens': 211, 'completion_tokens': 150, 'total_tokens': 361}}\n",
"Actual usage summary for ai_user_proxy: {'total_cost': 0.00669, 'gpt-4': {'cost': 0.00669, 'prompt_tokens': 161, 'completion_tokens': 31, 'total_tokens': 192}}\n",
"Total usage summary for ai_user_proxy: {'total_cost': 0.00669, 'gpt-4': {'cost': 0.00669, 'prompt_tokens': 161, 'completion_tokens': 31, 'total_tokens': 192}}\n",
"Actual usage summary for assistant (excluding completion from cache): {'total_cost': 0.0002235, 'gpt-35-turbo': {'cost': 0.0002235, 'prompt_tokens': 168, 'completion_tokens': 93, 'total_tokens': 261}}\n",
"Total usage summary for assistant (including completion from cache): {'total_cost': 0.0002235, 'gpt-35-turbo': {'cost': 0.0002235, 'prompt_tokens': 168, 'completion_tokens': 93, 'total_tokens': 261}}\n",
"Actual usage summary for ai_user_proxy: {'total_cost': 0.0001095, 'gpt-35-turbo': {'cost': 0.0001095, 'prompt_tokens': 114, 'completion_tokens': 35, 'total_tokens': 149}}\n",
"Total usage summary for ai_user_proxy: {'total_cost': 0.0001095, 'gpt-35-turbo': {'cost': 0.0001095, 'prompt_tokens': 114, 'completion_tokens': 35, 'total_tokens': 149}}\n",
"Actual usage summary for user_proxy: None\n",
"Total usage summary for user_proxy: None\n"
]
@ -475,20 +464,20 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'total_cost': 0.022019999999999998,\n",
" 'gpt-4': {'cost': 0.022019999999999998,\n",
" 'prompt_tokens': 372,\n",
" 'completion_tokens': 181,\n",
" 'total_tokens': 553}}"
"{'total_cost': 0.000333,\n",
" 'gpt-35-turbo': {'cost': 0.000333,\n",
" 'prompt_tokens': 282,\n",
" 'completion_tokens': 128,\n",
" 'total_tokens': 410}}"
]
},
"execution_count": 26,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}

File diff suppressed because one or more lines are too long

View File

@ -29,7 +29,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 14,
"id": "2b803c17",
"metadata": {},
"outputs": [],
@ -50,7 +50,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 15,
"id": "dca301a4",
"metadata": {},
"outputs": [],
@ -65,9 +65,7 @@
"\n",
"config_list = autogen.config_list_from_json(\n",
" \"OAI_CONFIG_LIST\",\n",
" filter_dict={\n",
" \"model\": [\"gpt-4\", \"gpt-3.5-turbo\", \"gpt-3.5-turbo-16k\"],\n",
" },\n",
" filter_dict={\"tags\": [\"3.5-tool\"]}, # comment out to get all\n",
")"
]
},
@ -77,14 +75,15 @@
"id": "92fde41f",
"metadata": {},
"source": [
"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). Only the models with matching names are kept in the list based on the filter condition.\n",
"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 tags (you can filter by other keys as well). Only the configs with matching tags are kept in the list based on the filter condition.\n",
"\n",
"The config list looks like the following:\n",
"```python\n",
"config_list = [\n",
" {\n",
" 'model': 'gpt-4',\n",
" 'model': 'gpt-3.5-turbo',\n",
" 'api_key': '<your OpenAI API key here>',\n",
" 'tags': ['tool', '3.5-tool'],\n",
" },\n",
" {\n",
" 'model': 'gpt-3.5-turbo',\n",
@ -92,6 +91,7 @@
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2024-02-15-preview',\n",
" 'tags': ['tool', '3.5-tool'],\n",
" },\n",
" {\n",
" 'model': 'gpt-3.5-turbo-16k',\n",
@ -99,6 +99,7 @@
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2024-02-15-preview',\n",
" 'tags': ['tool', '3.5-tool'],\n",
" },\n",
"]\n",
"```\n",
@ -119,7 +120,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 16,
"id": "9fb85afb",
"metadata": {},
"outputs": [],
@ -179,7 +180,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 17,
"id": "3e52bbfe",
"metadata": {},
"outputs": [
@ -203,7 +204,7 @@
" 'required': ['base_amount']}}}]"
]
},
"execution_count": 4,
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
@ -228,7 +229,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 18,
"id": "bd943369",
"metadata": {},
"outputs": [],
@ -246,7 +247,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 19,
"id": "d5518947",
"metadata": {},
"outputs": [
@ -258,12 +259,22 @@
"\n",
"How much is 123.45 USD in EUR?\n",
"\n",
"--------------------------------------------------------------------------------\n",
"--------------------------------------------------------------------------------\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33mchatbot\u001b[0m (to user_proxy):\n",
"\n",
"\u001b[32m***** Suggested tool Call (call_Ak49uR4cwLWyPKs5T2gK9bMg): currency_calculator *****\u001b[0m\n",
"\u001b[32m***** Suggested tool call (call_9ogJS4d40BT1rXfMn7YJb151): currency_calculator *****\u001b[0m\n",
"Arguments: \n",
"{\"base_amount\":123.45}\n",
"{\n",
" \"base_amount\": 123.45,\n",
" \"base_currency\": \"USD\",\n",
" \"quote_currency\": \"EUR\"\n",
"}\n",
"\u001b[32m************************************************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
@ -273,14 +284,14 @@
"\n",
"\u001b[33muser_proxy\u001b[0m (to chatbot):\n",
"\n",
"\u001b[32m***** Response from calling tool \"call_Ak49uR4cwLWyPKs5T2gK9bMg\" *****\u001b[0m\n",
"\u001b[32m***** Response from calling tool (call_9ogJS4d40BT1rXfMn7YJb151) *****\u001b[0m\n",
"112.22727272727272 EUR\n",
"\u001b[32m**********************************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mchatbot\u001b[0m (to user_proxy):\n",
"\n",
"123.45 USD is approximately 112.23 EUR.\n",
"123.45 USD is equivalent to 112.23 EUR.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33muser_proxy\u001b[0m (to chatbot):\n",
@ -306,7 +317,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 20,
"id": "4b5a0edc",
"metadata": {},
"outputs": [
@ -314,7 +325,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Chat summary: 123.45 USD is equivalent to approximately 112.23 EUR.\n"
"Chat summary: 123.45 USD is equivalent to 112.23 EUR.\n"
]
}
],
@ -340,7 +351,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 21,
"id": "7b3d8b58",
"metadata": {},
"outputs": [],
@ -389,7 +400,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 22,
"id": "971ed0d5",
"metadata": {},
"outputs": [
@ -420,7 +431,7 @@
" 'required': ['base']}}}]"
]
},
"execution_count": 8,
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
@ -431,7 +442,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 23,
"id": "ab081090",
"metadata": {},
"outputs": [
@ -443,12 +454,24 @@
"\n",
"How much is 112.23 Euros in US Dollars?\n",
"\n",
"--------------------------------------------------------------------------------\n",
"--------------------------------------------------------------------------------\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33mchatbot\u001b[0m (to user_proxy):\n",
"\n",
"\u001b[32m***** Suggested tool Call (call_G64JQKQBT2rI4vnuA4iz1vmE): currency_calculator *****\u001b[0m\n",
"\u001b[32m***** Suggested tool call (call_BQkSmdFHsrKvmtDWCk0mY5sF): currency_calculator *****\u001b[0m\n",
"Arguments: \n",
"{\"base\":{\"currency\":\"EUR\",\"amount\":112.23},\"quote_currency\":\"USD\"}\n",
"{\n",
" \"base\": {\n",
" \"currency\": \"EUR\",\n",
" \"amount\": 112.23\n",
" },\n",
" \"quote_currency\": \"USD\"\n",
"}\n",
"\u001b[32m************************************************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
@ -458,23 +481,14 @@
"\n",
"\u001b[33muser_proxy\u001b[0m (to chatbot):\n",
"\n",
"\u001b[32m***** Response from calling tool \"call_G64JQKQBT2rI4vnuA4iz1vmE\" *****\u001b[0m\n",
"\u001b[32m***** Response from calling tool (call_BQkSmdFHsrKvmtDWCk0mY5sF) *****\u001b[0m\n",
"{\"currency\":\"USD\",\"amount\":123.45300000000002}\n",
"\u001b[32m**********************************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mchatbot\u001b[0m (to user_proxy):\n",
"\n",
"112.23 Euros is equivalent to approximately 123.45 US Dollars.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33muser_proxy\u001b[0m (to chatbot):\n",
"\n",
"\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mchatbot\u001b[0m (to user_proxy):\n",
"\n",
"112.23 Euros is equivalent to 123.45 US Dollars.\n",
"TERMINATE\n",
"\n",
"--------------------------------------------------------------------------------\n"
@ -491,7 +505,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 24,
"id": "4799f60c",
"metadata": {},
"outputs": [
@ -499,7 +513,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Chat summary: 112.23 Euros is approximately 123.45 US Dollars.\n"
"Chat summary: 112.23 Euros is equivalent to 123.45 US Dollars.\n"
]
}
],
@ -509,7 +523,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 25,
"id": "0064d9cd",
"metadata": {},
"outputs": [
@ -521,12 +535,24 @@
"\n",
"How much is 123.45 US Dollars in Euros?\n",
"\n",
"--------------------------------------------------------------------------------\n",
"--------------------------------------------------------------------------------\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33mchatbot\u001b[0m (to user_proxy):\n",
"\n",
"\u001b[32m***** Suggested tool Call (call_qv2SwJHpKrG73btxNzUnYBoR): currency_calculator *****\u001b[0m\n",
"\u001b[32m***** Suggested tool call (call_Xxol42xTswZHGX60OjvIQRG1): currency_calculator *****\u001b[0m\n",
"Arguments: \n",
"{\"base\":{\"currency\":\"USD\",\"amount\":123.45},\"quote_currency\":\"EUR\"}\n",
"{\n",
" \"base\": {\n",
" \"currency\": \"USD\",\n",
" \"amount\": 123.45\n",
" },\n",
" \"quote_currency\": \"EUR\"\n",
"}\n",
"\u001b[32m************************************************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
@ -536,14 +562,14 @@
"\n",
"\u001b[33muser_proxy\u001b[0m (to chatbot):\n",
"\n",
"\u001b[32m***** Response from calling tool \"call_qv2SwJHpKrG73btxNzUnYBoR\" *****\u001b[0m\n",
"\u001b[32m***** Response from calling tool (call_Xxol42xTswZHGX60OjvIQRG1) *****\u001b[0m\n",
"{\"currency\":\"EUR\",\"amount\":112.22727272727272}\n",
"\u001b[32m**********************************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mchatbot\u001b[0m (to user_proxy):\n",
"\n",
"123.45 US Dollars is approximately 112.23 Euros.\n",
"123.45 US Dollars is equivalent to 112.23 Euros.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33muser_proxy\u001b[0m (to chatbot):\n",
@ -571,7 +597,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 26,
"id": "80b2b42c",
"metadata": {},
"outputs": [
@ -579,7 +605,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Chat history: [{'content': 'How much is 123.45 US Dollars in Euros?', 'role': 'assistant'}, {'tool_calls': [{'id': 'call_qv2SwJHpKrG73btxNzUnYBoR', 'function': {'arguments': '{\"base\":{\"currency\":\"USD\",\"amount\":123.45},\"quote_currency\":\"EUR\"}', 'name': 'currency_calculator'}, 'type': 'function'}], 'content': None, 'role': 'assistant'}, {'content': '{\"currency\":\"EUR\",\"amount\":112.22727272727272}', 'tool_responses': [{'tool_call_id': 'call_qv2SwJHpKrG73btxNzUnYBoR', 'role': 'tool', 'content': '{\"currency\":\"EUR\",\"amount\":112.22727272727272}'}], 'role': 'tool'}, {'content': '123.45 US Dollars is approximately 112.23 Euros.', 'role': 'user'}, {'content': '', 'role': 'assistant'}, {'content': 'TERMINATE', 'role': 'user'}]\n"
"Chat history: [{'content': 'How much is 123.45 US Dollars in Euros?', 'role': 'assistant'}, {'tool_calls': [{'id': 'call_Xxol42xTswZHGX60OjvIQRG1', 'function': {'arguments': '{\\n \"base\": {\\n \"currency\": \"USD\",\\n \"amount\": 123.45\\n },\\n \"quote_currency\": \"EUR\"\\n}', 'name': 'currency_calculator'}, 'type': 'function'}], 'content': None, 'role': 'assistant'}, {'content': '{\"currency\":\"EUR\",\"amount\":112.22727272727272}', 'tool_responses': [{'tool_call_id': 'call_Xxol42xTswZHGX60OjvIQRG1', 'role': 'tool', 'content': '{\"currency\":\"EUR\",\"amount\":112.22727272727272}'}], 'role': 'tool'}, {'content': '123.45 US Dollars is equivalent to 112.23 Euros.', 'role': 'user'}, {'content': '', 'role': 'assistant'}, {'content': 'TERMINATE', 'role': 'user'}]\n"
]
}
],
@ -589,30 +615,30 @@
}
],
"metadata": {
"front_matter": {
"description": "Learn how to register function calls using AssistantAgent and UserProxyAgent in AutoGen.",
"tags": [
"function call",
"tool use"
]
},
"kernelspec": {
"display_name": "flaml_dev",
"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.10.13"
}
"front_matter": {
"description": "Learn how to register function calls using AssistantAgent and UserProxyAgent in AutoGen.",
"tags": [
"function call",
"tool use"
]
},
"kernelspec": {
"display_name": "flaml_dev",
"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.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 5

File diff suppressed because one or more lines are too long

View File

@ -14,7 +14,7 @@ with open(os.path.join(here, "autogen/version.py")) as fp:
__version__ = version["__version__"]
install_requires = [
"openai>=1.3",
"openai>=1.3,<1.21",
"diskcache",
"termcolor",
"flaml",

View File

@ -28,6 +28,7 @@ if not skip_openai:
filter_dict={
"api_type": ["openai"],
"model": [
"gpt-4-turbo",
"gpt-4-turbo-preview",
"gpt-4-0125-preview",
"gpt-4-1106-preview",
@ -640,10 +641,10 @@ def test_gpt_reflection_with_llm() -> None:
if __name__ == "__main__":
test_gpt_assistant_chat()
test_get_assistant_instructions()
test_gpt_assistant_instructions_overwrite()
test_gpt_assistant_existing_no_instructions()
# test_gpt_assistant_chat()
# test_get_assistant_instructions()
# test_gpt_assistant_instructions_overwrite()
# test_gpt_assistant_existing_no_instructions()
test_get_assistant_files()
test_assistant_mismatch_retrieval()
test_gpt_assistant_tools_overwrite()
# test_assistant_mismatch_retrieval()
# test_gpt_assistant_tools_overwrite()