Skip to content

Commit

Permalink
Style fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkbrnd committed Dec 20, 2024
1 parent 8ad8712 commit 37340f9
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 36 deletions.
2 changes: 1 addition & 1 deletion cookbook/agents/37_audio_input_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
audio={"data": encoded_string, "format": "wav"},
)

if agent.run_response.response_audio is not None and "data" in agent.run_response.response_audio:
if agent.run_response.response_audio is not None:
write_audio_to_file(audio=agent.run_response.response_audio.base64_audio, filename="tmp/dog.wav")
4 changes: 2 additions & 2 deletions cookbook/agents/38_audio_multi_turn.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
)

agent.run("Is a golden retriever a good family dog?")
if agent.run_response.response_audio is not None and "data" in agent.run_response.response_audio:
if agent.run_response.response_audio is not None:
write_audio_to_file(audio=agent.run_response.response_audio.base64_audio, filename="tmp/answer_1.wav")

agent.run("Why do you say they are loyal?")
if agent.run_response.response_audio is not None and "data" in agent.run_response.response_audio:
if agent.run_response.response_audio is not None:
write_audio_to_file(audio=agent.run_response.response_audio.base64_audio, filename="tmp/answer_2.wav")
2 changes: 1 addition & 1 deletion cookbook/agents/42_image_to_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
)

audio_story: RunResponse = audio_agent.run(f"Narrate the story with flair: {image_story.content}")
if audio_story.response_audio is not None and "data" in audio_story.response_audio:
if audio_story.response_audio is not None:
write_audio_to_file(audio=audio_story.response_audio.base64_audio, filename="tmp/multimodal-agents.wav")
4 changes: 3 additions & 1 deletion cookbook/playground/audio_conversation_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
audio_agent = Agent(
name="Audio Chat Agent",
model=OpenAIChat(
id="gpt-4o-audio-preview", modalities=["text", "audio"], audio={"voice": "alloy", "format": "pcm16"} # Wav not supported for streaming
id="gpt-4o-audio-preview",
modalities=["text", "audio"],
audio={"voice": "alloy", "format": "pcm16"}, # Wav not supported for streaming
),
debug_mode=True,
add_history_to_messages=True,
Expand Down
2 changes: 1 addition & 1 deletion cookbook/workflows/startup_idea_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def run(self, startup_idea: str) -> Iterator[RunResponse]:
table_name="validate_startup_ideas_workflow",
db_file="tmp/workflows.db",
),
debug_mode=True
debug_mode=True,
)

final_report: Iterator[RunResponse] = startup_idea_validator.run(startup_idea=idea)
Expand Down
18 changes: 9 additions & 9 deletions phi/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1856,9 +1856,9 @@ def _run(
self.run_response.content = model_response.content
if model_response.audio is not None:
self.run_response.response_audio = ModelResponseAudio(
base64_audio=model_response.audio.get("data"),
transcript=model_response.audio.get("transcript"),
)
base64_audio=model_response.audio.get("data"),
transcript=model_response.audio.get("transcript"),
)
self.run_response.messages = messages_for_model
self.run_response.created_at = model_response.created_at

Expand All @@ -1874,9 +1874,9 @@ def _run(
self.run_response.content = model_response.content
if model_response.audio is not None:
self.run_response.response_audio = ModelResponseAudio(
base64_audio=model_response.audio.get("data"),
transcript=model_response.audio.get("transcript"),
)
base64_audio=model_response.audio.get("data"),
transcript=model_response.audio.get("transcript"),
)

# 6. Update Memory
if self.stream_intermediate_steps:
Expand Down Expand Up @@ -2234,9 +2234,9 @@ async def _arun(
self.run_response.content = model_response.content
if model_response.audio is not None:
self.run_response.response_audio = ModelResponseAudio(
base64_audio=model_response.audio.get("data"),
transcript=model_response.audio.get("transcript"),
)
base64_audio=model_response.audio.get("data"),
transcript=model_response.audio.get("transcript"),
)

# 6. Update Memory
if self.stream_intermediate_steps:
Expand Down
8 changes: 7 additions & 1 deletion phi/playground/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,13 @@ async def chat_response_streamer(
) -> AsyncGenerator:
run_response = await agent.arun(message, images=images, stream=True, stream_intermediate_steps=True)
async for run_response_chunk in run_response:
print(run_response_chunk.event, "|", run_response_chunk.content, "|", run_response_chunk.response_audio.base64_audio[:10] if run_response_chunk.response_audio else "-")
print(
run_response_chunk.event,
"|",
run_response_chunk.content,
"|",
run_response_chunk.response_audio.base64_audio[:10] if run_response_chunk.response_audio else "-",
)
run_response_chunk = cast(RunResponse, run_response_chunk)
yield run_response_chunk.to_json()

Expand Down
39 changes: 19 additions & 20 deletions phi/tools/eleven_labs_tools.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from base64 import b64encode
from io import BytesIO
from pathlib import Path
Expand Down Expand Up @@ -63,14 +62,14 @@ def __init__(

def get_voices(self) -> str:
"""
<<<<<<< HEAD
Use this function to generate sound effect audio from a text prompt.
=======
Use this function to get all the voices available.
>>>>>>> 48addb496442892c21382ff27d03578b3f9d7ac6
Returns:
result (list): A list of voices that have an ID, name and description.
<<<<<<< HEAD
Use this function to generate sound effect audio from a text prompt.
=======
Use this function to get all the voices available.
>>>>>>> 48addb496442892c21382ff27d03578b3f9d7ac6
Returns:
result (list): A list of voices that have an ID, name and description.
"""
try:
voices = self.eleven_labs_client.voices.get_all()
Expand Down Expand Up @@ -157,17 +156,17 @@ def generate_sound_effect(self, agent: Agent, prompt: str, duration_seconds: Opt

def text_to_speech(self, agent: Agent, prompt: str, voice_id: Optional[str] = None) -> str:
"""
Use this function to convert text to speech audio.
Args:
prompt (str): Text to generate audio from.
<<<<<<< HEAD
voice_id (str): The ID of the voice to use for audio generation.
=======
voice_id (Optional[str]): The ID of the voice to use for audio generation. Uses default if none is specified.
>>>>>>> 48addb496442892c21382ff27d03578b3f9d7ac6
Returns:
str: Return the path to the generated audio file.
Use this function to convert text to speech audio.
Args:
prompt (str): Text to generate audio from.
<<<<<<< HEAD
voice_id (str): The ID of the voice to use for audio generation.
=======
voice_id (Optional[str]): The ID of the voice to use for audio generation. Uses default if none is specified.
>>>>>>> 48addb496442892c21382ff27d03578b3f9d7ac6
Returns:
str: Return the path to the generated audio file.
"""
try:
audio_generator = self.eleven_labs_client.text_to_speech.convert(
Expand Down

0 comments on commit 37340f9

Please sign in to comment.