Skip to content

Commit

Permalink
ruff formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimchauvet committed Oct 15, 2024
1 parent 5f2cc93 commit 474f06e
Show file tree
Hide file tree
Showing 20 changed files with 31 additions and 29 deletions.
2 changes: 1 addition & 1 deletion examples/canonical-metrics/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async def lifespan(app: FastAPI):

@app.get("/start")
async def start_agent(request: Request):
print(f"!!! Creating room")
print("!!! Creating room")
room = await daily_helpers["rest"].create_room(DailyRoomParams())
print(f"!!! Room URL: {room.url}")
# Ensure the room property is present
Expand Down
2 changes: 1 addition & 1 deletion examples/chatbot-audio-recording/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async def lifespan(app: FastAPI):

@app.get("/start")
async def start_agent(request: Request):
print(f"!!! Creating room")
print("!!! Creating room")
room = await daily_helpers["rest"].create_room(DailyRoomParams())
print(f"!!! Room URL: {room.url}")
# Ensure the room property is present
Expand Down
2 changes: 1 addition & 1 deletion examples/deployment/flyio-example/bot_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async def start_bot(request: Request) -> JSONResponse:
# Is this a webhook creation request?
if "test" in data:
return JSONResponse({"test": True})
except Exception as e:
except Exception:
pass

# Use specified room URL, or create a new one if not specified
Expand Down
8 changes: 4 additions & 4 deletions examples/dialin-chatbot/bot_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async def _create_daily_room(room_url, callId, callDomain=None, vendor="daily"):
)
)

print(f"Creating new room...")
print("Creating new room...")
room: DailyRoomObject = await daily_helpers["rest"].create_room(params=params)

else:
Expand All @@ -103,7 +103,7 @@ async def _create_daily_room(room_url, callId, callDomain=None, vendor="daily"):
token = await daily_helpers["rest"].get_token(room.url, MAX_SESSION_TIME)

if not room or not token:
raise HTTPException(status_code=500, detail=f"Failed to get room or token token")
raise HTTPException(status_code=500, detail="Failed to get room or token token")

# Spawn a new agent, and join the user session
# Note: this is mostly for demonstration purposes (refer to 'deployment' in docs)
Expand All @@ -126,7 +126,7 @@ async def _create_daily_room(room_url, callId, callDomain=None, vendor="daily"):

@app.post("/twilio_start_bot", response_class=PlainTextResponse)
async def twilio_start_bot(request: Request):
print(f"POST /twilio_voice_bot")
print("POST /twilio_voice_bot")

# twilio_start_bot is invoked directly by Twilio (as a web hook).
# On Twilio, under Active Numbers, pick the phone number
Expand All @@ -153,7 +153,7 @@ async def twilio_start_bot(request: Request):
# note: Twilio does not require a callDomain
room: DailyRoomObject = await _create_daily_room(room_url, callId, None, "twilio")

print(f"Put Twilio on hold...")
print("Put Twilio on hold...")
# We have the room and the SIP URI,
# but we do not know if the Daily SIP Worker and the Bot have joined the call
# put the call on hold until the 'on_dialin_ready' fires.
Expand Down
2 changes: 1 addition & 1 deletion examples/foundational/05a-local-sync-speech-and-image.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from pipecat.services.openai import OpenAILLMService
from pipecat.services.fal import FalImageGenService
from pipecat.transports.base_transport import TransportParams
from pipecat.transports.local.tk import TkLocalTransport, TkOutputTransport
from pipecat.transports.local.tk import TkLocalTransport

from loguru import logger

Expand Down
2 changes: 1 addition & 1 deletion examples/foundational/06-listen-and-respond.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)
from pipecat.pipeline.pipeline import Pipeline
from pipecat.pipeline.runner import PipelineRunner
from pipecat.pipeline.task import PipelineParams, PipelineTask
from pipecat.pipeline.task import PipelineTask
from pipecat.processors.aggregators.llm_response import (
LLMAssistantResponseAggregator,
LLMUserResponseAggregator,
Expand Down
8 changes: 6 additions & 2 deletions examples/foundational/07g-interruptible-openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
LLMAssistantResponseAggregator,
LLMUserResponseAggregator,
)
from pipecat.services.openai import OpenAILLMService, OpenAITTSService
from pipecat.services.openai import OpenAILLMService, OpenAISTTService, OpenAITTSService
from pipecat.transports.services.daily import DailyParams, DailyTransport
from pipecat.vad.silero import SileroVADAnalyzer

Expand All @@ -42,12 +42,15 @@ async def main():
DailyParams(
audio_out_enabled=True,
audio_out_sample_rate=24000,
transcription_enabled=True,
transcription_enabled=False,
vad_enabled=True,
vad_analyzer=SileroVADAnalyzer(),
vad_audio_passthrough=True,
),
)

stt = OpenAISTTService(api_key=os.getenv("OPENAI_API_KEY"), model="whisper-1")

tts = OpenAITTSService(api_key=os.getenv("OPENAI_API_KEY"), voice="alloy")

llm = OpenAILLMService(api_key=os.getenv("OPENAI_API_KEY"), model="gpt-4o")
Expand All @@ -66,6 +69,7 @@ async def main():
[
transport.input(), # Transport user input
tma_in, # User responses
stt, # STT
llm, # LLM
tts, # TTS
transport.output(), # Transport bot output
Expand Down
1 change: 0 additions & 1 deletion examples/foundational/07i-interruptible-xtts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
LLMAssistantResponseAggregator,
LLMUserResponseAggregator,
)
from pipecat.services.deepgram import DeepgramSTTService, DeepgramTTSService
from pipecat.services.openai import OpenAILLMService
from pipecat.services.xtts import XTTSService
from pipecat.transports.services.daily import DailyParams, DailyTransport
Expand Down
2 changes: 1 addition & 1 deletion examples/foundational/08-bots-arguing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

