-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into better-error-handling-when-a-model-doesnt-su…
…pport-async-for-phi-2162
- Loading branch information
Showing
7 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*.jpg | ||
*.png | ||
*.mp3 | ||
*.wav | ||
*.mp4 | ||
*.mp3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import base64 | ||
import requests | ||
from phi.agent import Agent, RunResponse # noqa | ||
from phi.model.openai import OpenAIChat | ||
|
||
# Fetch the audio file and convert it to a base64 encoded string | ||
url = "https://openaiassets.blob.core.windows.net/$web/API/docs/audio/alloy.wav" | ||
response = requests.get(url) | ||
response.raise_for_status() | ||
wav_data = response.content | ||
encoded_string = base64.b64encode(wav_data).decode("utf-8") | ||
|
||
# Provide the agent with the audio file and get result as text | ||
agent = Agent( | ||
model=OpenAIChat(id="gpt-4o-audio-preview", modalities=["text"]), | ||
markdown=True, | ||
) | ||
agent.print_response("What is in this audio?", audio={"data": encoded_string, "format": "wav"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import base64 | ||
import requests | ||
from phi.agent import Agent, RunResponse # noqa | ||
from phi.model.openai import OpenAIChat | ||
from phi.utils.audio import write_audio_to_file | ||
|
||
# Fetch the audio file and convert it to a base64 encoded string | ||
url = "https://openaiassets.blob.core.windows.net/$web/API/docs/audio/alloy.wav" | ||
response = requests.get(url) | ||
response.raise_for_status() | ||
wav_data = response.content | ||
encoded_string = base64.b64encode(wav_data).decode("utf-8") | ||
|
||
# Provide the agent with the audio file and audio configuration and get result as text + audio | ||
agent = Agent( | ||
model=OpenAIChat( | ||
id="gpt-4o-audio-preview", modalities=["text", "audio"], audio={"voice": "alloy", "format": "wav"} | ||
), | ||
markdown=True, | ||
) | ||
agent.print_response("What is in this audio?", audio={"data": encoded_string, "format": "wav"}) | ||
|
||
# Save the response audio to a file | ||
if agent.run_response.response_audio is not None and "data" in agent.run_response.response_audio: | ||
write_audio_to_file(audio=agent.run_response.response_audio["data"], filename="tmp/dog.wav") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters