Skip to content

Commit 3af879e

Browse files
authored
update tests (#266)
2 parents 6f13d50 + 1771c1e commit 3af879e

13 files changed

+57
-87
lines changed

examples/voice/static/main.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import asyncio
22
import random
33

4-
from agents import (
5-
Agent,
4+
from agents import Agent, function_tool
5+
from agents.extensions.handoff_prompt import prompt_with_handoff_instructions
6+
from agents.voice import (
67
AudioInput,
78
SingleAgentVoiceWorkflow,
89
SingleAgentWorkflowCallbacks,
910
VoicePipeline,
10-
function_tool,
1111
)
12-
from agents.extensions.handoff_prompt import prompt_with_handoff_instructions
1312

1413
from .util import AudioPlayer, record_audio
1514

examples/voice/streamed/agents.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@
22
from collections.abc import AsyncIterator
33
from typing import Callable
44

5-
from agents import (
6-
Agent,
7-
Runner,
8-
TResponseInputItem,
9-
VoiceWorkflowBase,
10-
VoiceWorkflowHelper,
11-
function_tool,
12-
)
5+
from agents import Agent, Runner, TResponseInputItem, function_tool
136
from agents.extensions.handoff_prompt import prompt_with_handoff_instructions
7+
from agents.voice import VoiceWorkflowBase, VoiceWorkflowHelper
148

159

1610
@function_tool

examples/voice/streamed/main.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
from textual.widgets import Button, RichLog, Static
1212
from typing_extensions import override
1313

14-
from agents import VoicePipeline
15-
from agents.voice.input import StreamedAudioInput
14+
from agents.voice import StreamedAudioInput, VoicePipeline
1615

1716
from .agents import MyWorkflow
1817

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ dev = [
5454
"sounddevice",
5555
"pynput",
5656
"textual",
57+
"websockets",
5758
]
5859
[tool.uv.workspace]
5960
members = ["agents"]

src/agents/__init__.py

-48
Original file line numberDiff line numberDiff line change
@@ -98,31 +98,6 @@
9898
transcription_span,
9999
)
100100
from .usage import Usage
101-
from .voice import (
102-
AudioInput,
103-
OpenAISTTModel,
104-
OpenAISTTTranscriptionSession,
105-
OpenAITTSModel,
106-
OpenAIVoiceModelProvider,
107-
SingleAgentVoiceWorkflow,
108-
SingleAgentWorkflowCallbacks,
109-
StreamedAudioInput,
110-
StreamedAudioResult,
111-
StreamedTranscriptionSession,
112-
STTModel,
113-
STTModelSettings,
114-
TTSModel,
115-
TTSModelSettings,
116-
VoiceModelProvider,
117-
VoicePipeline,
118-
VoicePipelineConfig,
119-
VoiceStreamEvent,
120-
VoiceStreamEventAudio,
121-
VoiceStreamEventLifecycle,
122-
VoiceWorkflowBase,
123-
VoiceWorkflowHelper,
124-
get_sentence_based_splitter,
125-
)
126101

127102

128103
def set_default_openai_key(key: str, use_for_tracing: bool = True) -> None:
@@ -268,27 +243,4 @@ def enable_verbose_stdout_logging():
268243
"gen_trace_id",
269244
"gen_span_id",
270245
"default_tool_error_function",
271-
"AudioInput",
272-
"StreamedAudioInput",
273-
"STTModel",
274-
"STTModelSettings",
275-
"TTSModel",
276-
"TTSModelSettings",
277-
"VoiceModelProvider",
278-
"StreamedAudioResult",
279-
"SingleAgentVoiceWorkflow",
280-
"OpenAIVoiceModelProvider",
281-
"OpenAISTTModel",
282-
"OpenAITTSModel",
283-
"VoiceStreamEventAudio",
284-
"VoiceStreamEventLifecycle",
285-
"VoiceStreamEvent",
286-
"VoicePipeline",
287-
"VoicePipelineConfig",
288-
"get_sentence_based_splitter",
289-
"VoiceWorkflowHelper",
290-
"VoiceWorkflowBase",
291-
"StreamedTranscriptionSession",
292-
"OpenAISTTTranscriptionSession",
293-
"SingleAgentWorkflowCallbacks",
294246
]

