From b876426e6942ec94fbbff39df580732f1f31b621 Mon Sep 17 00:00:00 2001 From: Sternakt Date: Fri, 29 Nov 2024 19:28:42 +0100 Subject: [PATCH] Fix custom client tests Signed-off-by: Sternakt --- notebook/agentchat_structured_outputs.ipynb | 50 ++++++++++----------- test/oai/test_custom_client.py | 4 +- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/notebook/agentchat_structured_outputs.ipynb b/notebook/agentchat_structured_outputs.ipynb index 6e8087a717..cdf51fc751 100644 --- a/notebook/agentchat_structured_outputs.ipynb +++ b/notebook/agentchat_structured_outputs.ipynb @@ -5,12 +5,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Group Chat\n", + "# Structured output\n", "\n", - "AutoGen offers conversable agents powered by LLM, tool or human, which can be used to perform tasks collectively via automated chat. This framework allows tool use and human participation through multi-agent conversation.\n", - "Please find documentation about this feature [here](https://ag2ai.github.io/ag2/docs/Use-Cases/agent_chat).\n", + "OpenAI offers a functionality for defining a structure of the messages generated by LLMs, AutoGen enables this functionality by propagating `response_format` passed to your agents to the underlying client.\n", + "\n", + "For more info on structured output, please check [here](https://platform.openai.com/docs/guides/structured-outputs)\n", "\n", - "This notebook is modified based on https://github.com/ag2ai/FLAML/blob/4ea686af5c3e8ff24d9076a7a626c8b28ab5b1d7/notebook/autogen_multiagent_roleplay_chat.ipynb\n", "\n", "````{=mdx}\n", ":::info Requirements\n", @@ -24,6 +24,11 @@ "````" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, { "attachments": {}, "cell_type": "markdown", @@ -36,7 +41,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -45,7 +50,7 @@ "config_list = autogen.config_list_from_json(\n", " \"OAI_CONFIG_LIST\",\n", " filter_dict={\n", - " \"model\": [\"gpt-3.5-turbo\"],\n", + " \"model\": [\"gpt-4o\", \"gpt-4o-mini\"],\n", " },\n", ")" ] @@ -116,29 +121,24 @@ "\n", "What's up\n", "\n", + "--------------------------------------------------------------------------------\n", + "[autogen.oai.client: 11-29 19:13:00] {921} INFO - Failed to cache response: Can't pickle : attribute lookup ParsedChatCompletion[ResponseModel] on openai.types.chat.parsed_chat_completion failed\n", + "\u001b[33mAssistant\u001b[0m (to User_proxy):\n", + "\n", + "{\"question\":\"What's the current date and time?\",\"short_answer\":\"You can get the current date and time by executing the following code:\",\"reasoning\":\"To get the current date and time, we can use Python's built-in datetime module which provides functions to get the current date and time. By executing the code snippet, you will be able to see the current date and time.\",\"difficulty\":1}\n", + "\n", "--------------------------------------------------------------------------------\n" ] }, { - "ename": "PicklingError", - "evalue": "Can't pickle : attribute lookup ParsedChatCompletion[ResponseModel] on openai.types.chat.parsed_chat_completion failed", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mPicklingError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[3], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43muser_proxy\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minitiate_chat\u001b[49m\u001b[43m(\u001b[49m\u001b[43massistant\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmessage\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mWhat\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43ms up\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmax_turns\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msummary_method\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mlast_msg\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/ag2/autogen/agentchat/conversable_agent.py:1106\u001b[0m, in \u001b[0;36mConversableAgent.initiate_chat\u001b[0;34m(self, recipient, clear_history, silent, cache, max_turns, summary_method, summary_args, message, **kwargs)\u001b[0m\n\u001b[1;32m 1104\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m msg2send \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 1105\u001b[0m \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[0;32m-> 1106\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmsg2send\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrecipient\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrequest_reply\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msilent\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msilent\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1107\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1108\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_prepare_chat(recipient, clear_history)\n", - "File \u001b[0;32m~/ag2/autogen/agentchat/conversable_agent.py:748\u001b[0m, in \u001b[0;36mConversableAgent.send\u001b[0;34m(self, message, recipient, request_reply, silent)\u001b[0m\n\u001b[1;32m 746\u001b[0m valid \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_append_oai_message(message, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124massistant\u001b[39m\u001b[38;5;124m\"\u001b[39m, recipient, is_sending\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[1;32m 747\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m valid:\n\u001b[0;32m--> 748\u001b[0m \u001b[43mrecipient\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mreceive\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmessage\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrequest_reply\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msilent\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 749\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 750\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m 751\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMessage can\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mt be converted into a valid ChatCompletion message. Either content or function_call must be provided.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 752\u001b[0m )\n", - "File \u001b[0;32m~/ag2/autogen/agentchat/conversable_agent.py:913\u001b[0m, in \u001b[0;36mConversableAgent.receive\u001b[0;34m(self, message, sender, request_reply, silent)\u001b[0m\n\u001b[1;32m 911\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m request_reply \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mFalse\u001b[39;00m \u001b[38;5;129;01mor\u001b[39;00m request_reply \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mreply_at_receive[sender] \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mFalse\u001b[39;00m:\n\u001b[1;32m 912\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m\n\u001b[0;32m--> 913\u001b[0m reply \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate_reply\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmessages\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mchat_messages\u001b[49m\u001b[43m[\u001b[49m\u001b[43msender\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msender\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msender\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 914\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m reply \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 915\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msend(reply, sender, silent\u001b[38;5;241m=\u001b[39msilent)\n", - "File \u001b[0;32m~/ag2/autogen/agentchat/conversable_agent.py:2071\u001b[0m, in \u001b[0;36mConversableAgent.generate_reply\u001b[0;34m(self, messages, sender, **kwargs)\u001b[0m\n\u001b[1;32m 2069\u001b[0m \u001b[38;5;28;01mcontinue\u001b[39;00m\n\u001b[1;32m 2070\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_match_trigger(reply_func_tuple[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtrigger\u001b[39m\u001b[38;5;124m\"\u001b[39m], sender):\n\u001b[0;32m-> 2071\u001b[0m final, reply \u001b[38;5;241m=\u001b[39m \u001b[43mreply_func\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmessages\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msender\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msender\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mreply_func_tuple\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mconfig\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2072\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m logging_enabled():\n\u001b[1;32m 2073\u001b[0m log_event(\n\u001b[1;32m 2074\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 2075\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mreply_func_executed\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 2079\u001b[0m reply\u001b[38;5;241m=\u001b[39mreply,\n\u001b[1;32m 2080\u001b[0m )\n", - "File \u001b[0;32m~/ag2/autogen/agentchat/conversable_agent.py:1435\u001b[0m, in \u001b[0;36mConversableAgent.generate_oai_reply\u001b[0;34m(self, messages, sender, config)\u001b[0m\n\u001b[1;32m 1433\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m messages \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 1434\u001b[0m messages \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_oai_messages[sender]\n\u001b[0;32m-> 1435\u001b[0m extracted_response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate_oai_reply_from_client\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1436\u001b[0m \u001b[43m \u001b[49m\u001b[43mclient\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_oai_system_message\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mclient_cache\u001b[49m\n\u001b[1;32m 1437\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1438\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m (\u001b[38;5;28;01mFalse\u001b[39;00m, \u001b[38;5;28;01mNone\u001b[39;00m) \u001b[38;5;28;01mif\u001b[39;00m extracted_response \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m (\u001b[38;5;28;01mTrue\u001b[39;00m, extracted_response)\n", - "File \u001b[0;32m~/ag2/autogen/agentchat/conversable_agent.py:1454\u001b[0m, in \u001b[0;36mConversableAgent._generate_oai_reply_from_client\u001b[0;34m(self, llm_client, messages, cache)\u001b[0m\n\u001b[1;32m 1451\u001b[0m all_messages\u001b[38;5;241m.\u001b[39mappend(message)\n\u001b[1;32m 1453\u001b[0m \u001b[38;5;66;03m# TODO: #1143 handle token limit exceeded error\u001b[39;00m\n\u001b[0;32m-> 1454\u001b[0m response \u001b[38;5;241m=\u001b[39m \u001b[43mllm_client\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcreate\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1455\u001b[0m \u001b[43m \u001b[49m\u001b[43mcontext\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmessages\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpop\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcontext\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1456\u001b[0m \u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mall_messages\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1457\u001b[0m \u001b[43m \u001b[49m\u001b[43mcache\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcache\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1458\u001b[0m \u001b[43m \u001b[49m\u001b[43magent\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1459\u001b[0m \u001b[43m \u001b[49m\u001b[43mresponse_format\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_response_format\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1460\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1461\u001b[0m extracted_response \u001b[38;5;241m=\u001b[39m llm_client\u001b[38;5;241m.\u001b[39mextract_text_or_completion_object(response)[\u001b[38;5;241m0\u001b[39m]\n\u001b[1;32m 1463\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m extracted_response \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n", - "File \u001b[0;32m~/ag2/autogen/oai/client.py:918\u001b[0m, in \u001b[0;36mOpenAIWrapper.create\u001b[0;34m(self, response_format, **config)\u001b[0m\n\u001b[1;32m 915\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m cache_client \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 916\u001b[0m \u001b[38;5;66;03m# Cache the response\u001b[39;00m\n\u001b[1;32m 917\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m cache_client \u001b[38;5;28;01mas\u001b[39;00m cache:\n\u001b[0;32m--> 918\u001b[0m \u001b[43mcache\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mset\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mresponse\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 919\u001b[0m \u001b[38;5;66;03m# try:\u001b[39;00m\n\u001b[1;32m 920\u001b[0m \u001b[38;5;66;03m# cache.set(key, response)\u001b[39;00m\n\u001b[1;32m 921\u001b[0m \u001b[38;5;66;03m# except PicklingError as e:\u001b[39;00m\n\u001b[1;32m 922\u001b[0m \u001b[38;5;66;03m# logger.info(f\"Failed to cache response: {e}\")\u001b[39;00m\n\u001b[1;32m 925\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m logging_enabled():\n\u001b[1;32m 926\u001b[0m \u001b[38;5;66;03m# TODO: log the config_id and pass_filter etc.\u001b[39;00m\n", - "File \u001b[0;32m~/ag2/autogen/cache/disk_cache.py:73\u001b[0m, in \u001b[0;36mDiskCache.set\u001b[0;34m(self, key, value)\u001b[0m\n\u001b[1;32m 65\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mset\u001b[39m(\u001b[38;5;28mself\u001b[39m, key: \u001b[38;5;28mstr\u001b[39m, value: Any) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 66\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 67\u001b[0m \u001b[38;5;124;03m Set an item in the cache.\u001b[39;00m\n\u001b[1;32m 68\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 71\u001b[0m \u001b[38;5;124;03m value: The value to be stored in the cache.\u001b[39;00m\n\u001b[1;32m 72\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m---> 73\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcache\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mset\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mvalue\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/ag2/.venv/lib/python3.9/site-packages/diskcache/core.py:772\u001b[0m, in \u001b[0;36mCache.set\u001b[0;34m(self, key, value, expire, read, tag, retry)\u001b[0m\n\u001b[1;32m 770\u001b[0m db_key, raw \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_disk\u001b[38;5;241m.\u001b[39mput(key)\n\u001b[1;32m 771\u001b[0m expire_time \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01mif\u001b[39;00m expire \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m now \u001b[38;5;241m+\u001b[39m expire\n\u001b[0;32m--> 772\u001b[0m size, mode, filename, db_value \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_disk\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstore\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvalue\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mread\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkey\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mkey\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 773\u001b[0m columns \u001b[38;5;241m=\u001b[39m (expire_time, tag, size, mode, filename, db_value)\n\u001b[1;32m 775\u001b[0m \u001b[38;5;66;03m# The order of SELECT, UPDATE, and INSERT is important below.\u001b[39;00m\n\u001b[1;32m 776\u001b[0m \u001b[38;5;66;03m#\u001b[39;00m\n\u001b[1;32m 777\u001b[0m \u001b[38;5;66;03m# Typical cache usage pattern is:\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 793\u001b[0m \u001b[38;5;66;03m# INSERT OR REPLACE aka UPSERT is not used because the old filename may\u001b[39;00m\n\u001b[1;32m 794\u001b[0m \u001b[38;5;66;03m# need cleanup.\u001b[39;00m\n", - "File \u001b[0;32m~/ag2/.venv/lib/python3.9/site-packages/diskcache/core.py:221\u001b[0m, in \u001b[0;36mDisk.store\u001b[0;34m(self, value, read, key)\u001b[0m\n\u001b[1;32m 219\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m size, MODE_BINARY, filename, \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 220\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 221\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[43mpickle\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdumps\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvalue\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mprotocol\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpickle_protocol\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 223\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(result) \u001b[38;5;241m<\u001b[39m min_file_size:\n\u001b[1;32m 224\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;241m0\u001b[39m, MODE_PICKLE, \u001b[38;5;28;01mNone\u001b[39;00m, sqlite3\u001b[38;5;241m.\u001b[39mBinary(result)\n", - "\u001b[0;31mPicklingError\u001b[0m: Can't pickle : attribute lookup ParsedChatCompletion[ResponseModel] on openai.types.chat.parsed_chat_completion failed" - ] + "data": { + "text/plain": [ + "ChatResult(chat_id=None, chat_history=[{'content': \"What's up\", 'role': 'assistant', 'name': 'User_proxy'}, {'content': '{\"question\":\"What\\'s the current date and time?\",\"short_answer\":\"You can get the current date and time by executing the following code:\",\"reasoning\":\"To get the current date and time, we can use Python\\'s built-in datetime module which provides functions to get the current date and time. By executing the code snippet, you will be able to see the current date and time.\",\"difficulty\":1}', 'tool_calls': [], 'role': 'user', 'name': 'Assistant'}], summary='{\"question\":\"What\\'s the current date and time?\",\"short_answer\":\"You can get the current date and time by executing the following code:\",\"reasoning\":\"To get the current date and time, we can use Python\\'s built-in datetime module which provides functions to get the current date and time. By executing the code snippet, you will be able to see the current date and time.\",\"difficulty\":1}', cost={'usage_including_cached_inference': {'total_cost': 0.0021725000000000004, 'gpt-4o-2024-08-06': {'cost': 0.0021725000000000004, 'prompt_tokens': 541, 'completion_tokens': 82, 'total_tokens': 623}}, 'usage_excluding_cached_inference': {'total_cost': 0.0021725000000000004, 'gpt-4o-2024-08-06': {'cost': 0.0021725000000000004, 'prompt_tokens': 541, 'completion_tokens': 82, 'total_tokens': 623}}}, human_input=[])" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ diff --git a/test/oai/test_custom_client.py b/test/oai/test_custom_client.py index 5976b7a46f..9e05b8a606 100644 --- a/test/oai/test_custom_client.py +++ b/test/oai/test_custom_client.py @@ -41,7 +41,7 @@ def __init__(self, config: Dict, test_hook): self.test_hook["other_params"] = self.other_params self.test_hook["max_length"] = self.max_length - def create(self, params): + def create(self, params, response_format): from types import SimpleNamespace response = SimpleNamespace() @@ -177,7 +177,7 @@ def __init__(self, config: Dict, test_hook): self.test_hook = test_hook self.test_hook["called"] = True - def create(self, params): + def create(self, params, response_format): from types import SimpleNamespace response = SimpleNamespace()