Skip to content

Commit

Permalink
fix: added tests for new audio files
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanleomk committed Oct 20, 2024
1 parent 930b34b commit 2e299b4
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/llm/test_openai/test_multimodal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,48 @@
from pydantic import Field, BaseModel
from itertools import product
from .util import models, modes
import requests
from pathlib import Path


audio_url = "https://www2.cs.uic.edu/~i101/SoundFiles/gettysburg.wav"


def gettysburg_audio():
audio_file = Path("gettysburg.wav")
if not audio_file.exists():
response = requests.get(audio_url)
response.raise_for_status()
with open(audio_file, "wb") as f:
f.write(response.content)
return audio_file


@pytest.mark.parametrize(
"audio_file",
[Audio.from_url(audio_url), Audio.from_path(gettysburg_audio())],
)
def test_multimodal_audio_description(audio_file, client):
client = instructor.from_openai(client)

class AudioDescription(BaseModel):
source: str

response = client.chat.completions.create(
model="gpt-4o-audio-preview",
response_model=AudioDescription,
modalities=["text"],
messages=[
{
"role": "user",
"content": [
"Where's this excerpt from?",
audio_file,
],
},
],
audio={"voice": "alloy", "format": "wav"},
)


@pytest.mark.parametrize("model, mode", product(models, modes))
Expand Down

0 comments on commit 2e299b4

Please sign in to comment.