From 5b2515d4b88977492fef47ee1a0864aa70ad0fee Mon Sep 17 00:00:00 2001 From: Govind Kamtamneni Date: Tue, 21 May 2024 04:48:06 -0700 Subject: [PATCH] update sessions notebook --- agents/autogen/notebooks/.env.example | 3 +- .../autogen/notebooks/OAI_CONFIG_LIST.example | 9 -- agents/autogen/notebooks/aca-sessions.ipynb | 112 ++++++------------ 3 files changed, 40 insertions(+), 84 deletions(-) delete mode 100644 agents/autogen/notebooks/OAI_CONFIG_LIST.example diff --git a/agents/autogen/notebooks/.env.example b/agents/autogen/notebooks/.env.example index bd72a5c2..af97f326 100644 --- a/agents/autogen/notebooks/.env.example +++ b/agents/autogen/notebooks/.env.example @@ -1 +1,2 @@ -ACA_SESSIONS_ENDPOINT= \ No newline at end of file +ACA_SESSIONS_ENDPOINT= +OAI_CONFIG_LIST=[{"model": "gpt-4", "api_key": "", "api_type": "azure", "base_url": "https://.openai.azure.com", "api_version": "2023-12-01-preview"}] \ No newline at end of file diff --git a/agents/autogen/notebooks/OAI_CONFIG_LIST.example b/agents/autogen/notebooks/OAI_CONFIG_LIST.example deleted file mode 100644 index 2d907735..00000000 --- a/agents/autogen/notebooks/OAI_CONFIG_LIST.example +++ /dev/null @@ -1,9 +0,0 @@ -[ - { - "model": "gpt-4", - "api_key": "", - "api_type": "azure", - "base_url": "https://.openai.azure.com", - "api_version": "2023-12-01-preview" - } -] diff --git a/agents/autogen/notebooks/aca-sessions.ipynb b/agents/autogen/notebooks/aca-sessions.ipynb index 5caa3679..1af7aa64 100644 --- a/agents/autogen/notebooks/aca-sessions.ipynb +++ b/agents/autogen/notebooks/aca-sessions.ipynb @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -53,14 +53,12 @@ "\n", "1. Get the Pool endpoint from [Azure Container Apps - Sessions Code Interpreter](https://learn.microsoft.com/en-us/azure/container-apps/sessions-code-interpreter?tabs=azure-cli).\n", "\n", - "2. Copy `.env.example` to `.env` and update it with your sessions endpoint.\n", - "\n", - "3. Copy `OAI_CONFIG_LIST.example` to `OAI_CONFIG_LIST` and update it with your Azure OpenAI values." + "2. Copy `.env.example` to `.env` and update it with your sessions endpoint and Azure OpenAI values" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -103,7 +101,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -180,7 +178,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -201,6 +199,7 @@ " \"All necessary libraries have already been installed.\\n\"\n", " \"Once the task is done, returns 'TERMINATE'.\",\n", " llm_config={\"config_list\":config_list},\n", + " is_termination_msg=lambda msg: \"code output\" in msg[\"content\"]\n", ")\n", "\n", "aca_pool_management_endpoint = ACA_SESSIONS_ENDPOINT\n", @@ -210,6 +209,7 @@ " name=\"CodeExecutor\",\n", " llm_config=False,\n", " code_execution_config={\"executor\": aca_sessions_executor},\n", + " human_input_mode=\"NEVER\",\n", " is_termination_msg=lambda msg: \"TERMINATE\" in msg.get(\"content\", \"\").strip().upper(),\n", ")" ] @@ -223,83 +223,47 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "chat_result = code_executor_agent.initiate_chat(\n", + " code_writer_agent,\n", + " message=\"125 KM/hr for an American?\",\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\u001b[33mCodeExecutor\u001b[0m (to CodeWriter):\n", - "\n", - "What is 30 plus 20?\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[31m\n", - ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", - "\u001b[33mCodeWriter\u001b[0m (to CodeExecutor):\n", - "\n", - "To solve this, you can simply add the two numbers in Python:\n", - "\n", - "```python\n", - "result = 30 + 20\n", - "print(result)\n", - "```\n", - "\n", - "When you run this code, it will output the sum of 30 and 20. \n", - "\n", - "Would you like me to execute this code to get the result?\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[31m\n", - ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", - "\u001b[31m\n", - ">>>>>>>> EXECUTING CODE BLOCK (inferred language is python)...\u001b[0m\n", - "eyJ0eXAiOiJKV1QiLCJyaCI6IjAuQW84RF9YSmZkVHdadDBDMVo3YkJMQXplY3pfWGZTd2hlbHRJdVgyaVVJLWhVc1AtQU5NLiIsImFsZyI6IlJTMjU2IiwieDV0IjoiTDFLZktGSV9qblhid1djMjJ4Wnh3MXNVSEgwIiwia2lkIjoiTDFLZktGSV9qblhid1djMjJ4Wnh3MXNVSEgwIn0.eyJhdWQiOiJodHRwczovL2R5bmFtaWNzZXNzaW9ucy5pbyIsImlzcyI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0Lzc1NWY3MmZkLTE5M2MtNDBiNy1iNTY3LWI2YzEyYzBjZGU3My8iLCJpYXQiOjE3MTQ5MjM1MTUsIm5iZiI6MTcxNDkyMzUxNSwiZXhwIjoxNzE0OTI3NjgwLCJhY3IiOiIxIiwiYWlvIjoiQVRRQnkvNFdBQUFBMHpDUjgwejRUY1FhMHp3eUdQZjUvSnJuNXNrY0M0czNKZEdsR2N4NVBvZnU5YW5MYkxSdlRNYmlwK0Evc1I0bmFBQ0l2TzNmRnk0dVFhQjJjbnFxcXFWdUxCNHBGWlkzandBcU1Pd1Q3WW01ck1BM0M5b01WUW1IMWxJUFVrQmFmL2ttdjdCaG5hUzF1TE5qOXorelBSQ3ZINVg4QjJJaVZEV0tWOFZjRGx1NmFBdFBNVXJNVG9xc0kwMzF6b0dsOUlvV0lic1lXaFBxK1pnUjVDSHhvT1BidUNCOWpVYWM0c2N3ZjlqZXN4TVU3L1lRZSs3TnNzME54SHI5Z3JYMUZhSXVMM0NYNDRUVnJ4YXY2SFZJWGs0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QzLTc2YjE5NGU4NTUwOSJdfQ.cYjJ814-Ybk6Z8ZWOpGO33N4a4g7GNM7CrbTsdtctTYYVlwtK7m0v6H7TFc56LjX-EgxrE17Emm8fUESXsKEDltHxWus-Na3ZiBQgRGh65dgs1dfHWXZ9upvlqAzwtcUB_-TVL7VObNJSh_6IZe3ORsxyi7AlB6gcIMr4EoKlGrYg1mdZxan2EI-46ZPpJBu071ce2Zz1hQxDRlPE4TxCwedhHEl9wB3IfM7cx_mabAZW9Gqktc6hwDI8atBWtXvUzRqS6tTG7vxzfwPGp7AKx1vloQivxgCTA6GaRnqSBz_-k0Hz8Ro9zR43kQ99qWHSafsdhQX5YjGjVSNukUscg\n", - "\u001b[33mCodeExecutor\u001b[0m (to CodeWriter):\n", - "\n", - "exitcode: 0 (execution succeeded)\n", - "Code output: 50\n", - "\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[31m\n", - ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", - "\u001b[33mCodeWriter\u001b[0m (to CodeExecutor):\n", - "\n", - "\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[31m\n", - ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", - "\u001b[33mCodeExecutor\u001b[0m (to CodeWriter):\n", - "\n", - "\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[31m\n", - ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", - "\u001b[33mCodeWriter\u001b[0m (to CodeExecutor):\n", - "\n", - "TERMINATE\n", - "\n", - "--------------------------------------------------------------------------------\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "C:\\Users\\gok\\AppData\\Roaming\\Python\\Python312\\site-packages\\autogen\\agentchat\\conversable_agent.py:1306: UserWarning: Extracted_response from {response} is None.\n", - " warnings.warn(\"Extracted_response from {response} is None.\", UserWarning)\n" + "77.67 mph\n" ] } ], "source": [ - "chat_result = code_executor_agent.initiate_chat(\n", - " code_writer_agent,\n", - " message=\"What is 30 plus 20?\",\n", - ")" + "import re\n", + "\n", + "# Find the message containing 'Code output:' from assistant\n", + "code_output_message = next((msg['content'] for msg in chat_result.chat_history if msg['role'] == 'assistant' and 'Code output:' in msg['content']), None)\n", + "\n", + " # Extract and round the value of 'Code output'\n", + "if code_output_message:\n", + " code_output_match = re.search(r'Code output:\\s*(.*)', code_output_message)\n", + " if code_output_match:\n", + " code_output_value = code_output_match.group(1)\n", + " # Further processing to extract and round the numeric part if necessary\n", + " numeric_match = re.search(r'(\\d+\\.\\d+)', code_output_value)\n", + " if numeric_match:\n", + " rounded_value = round(float(numeric_match.group(1)), 2)\n", + " code_output_value = f\"{rounded_value} mph\"\n", + "\n", + "print(code_output_value)" ] } ],