tests/voice/fake_models.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66
import numpy as np
77
import numpy.typing as npt
88

9-
from agents.voice import (
10-
AudioInput,
11-
StreamedAudioInput,
12-
StreamedTranscriptionSession,
13-
STTModel,
14-
STTModelSettings,
15-
TTSModel,
16-
TTSModelSettings,
17-
VoiceWorkflowBase,
18-
)
9+
try:
10+
from agents.voice import (
11+
AudioInput,
12+
StreamedAudioInput,
13+
StreamedTranscriptionSession,
14+
STTModel,
15+
STTModelSettings,
16+
TTSModel,
17+
TTSModelSettings,
18+
VoiceWorkflowBase,
19+
)
20+
except ImportError:
21+
pass
1922

2023

2124
class FakeTTS(TTSModel):

tests/voice/helpers.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
from agents.voice import StreamedAudioResult
1+
try:
2+
from agents.voice import StreamedAudioResult
3+
except ImportError:
4+
pass
25

36

47
async def extract_events(result: StreamedAudioResult) -> tuple[list[str], list[bytes]]:

tests/voice/test_input.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
import numpy as np
55
import pytest
66

7-
from agents import UserError
8-
from agents.voice import AudioInput, StreamedAudioInput
9-
from agents.voice.input import DEFAULT_SAMPLE_RATE, _buffer_to_audio_file
7+
try:
8+
from agents import UserError
9+
from agents.voice import AudioInput, StreamedAudioInput
10+
from agents.voice.input import DEFAULT_SAMPLE_RATE, _buffer_to_audio_file
11+
except ImportError:
12+
pass
1013

1114

1215
def test_buffer_to_audio_file_int16():

tests/voice/test_openai_stt.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
import numpy as np
99
import pytest
1010

11-
from agents.voice import OpenAISTTTranscriptionSession, StreamedAudioInput, STTModelSettings
12-
from agents.voice.exceptions import STTWebsocketConnectionError
13-
from agents.voice.models.openai_stt import EVENT_INACTIVITY_TIMEOUT
11+
try:
12+
from agents.voice import OpenAISTTTranscriptionSession, StreamedAudioInput, STTModelSettings
13+
from agents.voice.exceptions import STTWebsocketConnectionError
14+
from agents.voice.models.openai_stt import EVENT_INACTIVITY_TIMEOUT
15+
16+
from .fake_models import FakeStreamedAudioInput
17+
except ImportError:
18+
pass
1419

15-
from .fake_models import FakeStreamedAudioInput
1620

1721
# ===== Helpers =====
1822

tests/voice/test_openai_tts.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66
import pytest
77

8-
from agents.voice import OpenAITTSModel, TTSModelSettings
8+
try:
9+
from agents.voice import OpenAITTSModel, TTSModelSettings
10+
except ImportError:
11+
pass
912

1013

1114
class _FakeStreamResponse:

tests/voice/test_pipeline.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
import numpy.typing as npt
55
import pytest
66

7-
from agents.voice import AudioInput, TTSModelSettings, VoicePipeline, VoicePipelineConfig
7+
try:
8+
from agents.voice import AudioInput, TTSModelSettings, VoicePipeline, VoicePipelineConfig
89

9-
from .fake_models import FakeStreamedAudioInput, FakeSTT, FakeTTS, FakeWorkflow
10-
from .helpers import extract_events
10+
from .fake_models import FakeStreamedAudioInput, FakeSTT, FakeTTS, FakeWorkflow
11+
from .helpers import extract_events
12+
except ImportError:
13+
pass
1114

1215

1316
@pytest.mark.asyncio

tests/voice/test_workflow.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717
TResponseOutputItem,
1818
TResponseStreamEvent,
1919
)
20-
from agents.voice import SingleAgentVoiceWorkflow
2120

22-
from ..fake_model import get_response_obj
23-
from ..test_responses import get_function_tool, get_function_tool_call, get_text_message
21+
try:
22+
from agents.voice import SingleAgentVoiceWorkflow
23+
24+
from ..fake_model import get_response_obj
25+
from ..test_responses import get_function_tool, get_function_tool_call, get_text_message
26+
except ImportError:
27+
pass
2428

2529

2630
class FakeStreamingModel(Model):

uv.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)