From 875ecf7fcb744f1af9ff6c29da9f68ed93993a2f Mon Sep 17 00:00:00 2001 From: James Hush Date: Tue, 10 Dec 2024 15:12:30 +0800 Subject: [PATCH] Add command line args Fix --- .../batch_dialout_bot.py | 17 ++++++------ .../batch_dialout_demo.py | 26 ++++++++++++++----- examples/batch-dialout-chatbot/output.csv | 2 +- examples/dialin-chatbot/bot_runner.py | 3 ++- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/examples/batch-dialout-chatbot/batch_dialout_bot.py b/examples/batch-dialout-chatbot/batch_dialout_bot.py index a9cdbeb6c..6a14b1da2 100644 --- a/examples/batch-dialout-chatbot/batch_dialout_bot.py +++ b/examples/batch-dialout-chatbot/batch_dialout_bot.py @@ -80,21 +80,20 @@ class DialoutBot: task = PipelineTask(pipeline, PipelineParams(allow_interruptions=True)) def get_phone_number(callId: int, run_number: int) -> str: - # Avoca 818-722-9086 - # Dom: "+1 562-286-9362" - if run_number % 2 == 0: phone_numbers = [ - "+12097135124", # James - "+12097135125", # James - "+19499870006", # Varun + "+12097743694", # James (Daily Pipecat Local Computer) + # "+12097135124", # James + # "+12097135125", # James + # "+19499870006", # Varun ] return phone_numbers[callId % len(phone_numbers)] else: phone_numbers = [ - "+14155204406", # James - "+18187229086", # James (Avoca) - "+16673870006", # Varun + "+12097743694", # James (Daily Pipecat Local Computer) + # "+14155204406", # James + # "+18187229086", # James (Avoca) + # "+16673870006", # Varun ] return phone_numbers[callId % len(phone_numbers)] diff --git a/examples/batch-dialout-chatbot/batch_dialout_demo.py b/examples/batch-dialout-chatbot/batch_dialout_demo.py index ffe5398cd..6022904ea 100644 --- a/examples/batch-dialout-chatbot/batch_dialout_demo.py +++ b/examples/batch-dialout-chatbot/batch_dialout_demo.py @@ -1,3 +1,4 @@ +import argparse import asyncio import csv import os @@ -16,7 +17,7 @@ from pipecat.transports.services.helpers.daily_rest import ( BOT_RUN_TIME = 300 -async def run_bot(id: int, run_number: int, csv_writer): +async def run_bot(id: int, run_number: int, bot_run_time: int, csv_writer): async with aiohttp.ClientSession() as aiohttp_session: print(f"Starting bot number: {id}") rest = DailyRESTHelper( @@ -71,19 +72,30 @@ async def run_bot(id: int, run_number: int, csv_writer): async def main(): + parser = argparse.ArgumentParser(description="Pipecat Simple Dialout Bot") + parser.add_argument("-b", type=int, help="Number of bots per run") + parser.add_argument("-r", type=int, help="Number of runs") + parser.add_argument("-t", type=int, help="Time to run the bot in seconds") + config = parser.parse_args() + + number_of_batches = int(config.r) + number_of_bots = int(config.b) + bot_run_time = int(config.t) + # Open the CSV file in append mode with open("output.csv", mode="w", newline="") as file: csv_writer = csv.writer(file) # Write the header row csv_writer.writerow(["bot_id", "enable_dialout", "timestamp"]) - for run_number in range(1): - print(f"-- Starting batch run number: {run_number}") - bots = [run_bot(i, run_number, csv_writer) for i in range(1)] + for run_number in range(number_of_batches): + print(f"-- Starting batch run number: {run_number} of {number_of_batches}") + bots = [run_bot(i, run_number, bot_run_time, csv_writer) for i in range(number_of_bots)] + print(f"-- Number of bots: {len(bots)}") await asyncio.gather(*bots) - print("-- Batch finished, waiting 60 seconds...") - await asyncio.sleep(BOT_RUN_TIME + 60) - print("-- Finished waiting 60 seconds...") + print(f"-- Waiting {bot_run_time} seconds...") + await asyncio.sleep(bot_run_time) + print(f"-- Finished waiting {bot_run_time} seconds...") if __name__ == "__main__": diff --git a/examples/batch-dialout-chatbot/output.csv b/examples/batch-dialout-chatbot/output.csv index 7c74e589f..ab5639cef 100644 --- a/examples/batch-dialout-chatbot/output.csv +++ b/examples/batch-dialout-chatbot/output.csv @@ -1,2 +1,2 @@ bot_id,enable_dialout,timestamp -0,True,2024-11-13 17:16:41.533 +0,True,2024-12-10 14:57:45.708 diff --git a/examples/dialin-chatbot/bot_runner.py b/examples/dialin-chatbot/bot_runner.py index 050ad62b9..ce5898d87 100644 --- a/examples/dialin-chatbot/bot_runner.py +++ b/examples/dialin-chatbot/bot_runner.py @@ -170,7 +170,8 @@ async def daily_start_bot(request: Request) -> JSONResponse: # forward the call to the SIP URi when dialin_ready fires. # Use specified room URL, or create a new one if not specified - room_url = os.getenv("DAILY_SAMPLE_ROOM_URL", None) + # room_url = os.getenv("DAILY_SAMPLE_ROOM_URL", None) + room_url = None # Get the dial-in properties from the request try: data = await request.json()