load_dotenv(override=True)

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logging.basicConfig(format="%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("pipecat")
logger.setLevel(logging.DEBUG)

Expand Down
2 changes: 1 addition & 1 deletion examples/foundational/13b-deepgram-transcription.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pipecat.pipeline.runner import PipelineRunner
from pipecat.pipeline.task import PipelineTask
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
from pipecat.services.deepgram import DeepgramSTTService, LiveOptions, Language
from pipecat.services.deepgram import DeepgramSTTService
from pipecat.transports.services.daily import DailyParams, DailyTransport

from runner import configure
Expand Down
2 changes: 1 addition & 1 deletion examples/moondream-chatbot/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def lifespan(app: FastAPI):

@app.get("/start")
async def start_agent(request: Request):
print(f"!!! Creating room")
print("!!! Creating room")
room = await daily_helpers["rest"].create_room(DailyRoomParams())
print(f"!!! Room URL: {room.url}")
# Ensure the room property is present
Expand Down
8 changes: 4 additions & 4 deletions examples/patient-intake/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

class IntakeProcessor:
def __init__(self, context: OpenAILLMContext):
print(f"Initializing context from IntakeProcessor")
print("Initializing context from IntakeProcessor")
context.add_message(
{
"role": "system",
Expand Down Expand Up @@ -145,7 +145,7 @@ async def verify_birthday(
)

async def start_prescriptions(self, function_name, llm, context):
print(f"!!! doing start prescriptions")
print("!!! doing start prescriptions")
# Move on to allergies
context.set_tools(
[
Expand Down Expand Up @@ -181,9 +181,9 @@ async def start_prescriptions(self, function_name, llm, context):
"content": "Next, ask the user if they have any allergies. Once they have listed their allergies or confirmed they don't have any, call the list_allergies function.",
}
)
print(f"!!! about to await llm process frame in start prescrpitions")
print("!!! about to await llm process frame in start prescrpitions")
await llm.process_frame(OpenAILLMContextFrame(context), FrameDirection.DOWNSTREAM)
print(f"!!! past await process frame in start prescriptions")
print("!!! past await process frame in start prescriptions")

async def start_allergies(self, function_name, llm, context):
print("!!! doing start allergies")
Expand Down
2 changes: 1 addition & 1 deletion examples/patient-intake/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def lifespan(app: FastAPI):

@app.get("/start")
async def start_agent(request: Request):
print(f"!!! Creating room")
print("!!! Creating room")
room = await daily_helpers["rest"].create_room(DailyRoomParams())
print(f"!!! Room URL: {room.url}")
# Ensure the room property is present
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-chatbot/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def lifespan(app: FastAPI):

@app.get("/start")
async def start_agent(request: Request):
print(f"!!! Creating room")
print("!!! Creating room")
room = await daily_helpers["rest"].create_room(DailyRoomParams())
print(f"!!! Room URL: {room.url}")
# Ensure the room property is present
Expand Down
2 changes: 1 addition & 1 deletion examples/storytelling-chatbot/src/bot_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def start_bot(request: Request) -> JSONResponse:
# Is this a webhook creation request?
if "test" in data:
return JSONResponse({"test": True})
except Exception as e:
except Exception:
pass

# Use specified room URL, or create a new one if not specified
Expand Down
2 changes: 1 addition & 1 deletion examples/translation-chatbot/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def lifespan(app: FastAPI):

@app.get("/start")
async def start_agent(request: Request):
print(f"!!! Creating room")
print("!!! Creating room")
room = await daily_helpers["rest"].create_room(DailyRoomParams())
print(f"!!! Room URL: {room.url}")
# Ensure the room property is present
Expand Down
2 changes: 1 addition & 1 deletion src/pipecat/pipeline/parallel_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, *args):
super().__init__()

if len(args) == 0:
raise Exception(f"ParallelPipeline needs at least one argument")
raise Exception("ParallelPipeline needs at least one argument")

self._sources = []
self._sinks = []
Expand Down
2 changes: 1 addition & 1 deletion src/pipecat/pipeline/sync_parallel_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self, *args):
super().__init__()

if len(args) == 0:
raise Exception(f"SyncParallelPipeline needs at least one argument")
raise Exception("SyncParallelPipeline needs at least one argument")

self._sinks = []
self._sources = []
Expand Down
5 changes: 2 additions & 3 deletions src/pipecat/services/openai_realtime_beta/llm_and_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ async def _truncate_current_audio_response(self):
)
)


#
# frame processing
#
Expand Down Expand Up @@ -643,8 +642,8 @@ async def _handle_evt_speech_started(self, evt):
await self._truncate_current_audio_response()
# todo: might need to guard sending these when we fully support using either openai
# turn detection of Pipecat turn detection
await self._start_interruption() # cancels this processor task
await self.push_frame(StartInterruptionFrame()) # cancels downstream tasks
await self._start_interruption() # cancels this processor task
await self.push_frame(StartInterruptionFrame()) # cancels downstream tasks
await self.push_frame(UserStartedSpeakingFrame())

async def _handle_evt_speech_stopped(self, evt):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def run_text_sentiment(self, sentence):
# models use 2-character language codes**)
def run_text_translation(self, sentence, source_language, target_language):
translator = pipeline(
f"translation", model=f"Helsinki-NLP/opus-mt-{source_language}-{target_language}"
"translation", model=f"Helsinki-NLP/opus-mt-{source_language}-{target_language}"
)

return translator(sentence)[0]["translation_text"]
Expand Down

0 comments on commit 474f06e

Please sign in to comment.