From 101c31939437774a80230734fd3fd5c5b4393c30 Mon Sep 17 00:00:00 2001 From: Tvrtko Sternak Date: Fri, 20 Dec 2024 12:34:02 +0100 Subject: [PATCH] Notebook polishing --- notebook/agentchat_realtime_swarm.ipynb | 39 ++++++++++++++++++++----- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/notebook/agentchat_realtime_swarm.ipynb b/notebook/agentchat_realtime_swarm.ipynb index 909f5ad95d..2313ca1092 100644 --- a/notebook/agentchat_realtime_swarm.ipynb +++ b/notebook/agentchat_realtime_swarm.ipynb @@ -18,7 +18,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Install AG2 with realtime-twilio dependencies\n", + "## Install AG2 with twilio dependencies\n", "\n", "To use the realtime agent we will connect it to twilio service, this tutorial was inspired by [twilio tutorial](https://www.twilio.com/en-us/blog/voice-ai-assistant-openai-realtime-api-node) for connecting to OpenAPI real-time agent.\n", "\n", @@ -345,6 +345,37 @@ " agent.register_hand_off(ON_CONDITION(triage_agent, transfer_to_triage_description))" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Before you start the server\n", + "\n", + "To run uviconrn server inside the notebook, you will need to use nest_asyncio. This is because Jupyter uses the asyncio event loop, and uvicorn uses its own event loop. nest_asyncio will allow uvicorn to run in Jupyter.\n", + "\n", + "Please install nest_asyncio by running the following cell." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "!pip install nest_asyncio" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "import nest_asyncio\n", + "\n", + "nest_asyncio.apply()" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -378,12 +409,7 @@ "metadata": {}, "outputs": [], "source": [ - "from datetime import datetime\n", - "from time import time\n", - "\n", - "import nest_asyncio\n", "import uvicorn\n", - "from asyncer import asyncify, create_task_group, syncify\n", "from fastapi import FastAPI, Request, WebSocket\n", "from fastapi.responses import HTMLResponse, JSONResponse\n", "from twilio.twiml.voice_response import Connect, VoiceResponse\n", @@ -432,7 +458,6 @@ " await realtime_agent.run()\n", "\n", "\n", - "nest_asyncio.apply()\n", "uvicorn.run(app, host=\"0.0.0.0\", port=5050)" ] }