RealtimeAgent with gemini client using websockets
notebooks/agentchat_realtime_websocket/static
and
notebooks/agentchat_realtime_websocket/templates
folders are available
in the correct relative paths.
ag2
:WebSocketAudioAdapter
to enable you to connect your
realtime agent to a websocket service.
To be able to run this notebook, you will need to install ag2, fastapi,
uvicorn and jinja2.
ag2
with additional dependencies to run a fastAPI server:llm_config
and realtime_llm_config
LLMConfig.from_json
method loads a list of configurations from an environment variable or a
json file.
PORT
variable to 5050
, which will be
used for the server.FastAPI
instance named
app
, which serves as the main application.GET
endpoint at the root URL
(/
). When accessed, it returns a JSON response with the message
"Websocket Audio Stream Server is running!"
.start-chat
endpointnotebook_path
as the current
working directory using os.getcwd()
.static
directory (inside
agentchat_realtime_websocket
) to serve JavaScript, CSS, and other
static assets under the /static
path.templates
directory within agentchat_realtime_websocket
./start-chat/
Endpoint: Define a GET
route that
serves the chat.html
template. Pass the client’s request
and the
port
variable to the template for rendering a dynamic page for the
audio chat interface./media-stream
WebSocket route to handle audio streaming.WebSocketAudioAdapter
,
connecting the WebSocket to handle audio streaming with logging.RealtimeAgent
with the
following:
Weather Bot
.realtime_llm_config
for language
model settings.audio_adapter
.get_weather
to
the agent, allowing it to respond with basic weather information
based on the provided location
.realtime_agent
to handle interactions
in real time.