Skip to content

Commit fb0ba9f

Browse files
committed
test: scaffold audio testing
Wav file is CC0 public domain, per source: https://upload.wikimedia.org/wikipedia/commons/9/9d/French_Hello%2C_how_are_you.wav
1 parent d622c51 commit fb0ba9f

File tree

8 files changed

+80
-4
lines changed

8 files changed

+80
-4
lines changed

python/mirascope/llm/clients/anthropic/_utils/encode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def _encode_content(
108108
)
109109
)
110110
else:
111-
raise NotImplementedError(f"Content type {part.type} not supported")
111+
raise NotImplementedError(f"Unsupported content type: {part.type}")
112112

113113
return blocks
114114

python/mirascope/llm/clients/google/_utils/encode.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ def _encode_content(
9999
genai_types.PartDict(text="**Thinking:** " + part.thought)
100100
)
101101
else:
102-
raise NotImplementedError(
103-
f"Have not implemented conversion for {part.type}"
104-
)
102+
raise NotImplementedError(f"Unsupported content type: {part.type}")
105103
return result
106104

107105

41.4 KB
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from inline_snapshot import snapshot
2+
3+
test_snapshot = snapshot(
4+
{
5+
"exception": {
6+
"type": "NotImplementedError",
7+
"args": "('Unsupported content type: audio',)",
8+
}
9+
}
10+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from inline_snapshot import snapshot
2+
3+
test_snapshot = snapshot(
4+
{
5+
"exception": {
6+
"type": "NotImplementedError",
7+
"args": "('Unsupported content type: audio',)",
8+
}
9+
}
10+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from inline_snapshot import snapshot
2+
3+
test_snapshot = snapshot(
4+
{
5+
"exception": {
6+
"type": "NotImplementedError",
7+
"args": "('Unsupported user content part type: audio',)",
8+
}
9+
}
10+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from inline_snapshot import snapshot
2+
3+
test_snapshot = snapshot(
4+
{
5+
"exception": {
6+
"type": "NotImplementedError",
7+
"args": "('Unsupported user content part type: audio',)",
8+
}
9+
}
10+
)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""End-to-end tests for a LLM call with audio input."""
2+
3+
from pathlib import Path
4+
5+
import pytest
6+
7+
from mirascope import llm
8+
from tests.e2e.conftest import PROVIDER_MODEL_ID_PAIRS
9+
from tests.utils import (
10+
Snapshot,
11+
snapshot_test,
12+
)
13+
14+
HELLO_AUDIO_PATH = str(
15+
Path(__file__).parent.parent / "assets" / "audio" / "tagline.mp3"
16+
)
17+
18+
19+
@pytest.mark.parametrize("provider,model_id", PROVIDER_MODEL_ID_PAIRS)
20+
@pytest.mark.vcr
21+
def test_call_with_audio(
22+
provider: llm.Provider,
23+
model_id: llm.ModelId,
24+
snapshot: Snapshot,
25+
caplog: pytest.LogCaptureFixture,
26+
) -> None:
27+
"""Test a call using an audio file loaded from disk."""
28+
29+
@llm.call(provider=provider, model_id=model_id)
30+
def transcribe_audio(audio_path: str) -> llm.UserContent:
31+
return [
32+
"Repeat exactly what you hear:",
33+
llm.Audio.from_file(audio_path),
34+
]
35+
36+
with snapshot_test(snapshot, caplog) as snap:
37+
response = transcribe_audio(HELLO_AUDIO_PATH)
38+
snap.set_response(response)

0 commit comments

Comments
 (0)