session_args become runner_args
This commit is contained in:
@@ -101,11 +101,11 @@ async def run_bot(transport):
|
|||||||
|
|
||||||
|
|
||||||
async def bot(
|
async def bot(
|
||||||
session_args: DailyRunnerArguments | SmallWebRTCRunnerArguments | WebSocketRunnerArguments,
|
runner_args: DailyRunnerArguments | SmallWebRTCRunnerArguments | WebSocketRunnerArguments,
|
||||||
):
|
):
|
||||||
"""Main bot entry point compatible with Pipecat Cloud."""
|
"""Main bot entry point compatible with Pipecat Cloud."""
|
||||||
|
|
||||||
if isinstance(session_args, DailyRunnerArguments):
|
if isinstance(runner_args, DailyRunnerArguments):
|
||||||
from pipecat.transports.services.daily import DailyParams, DailyTransport
|
from pipecat.transports.services.daily import DailyParams, DailyTransport
|
||||||
|
|
||||||
if os.environ.get("ENV") != "local":
|
if os.environ.get("ENV") != "local":
|
||||||
@@ -116,8 +116,8 @@ async def bot(
|
|||||||
krisp_filter = None
|
krisp_filter = None
|
||||||
|
|
||||||
transport = DailyTransport(
|
transport = DailyTransport(
|
||||||
session_args.room_url,
|
runner_args.room_url,
|
||||||
session_args.token,
|
runner_args.token,
|
||||||
"Pipecat Bot",
|
"Pipecat Bot",
|
||||||
params=DailyParams(
|
params=DailyParams(
|
||||||
audio_in_enabled=True,
|
audio_in_enabled=True,
|
||||||
@@ -127,7 +127,7 @@ async def bot(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
elif isinstance(session_args, SmallWebRTCRunnerArguments):
|
elif isinstance(runner_args, SmallWebRTCRunnerArguments):
|
||||||
from pipecat.transports.base_transport import TransportParams
|
from pipecat.transports.base_transport import TransportParams
|
||||||
from pipecat.transports.network.small_webrtc import SmallWebRTCTransport
|
from pipecat.transports.network.small_webrtc import SmallWebRTCTransport
|
||||||
|
|
||||||
@@ -137,14 +137,14 @@ async def bot(
|
|||||||
audio_out_enabled=True,
|
audio_out_enabled=True,
|
||||||
vad_analyzer=SileroVADAnalyzer(),
|
vad_analyzer=SileroVADAnalyzer(),
|
||||||
),
|
),
|
||||||
webrtc_connection=session_args.webrtc_connection,
|
webrtc_connection=runner_args.webrtc_connection,
|
||||||
)
|
)
|
||||||
|
|
||||||
elif isinstance(session_args, WebSocketRunnerArguments):
|
elif isinstance(runner_args, WebSocketRunnerArguments):
|
||||||
# Use the utility to parse WebSocket data
|
# Use the utility to parse WebSocket data
|
||||||
from pipecat.runner.utils import parse_telephony_websocket
|
from pipecat.runner.utils import parse_telephony_websocket
|
||||||
|
|
||||||
transport_type, call_data = await parse_telephony_websocket(session_args.websocket)
|
transport_type, call_data = await parse_telephony_websocket(runner_args.websocket)
|
||||||
logger.info(f"Auto-detected transport: {transport_type}")
|
logger.info(f"Auto-detected transport: {transport_type}")
|
||||||
|
|
||||||
# Create transport based on detected type
|
# Create transport based on detected type
|
||||||
@@ -190,7 +190,7 @@ async def bot(
|
|||||||
)
|
)
|
||||||
|
|
||||||
transport = FastAPIWebsocketTransport(
|
transport = FastAPIWebsocketTransport(
|
||||||
websocket=session_args.websocket,
|
websocket=runner_args.websocket,
|
||||||
params=FastAPIWebsocketParams(
|
params=FastAPIWebsocketParams(
|
||||||
audio_in_enabled=True,
|
audio_in_enabled=True,
|
||||||
audio_out_enabled=True,
|
audio_out_enabled=True,
|
||||||
|
|||||||
@@ -137,10 +137,10 @@ async def run_bot(transport):
|
|||||||
|
|
||||||
|
|
||||||
async def bot(
|
async def bot(
|
||||||
session_args: DailyRunnerArguments | SmallWebRTCRunnerArguments | WebSocketRunnerArguments,
|
runner_args: DailyRunnerArguments | SmallWebRTCRunnerArguments | WebSocketRunnerArguments,
|
||||||
):
|
):
|
||||||
"""Main bot entry point compatible with Pipecat Cloud."""
|
"""Main bot entry point compatible with Pipecat Cloud."""
|
||||||
transport = await create_transport(session_args, transport_params)
|
transport = await create_transport(runner_args, transport_params)
|
||||||
await run_bot(transport)
|
await run_bot(transport)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -92,10 +92,10 @@ async def run_bot(transport):
|
|||||||
await runner.run(task)
|
await runner.run(task)
|
||||||
|
|
||||||
|
|
||||||
async def bot(session_args: DailyRunnerArguments | SmallWebRTCRunnerArguments):
|
async def bot(runner_args: DailyRunnerArguments | SmallWebRTCRunnerArguments):
|
||||||
"""Main bot entry point compatible with Pipecat Cloud."""
|
"""Main bot entry point compatible with Pipecat Cloud."""
|
||||||
|
|
||||||
if isinstance(session_args, DailyRunnerArguments):
|
if isinstance(runner_args, DailyRunnerArguments):
|
||||||
from pipecat.transports.services.daily import DailyParams, DailyTransport
|
from pipecat.transports.services.daily import DailyParams, DailyTransport
|
||||||
|
|
||||||
if os.environ.get("ENV") != "local":
|
if os.environ.get("ENV") != "local":
|
||||||
@@ -106,8 +106,8 @@ async def bot(session_args: DailyRunnerArguments | SmallWebRTCRunnerArguments):
|
|||||||
krisp_filter = None
|
krisp_filter = None
|
||||||
|
|
||||||
transport = DailyTransport(
|
transport = DailyTransport(
|
||||||
session_args.room_url,
|
runner_args.room_url,
|
||||||
session_args.token,
|
runner_args.token,
|
||||||
"Pipecat Bot",
|
"Pipecat Bot",
|
||||||
params=DailyParams(
|
params=DailyParams(
|
||||||
audio_in_enabled=True,
|
audio_in_enabled=True,
|
||||||
@@ -117,7 +117,7 @@ async def bot(session_args: DailyRunnerArguments | SmallWebRTCRunnerArguments):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
elif isinstance(session_args, SmallWebRTCRunnerArguments):
|
elif isinstance(runner_args, SmallWebRTCRunnerArguments):
|
||||||
from pipecat.transports.base_transport import TransportParams
|
from pipecat.transports.base_transport import TransportParams
|
||||||
from pipecat.transports.network.small_webrtc import SmallWebRTCTransport
|
from pipecat.transports.network.small_webrtc import SmallWebRTCTransport
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ async def bot(session_args: DailyRunnerArguments | SmallWebRTCRunnerArguments):
|
|||||||
audio_out_enabled=True,
|
audio_out_enabled=True,
|
||||||
vad_analyzer=SileroVADAnalyzer(),
|
vad_analyzer=SileroVADAnalyzer(),
|
||||||
),
|
),
|
||||||
webrtc_connection=session_args.webrtc_connection,
|
webrtc_connection=runner_args.webrtc_connection,
|
||||||
)
|
)
|
||||||
|
|
||||||
await run_bot(transport)
|
await run_bot(transport)
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ async def run_bot(transport):
|
|||||||
await runner.run(task)
|
await runner.run(task)
|
||||||
|
|
||||||
|
|
||||||
async def bot(session_args: SmallWebRTCRunnerArguments):
|
async def bot(runner_args: SmallWebRTCRunnerArguments):
|
||||||
"""Main bot entry point compatible with Pipecat Cloud."""
|
"""Main bot entry point compatible with Pipecat Cloud."""
|
||||||
|
|
||||||
transport = SmallWebRTCTransport(
|
transport = SmallWebRTCTransport(
|
||||||
@@ -100,7 +100,7 @@ async def bot(session_args: SmallWebRTCRunnerArguments):
|
|||||||
audio_out_enabled=True,
|
audio_out_enabled=True,
|
||||||
vad_analyzer=SileroVADAnalyzer(),
|
vad_analyzer=SileroVADAnalyzer(),
|
||||||
),
|
),
|
||||||
webrtc_connection=session_args.webrtc_connection,
|
webrtc_connection=runner_args.webrtc_connection,
|
||||||
)
|
)
|
||||||
|
|
||||||
await run_bot(transport)
|
await run_bot(transport)
|
||||||
|
|||||||
@@ -15,16 +15,16 @@ Install with::
|
|||||||
|
|
||||||
pip install pipecat-ai[runner]
|
pip install pipecat-ai[runner]
|
||||||
|
|
||||||
All bots must implement a `bot(session_args)` async function as the entry point.
|
All bots must implement a `bot(runner_args)` async function as the entry point.
|
||||||
The server automatically discovers and executes this function when connections
|
The server automatically discovers and executes this function when connections
|
||||||
are established.
|
are established.
|
||||||
|
|
||||||
Single transport example::
|
Single transport example::
|
||||||
|
|
||||||
async def bot(session_args: DailyRunnerArguments):
|
async def bot(runner_args: DailyRunnerArguments):
|
||||||
transport = DailyTransport(
|
transport = DailyTransport(
|
||||||
session_args.room_url,
|
runner_args.room_url,
|
||||||
session_args.token,
|
runner_args.token,
|
||||||
"Bot",
|
"Bot",
|
||||||
DailyParams(...)
|
DailyParams(...)
|
||||||
)
|
)
|
||||||
@@ -37,14 +37,14 @@ Single transport example::
|
|||||||
|
|
||||||
Multiple transport example::
|
Multiple transport example::
|
||||||
|
|
||||||
async def bot(session_args):
|
async def bot(runner_args):
|
||||||
# Type-safe transport detection
|
# Type-safe transport detection
|
||||||
if isinstance(session_args, DailyRunnerArguments):
|
if isinstance(runner_args, DailyRunnerArguments):
|
||||||
transport = setup_daily_transport(session_args) # Your application code
|
transport = setup_daily_transport(runner_args) # Your application code
|
||||||
elif isinstance(session_args, SmallWebRTCRunnerArguments):
|
elif isinstance(runner_args, SmallWebRTCRunnerArguments):
|
||||||
transport = setup_webrtc_transport(session_args) # Your application code
|
transport = setup_webrtc_transport(runner_args) # Your application code
|
||||||
elif isinstance(session_args, WebSocketRunnerArguments):
|
elif isinstance(runner_args, WebSocketRunnerArguments):
|
||||||
transport = setup_telephony_transport(session_args) # Your application code
|
transport = setup_telephony_transport(runner_args) # Your application code
|
||||||
|
|
||||||
# Your bot implementation
|
# Your bot implementation
|
||||||
await run_pipeline(transport)
|
await run_pipeline(transport)
|
||||||
@@ -144,9 +144,9 @@ async def _run_telephony_bot(websocket: WebSocket):
|
|||||||
bot_module = _get_bot_module()
|
bot_module = _get_bot_module()
|
||||||
|
|
||||||
# Just pass the WebSocket - let the bot handle parsing
|
# Just pass the WebSocket - let the bot handle parsing
|
||||||
session_args = WebSocketRunnerArguments(websocket=websocket)
|
runner_args = WebSocketRunnerArguments(websocket=websocket)
|
||||||
|
|
||||||
await bot_module.bot(session_args)
|
await bot_module.bot(runner_args)
|
||||||
|
|
||||||
|
|
||||||
def _create_server_app(
|
def _create_server_app(
|
||||||
@@ -221,8 +221,8 @@ def _setup_webrtc_routes(app: FastAPI, esp32_mode: bool = False, host: str = "lo
|
|||||||
pcs_map.pop(webrtc_connection.pc_id, None)
|
pcs_map.pop(webrtc_connection.pc_id, None)
|
||||||
|
|
||||||
bot_module = _get_bot_module()
|
bot_module = _get_bot_module()
|
||||||
session_args = SmallWebRTCRunnerArguments(webrtc_connection=pipecat_connection)
|
runner_args = SmallWebRTCRunnerArguments(webrtc_connection=pipecat_connection)
|
||||||
background_tasks.add_task(bot_module.bot, session_args)
|
background_tasks.add_task(bot_module.bot, runner_args)
|
||||||
|
|
||||||
answer = pipecat_connection.get_answer()
|
answer = pipecat_connection.get_answer()
|
||||||
|
|
||||||
@@ -263,8 +263,8 @@ def _setup_daily_routes(app: FastAPI):
|
|||||||
|
|
||||||
# Start the bot in the background
|
# Start the bot in the background
|
||||||
bot_module = _get_bot_module()
|
bot_module = _get_bot_module()
|
||||||
session_args = DailyRunnerArguments(room_url=room_url, token=token, body={})
|
runner_args = DailyRunnerArguments(room_url=room_url, token=token, body={})
|
||||||
asyncio.create_task(bot_module.bot(session_args))
|
asyncio.create_task(bot_module.bot(runner_args))
|
||||||
return RedirectResponse(room_url)
|
return RedirectResponse(room_url)
|
||||||
|
|
||||||
@app.post("/connect")
|
@app.post("/connect")
|
||||||
@@ -281,8 +281,8 @@ def _setup_daily_routes(app: FastAPI):
|
|||||||
|
|
||||||
# Start the bot in the background
|
# Start the bot in the background
|
||||||
bot_module = _get_bot_module()
|
bot_module = _get_bot_module()
|
||||||
session_args = DailyRunnerArguments(room_url=room_url, token=token, body={})
|
runner_args = DailyRunnerArguments(room_url=room_url, token=token, body={})
|
||||||
asyncio.create_task(bot_module.bot(session_args))
|
asyncio.create_task(bot_module.bot(runner_args))
|
||||||
return {"room_url": room_url, "token": token}
|
return {"room_url": room_url, "token": token}
|
||||||
|
|
||||||
|
|
||||||
@@ -345,7 +345,7 @@ async def _run_daily_direct():
|
|||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
room_url, token = await configure(session)
|
room_url, token = await configure(session)
|
||||||
|
|
||||||
session_args = DailyRunnerArguments(room_url=room_url, token=token, body={})
|
runner_args = DailyRunnerArguments(room_url=room_url, token=token, body={})
|
||||||
|
|
||||||
# Get the bot module and run it directly
|
# Get the bot module and run it directly
|
||||||
bot_module = _get_bot_module()
|
bot_module = _get_bot_module()
|
||||||
@@ -354,7 +354,7 @@ async def _run_daily_direct():
|
|||||||
print(" (Direct connection - no web server needed)")
|
print(" (Direct connection - no web server needed)")
|
||||||
print()
|
print()
|
||||||
|
|
||||||
await bot_module.bot(session_args)
|
await bot_module.bot(runner_args)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -375,7 +375,7 @@ def main():
|
|||||||
-d/--direct: Connect directly to Daily room (automatically sets transport to daily)
|
-d/--direct: Connect directly to Daily room (automatically sets transport to daily)
|
||||||
-v/--verbose: Increase logging verbosity
|
-v/--verbose: Increase logging verbosity
|
||||||
|
|
||||||
The bot file must contain a `bot(session_args)` function as the entry point.
|
The bot file must contain a `bot(runner_args)` function as the entry point.
|
||||||
"""
|
"""
|
||||||
parser = argparse.ArgumentParser(description="Pipecat Development Runner")
|
parser = argparse.ArgumentParser(description="Pipecat Development Runner")
|
||||||
parser.add_argument("--host", type=str, default="localhost", help="Host address")
|
parser.add_argument("--host", type=str, default="localhost", help="Host address")
|
||||||
|
|||||||
@@ -389,15 +389,15 @@ async def _create_telephony_transport(
|
|||||||
|
|
||||||
|
|
||||||
async def create_transport(
|
async def create_transport(
|
||||||
session_args: Any, transport_params: Dict[str, Callable]
|
runner_args: Any, transport_params: Dict[str, Callable]
|
||||||
) -> BaseTransport:
|
) -> BaseTransport:
|
||||||
"""Create a transport from session arguments using factory functions.
|
"""Create a transport from runner arguments using factory functions.
|
||||||
|
|
||||||
This function uses the clean transport_params factory pattern where users
|
This function uses the clean transport_params factory pattern where users
|
||||||
define a dictionary mapping transport names to parameter factory functions.
|
define a dictionary mapping transport names to parameter factory functions.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
session_args: Session arguments from the runner.
|
runner_args: Arguments from the runner.
|
||||||
transport_params: Dict mapping transport names to parameter factory functions.
|
transport_params: Dict mapping transport names to parameter factory functions.
|
||||||
Keys should be: "daily", "webrtc", "twilio", "telnyx", "plivo"
|
Keys should be: "daily", "webrtc", "twilio", "telnyx", "plivo"
|
||||||
Values should be functions that return transport parameters when called.
|
Values should be functions that return transport parameters when called.
|
||||||
@@ -406,7 +406,7 @@ async def create_transport(
|
|||||||
Configured transport instance.
|
Configured transport instance.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ValueError: If transport key is missing from transport_params or session args type is unsupported.
|
ValueError: If transport key is missing from transport_params or runner_args type is unsupported.
|
||||||
ImportError: If required dependencies are not installed.
|
ImportError: If required dependencies are not installed.
|
||||||
|
|
||||||
Example::
|
Example::
|
||||||
@@ -442,40 +442,40 @@ async def create_transport(
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
transport = await create_transport(session_args, transport_params)
|
transport = await create_transport(runner_args, transport_params)
|
||||||
"""
|
"""
|
||||||
# Create transport based on session args type
|
# Create transport based on runner args type
|
||||||
if isinstance(session_args, DailyRunnerArguments):
|
if isinstance(runner_args, DailyRunnerArguments):
|
||||||
params = _get_transport_params("daily", transport_params)
|
params = _get_transport_params("daily", transport_params)
|
||||||
|
|
||||||
from pipecat.transports.services.daily import DailyTransport
|
from pipecat.transports.services.daily import DailyTransport
|
||||||
|
|
||||||
return DailyTransport(
|
return DailyTransport(
|
||||||
session_args.room_url,
|
runner_args.room_url,
|
||||||
session_args.token,
|
runner_args.token,
|
||||||
"Pipecat Bot",
|
"Pipecat Bot",
|
||||||
params=params,
|
params=params,
|
||||||
)
|
)
|
||||||
|
|
||||||
elif isinstance(session_args, SmallWebRTCRunnerArguments):
|
elif isinstance(runner_args, SmallWebRTCRunnerArguments):
|
||||||
params = _get_transport_params("webrtc", transport_params)
|
params = _get_transport_params("webrtc", transport_params)
|
||||||
|
|
||||||
from pipecat.transports.network.small_webrtc import SmallWebRTCTransport
|
from pipecat.transports.network.small_webrtc import SmallWebRTCTransport
|
||||||
|
|
||||||
return SmallWebRTCTransport(
|
return SmallWebRTCTransport(
|
||||||
params=params,
|
params=params,
|
||||||
webrtc_connection=session_args.webrtc_connection,
|
webrtc_connection=runner_args.webrtc_connection,
|
||||||
)
|
)
|
||||||
|
|
||||||
elif isinstance(session_args, WebSocketRunnerArguments):
|
elif isinstance(runner_args, WebSocketRunnerArguments):
|
||||||
# Parse once to determine the provider and get data
|
# Parse once to determine the provider and get data
|
||||||
transport_type, call_data = await parse_telephony_websocket(session_args.websocket)
|
transport_type, call_data = await parse_telephony_websocket(runner_args.websocket)
|
||||||
params = _get_transport_params(transport_type, transport_params)
|
params = _get_transport_params(transport_type, transport_params)
|
||||||
|
|
||||||
# Create telephony transport with pre-parsed data
|
# Create telephony transport with pre-parsed data
|
||||||
return await _create_telephony_transport(
|
return await _create_telephony_transport(
|
||||||
session_args.websocket, params, transport_type, call_data
|
runner_args.websocket, params, transport_type, call_data
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Unsupported session arguments type: {type(session_args)}")
|
raise ValueError(f"Unsupported runner arguments type: {type(runner_args)}")
|
||||||
|
|||||||
Reference in New Issue
Block a user