From 471311b18f26c7e459292fcc794abdbc230325b7 Mon Sep 17 00:00:00 2001 From: Mark Backman Date: Wed, 30 Jul 2025 19:50:47 -0400 Subject: [PATCH] Add is_local_development utility for a cleaner API to determine if running locally --- .../runner-examples/01-all-transport-bot.py | 16 +++++++++------- .../runner-examples/02-two-transport-bot.py | 17 +++++++++-------- src/pipecat/runner/run.py | 1 - src/pipecat/runner/utils.py | 11 +++++++++++ 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/examples/runner-examples/01-all-transport-bot.py b/examples/runner-examples/01-all-transport-bot.py index 6d884dc76..78557bffb 100644 --- a/examples/runner-examples/01-all-transport-bot.py +++ b/examples/runner-examples/01-all-transport-bot.py @@ -30,6 +30,7 @@ from pipecat.runner.types import ( DailyRunnerArguments, SmallWebRTCRunnerArguments, WebSocketRunnerArguments, + is_local_development, ) from pipecat.services.cartesia.tts import CartesiaTTSService from pipecat.services.deepgram.stt import DeepgramSTTService @@ -37,9 +38,6 @@ from pipecat.services.openai.llm import OpenAILLMService load_dotenv(override=True) -# Check if we're running locally -IS_LOCAL_RUN = os.environ.get("LOCAL_RUN", "0") == "1" - async def run_bot(transport): """Main bot logic that works with any transport.""" @@ -111,18 +109,22 @@ async def bot( if isinstance(session_args, DailyRunnerArguments): from pipecat.transports.services.daily import DailyParams, DailyTransport - if not IS_LOCAL_RUN: + is_local = is_local_development() + + if not is_local: from pipecat.audio.filters.krisp_filter import KrispFilter + krisp_filter = KrispFilter() + else: + krisp_filter = None + transport = DailyTransport( session_args.room_url, session_args.token, "Pipecat Bot", params=DailyParams( audio_in_enabled=True, - audio_in_filter=None - if IS_LOCAL_RUN - else KrispFilter(), # Only use Krisp in production + audio_in_filter=krisp_filter, audio_out_enabled=True, vad_analyzer=SileroVADAnalyzer(), ), diff --git a/examples/runner-examples/02-two-transport-bot.py b/examples/runner-examples/02-two-transport-bot.py index 7d3e4d4ef..a74a5e51d 100644 --- a/examples/runner-examples/02-two-transport-bot.py +++ b/examples/runner-examples/02-two-transport-bot.py @@ -23,6 +23,7 @@ from pipecat.runner.types import ( DailyRunnerArguments, SmallWebRTCRunnerArguments, ) +from pipecat.runner.utils import is_local_development from pipecat.services.cartesia.tts import CartesiaTTSService from pipecat.services.deepgram.stt import DeepgramSTTService from pipecat.services.openai.llm import OpenAILLMService @@ -30,10 +31,6 @@ from pipecat.services.openai.llm import OpenAILLMService load_dotenv(override=True) -# Check if we're running locally -IS_LOCAL_RUN = os.environ.get("LOCAL_RUN", "0") == "1" - - async def run_bot(transport): """Main bot logic that works with any transport.""" logger.info(f"Starting bot") @@ -102,18 +99,22 @@ async def bot(session_args: DailyRunnerArguments | SmallWebRTCRunnerArguments): if isinstance(session_args, DailyRunnerArguments): from pipecat.transports.services.daily import DailyParams, DailyTransport - if not IS_LOCAL_RUN: + is_local = is_local_development() + + if not is_local: from pipecat.audio.filters.krisp_filter import KrispFilter + krisp_filter = KrispFilter() + else: + krisp_filter = None + transport = DailyTransport( session_args.room_url, session_args.token, "Pipecat Bot", params=DailyParams( audio_in_enabled=True, - audio_in_filter=None - if IS_LOCAL_RUN - else KrispFilter(), # Only use Krisp in production + audio_in_filter=krisp_filter, audio_out_enabled=True, vad_analyzer=SileroVADAnalyzer(), ), diff --git a/src/pipecat/runner/run.py b/src/pipecat/runner/run.py index 64e7808bc..8c137eecf 100644 --- a/src/pipecat/runner/run.py +++ b/src/pipecat/runner/run.py @@ -94,7 +94,6 @@ except ImportError as e: load_dotenv(override=True) -os.environ["LOCAL_RUN"] = "1" def _get_bot_module(): diff --git a/src/pipecat/runner/utils.py b/src/pipecat/runner/utils.py index cd0781f78..b2f5267d9 100644 --- a/src/pipecat/runner/utils.py +++ b/src/pipecat/runner/utils.py @@ -32,6 +32,7 @@ Example:: import json import os import re +import sys from typing import Any, Callable, Dict, Optional from fastapi import WebSocket @@ -479,3 +480,13 @@ async def create_transport( else: raise ValueError(f"Unsupported session arguments type: {type(session_args)}") + + +def is_local_development() -> bool: + """Detect if running in local development environment. + + Returns True if the pipecat development runner is being used. + This works by detecting if pipecat.runner.run has been imported, + which only happens when running locally via the development runner. + """ + return "pipecat.runner.run" in sys.modules