Skip to content

Commit bbb8b53

Browse files
committed
runner: allow custom CLI arguments
1 parent f3b72e9 commit bbb8b53

4 files changed

Lines changed: 94 additions & 89 deletions

File tree

changelog/3590.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- `main()` in `pipecat.runner.run` now accepts an optional `argparse.ArgumentParser`, allowing bots to define custom CLI arguments accessible via `runner_args.cli_args`.

examples/foundational/18-gstreamer-filesrc.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020

2121
load_dotenv(override=True)
2222

23-
parser = argparse.ArgumentParser(description="Pipecat Video Streaming Bot")
24-
parser.add_argument("-i", "--input", type=str, required=True, help="Input video file")
25-
args = parser.parse_args()
26-
2723
# We store functions so objects (e.g. SileroVADAnalyzer) don't get
2824
# instantiated. The function will be called when the desired transport gets
2925
# selected.
@@ -46,10 +42,10 @@
4642

4743

4844
async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
49-
logger.info(f"Starting bot with video input: {args.input}")
45+
logger.info(f"Starting bot with video input: {runner_args.cli_args.input}")
5046

5147
gst = GStreamerPipelineSource(
52-
pipeline=f"filesrc location={args.input}",
48+
pipeline=f"filesrc location={runner_args.cli_args.input}",
5349
out_params=GStreamerPipelineSource.OutputParams(
5450
video_width=1280,
5551
video_height=720,
@@ -68,6 +64,15 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
6864
idle_timeout_secs=runner_args.pipeline_idle_timeout_secs,
6965
)
7066

67+
@transport.event_handler("on_client_connected")
68+
async def on_client_connected(transport, client):
69+
logger.info(f"Client connected")
70+
71+
@transport.event_handler("on_client_disconnected")
72+
async def on_client_disconnected(transport, client):
73+
logger.info(f"Client disconnected")
74+
await task.cancel()
75+
7176
runner = PipelineRunner(handle_sigint=runner_args.handle_sigint)
7277

7378
await runner.run(task)
@@ -82,4 +87,7 @@ async def bot(runner_args: RunnerArguments):
8287
if __name__ == "__main__":
8388
from pipecat.runner.run import main
8489

85-
main()
90+
parser = argparse.ArgumentParser(description="Pipecat Video Streaming Bot")
91+
parser.add_argument("-i", "--input", type=str, required=True, help="Input video file")
92+
93+
main(parser)

0 commit comments

Comments
 (0)