From bb53150e6839a8246b0510228bc6d4d54b62b221 Mon Sep 17 00:00:00 2001 From: Hamdan <96612374+s-hamdananwar@users.noreply.github.com> Date: Wed, 11 Dec 2024 15:13:28 -0800 Subject: [PATCH] fix agent dispatch example imports (#322) --- examples/agent_dispatch.py | 51 ++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/examples/agent_dispatch.py b/examples/agent_dispatch.py index 13a00b79..9e754b44 100644 --- a/examples/agent_dispatch.py +++ b/examples/agent_dispatch.py @@ -1,14 +1,5 @@ import asyncio -import os -import aiohttp -from livekit.protocol.room import RoomConfiguration -from livekit.protocol.agent_dispatch import ( - RoomAgentDispatch, - CreateAgentDispatchRequest, -) -from livekit.api import AccessToken, VideoGrants -from livekit.api.agent_dispatch_service import AgentDispatchService - +from livekit import api room_name = "my-room" agent_name = "test-agent" @@ -22,20 +13,19 @@ """ -async def create_explicit_dispatch(http_session: aiohttp.ClientSession): - agent_dispatch_service = AgentDispatchService( - session=http_session, - url=os.getenv("LIVEKIT_URL"), - api_key=os.getenv("LIVEKIT_API_KEY"), - api_secret=os.getenv("LIVEKIT_API_SECRET"), - ) - dispatch_request = CreateAgentDispatchRequest( - agent_name=agent_name, room=room_name, metadata="my_metadata" +async def create_explicit_dispatch(): + lkapi = api.LiveKitAPI() + + dispatch = await lkapi.agent_dispatch.create_dispatch( + api.CreateAgentDispatchRequest( + agent_name=agent_name, room=room_name, metadata="my_metadata" + ) ) - dispatch = await agent_dispatch_service.create_dispatch(dispatch_request) print("created dispatch", dispatch) - dispatches = await agent_dispatch_service.list_dispatch(room_name=room_name) + + dispatches = await lkapi.agent_dispatch.list_dispatch(room_name=room_name) print(f"there are {len(dispatches)} dispatches in {room_name}") + await lkapi.aclose() """ @@ -48,13 +38,15 @@ async def create_explicit_dispatch(http_session: aiohttp.ClientSession): async def create_token_with_agent_dispatch() -> str: token = ( - AccessToken() + api.AccessToken() .with_identity("my_participant") - .with_grants(VideoGrants(room_join=True, room=room_name)) + .with_grants(api.VideoGrants(room_join=True, room=room_name)) .with_room_config( - RoomConfiguration( + api.RoomConfiguration( agents=[ - RoomAgentDispatch(agent_name="test-agent", metadata="my_metadata") + api.RoomAgentDispatch( + agent_name="test-agent", metadata="my_metadata" + ) ], ), ) @@ -64,11 +56,10 @@ async def create_token_with_agent_dispatch() -> str: async def main(): - async with aiohttp.ClientSession() as http_session: - token = await create_token_with_agent_dispatch() - print("created participant token", token) - print("creating explicit dispatch") - await create_explicit_dispatch(http_session) + token = await create_token_with_agent_dispatch() + print("created participant token", token) + print("creating explicit dispatch") + await create_explicit_dispatch() asyncio.run(main())