update tests (#266)
This commit is contained in:
commit
3af879ec3f
13 changed files with 57 additions and 87 deletions
|
|
@ -1,15 +1,14 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from agents import (
|
from agents import Agent, function_tool
|
||||||
Agent,
|
from agents.extensions.handoff_prompt import prompt_with_handoff_instructions
|
||||||
|
from agents.voice import (
|
||||||
AudioInput,
|
AudioInput,
|
||||||
SingleAgentVoiceWorkflow,
|
SingleAgentVoiceWorkflow,
|
||||||
SingleAgentWorkflowCallbacks,
|
SingleAgentWorkflowCallbacks,
|
||||||
VoicePipeline,
|
VoicePipeline,
|
||||||
function_tool,
|
|
||||||
)
|
)
|
||||||
from agents.extensions.handoff_prompt import prompt_with_handoff_instructions
|
|
||||||
|
|
||||||
from .util import AudioPlayer, record_audio
|
from .util import AudioPlayer, record_audio
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,9 @@ import random
|
||||||
from collections.abc import AsyncIterator
|
from collections.abc import AsyncIterator
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
from agents import (
|
from agents import Agent, Runner, TResponseInputItem, function_tool
|
||||||
Agent,
|
|
||||||
Runner,
|
|
||||||
TResponseInputItem,
|
|
||||||
VoiceWorkflowBase,
|
|
||||||
VoiceWorkflowHelper,
|
|
||||||
function_tool,
|
|
||||||
)
|
|
||||||
from agents.extensions.handoff_prompt import prompt_with_handoff_instructions
|
from agents.extensions.handoff_prompt import prompt_with_handoff_instructions
|
||||||
|
from agents.voice import VoiceWorkflowBase, VoiceWorkflowHelper
|
||||||
|
|
||||||
|
|
||||||
@function_tool
|
@function_tool
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,7 @@ from textual.reactive import reactive
|
||||||
from textual.widgets import Button, RichLog, Static
|
from textual.widgets import Button, RichLog, Static
|
||||||
from typing_extensions import override
|
from typing_extensions import override
|
||||||
|
|
||||||
from agents import VoicePipeline
|
from agents.voice import StreamedAudioInput, VoicePipeline
|
||||||
from agents.voice.input import StreamedAudioInput
|
|
||||||
|
|
||||||
from .agents import MyWorkflow
|
from .agents import MyWorkflow
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ dev = [
|
||||||
"sounddevice",
|
"sounddevice",
|
||||||
"pynput",
|
"pynput",
|
||||||
"textual",
|
"textual",
|
||||||
|
"websockets",
|
||||||
]
|
]
|
||||||
[tool.uv.workspace]
|
[tool.uv.workspace]
|
||||||
members = ["agents"]
|
members = ["agents"]
|
||||||
|
|
|
||||||
|
|
@ -98,31 +98,6 @@ from .tracing import (
|
||||||
transcription_span,
|
transcription_span,
|
||||||
)
|
)
|
||||||
from .usage import Usage
|
from .usage import Usage
|
||||||
from .voice import (
|
|
||||||
AudioInput,
|
|
||||||
OpenAISTTModel,
|
|
||||||
OpenAISTTTranscriptionSession,
|
|
||||||
OpenAITTSModel,
|
|
||||||
OpenAIVoiceModelProvider,
|
|
||||||
SingleAgentVoiceWorkflow,
|
|
||||||
SingleAgentWorkflowCallbacks,
|
|
||||||
StreamedAudioInput,
|
|
||||||
StreamedAudioResult,
|
|
||||||
StreamedTranscriptionSession,
|
|
||||||
STTModel,
|
|
||||||
STTModelSettings,
|
|
||||||
TTSModel,
|
|
||||||
TTSModelSettings,
|
|
||||||
VoiceModelProvider,
|
|
||||||
VoicePipeline,
|
|
||||||
VoicePipelineConfig,
|
|
||||||
VoiceStreamEvent,
|
|
||||||
VoiceStreamEventAudio,
|
|
||||||
VoiceStreamEventLifecycle,
|
|
||||||
VoiceWorkflowBase,
|
|
||||||
VoiceWorkflowHelper,
|
|
||||||
get_sentence_based_splitter,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def set_default_openai_key(key: str, use_for_tracing: bool = True) -> None:
|
def set_default_openai_key(key: str, use_for_tracing: bool = True) -> None:
|
||||||
|
|
@ -268,27 +243,4 @@ __all__ = [
|
||||||
"gen_trace_id",
|
"gen_trace_id",
|
||||||
"gen_span_id",
|
"gen_span_id",
|
||||||
"default_tool_error_function",
|
"default_tool_error_function",
|
||||||
"AudioInput",
|
|
||||||
"StreamedAudioInput",
|
|
||||||
"STTModel",
|
|
||||||
"STTModelSettings",
|
|
||||||
"TTSModel",
|
|
||||||
"TTSModelSettings",
|
|
||||||
"VoiceModelProvider",
|
|
||||||
"StreamedAudioResult",
|
|
||||||
"SingleAgentVoiceWorkflow",
|
|
||||||
"OpenAIVoiceModelProvider",
|
|
||||||
"OpenAISTTModel",
|
|
||||||
"OpenAITTSModel",
|
|
||||||
"VoiceStreamEventAudio",
|
|
||||||
"VoiceStreamEventLifecycle",
|
|
||||||
"VoiceStreamEvent",
|
|
||||||
"VoicePipeline",
|
|
||||||
"VoicePipelineConfig",
|
|
||||||
"get_sentence_based_splitter",
|
|
||||||
"VoiceWorkflowHelper",
|
|
||||||
"VoiceWorkflowBase",
|
|
||||||
"StreamedTranscriptionSession",
|
|
||||||
"OpenAISTTTranscriptionSession",
|
|
||||||
"SingleAgentWorkflowCallbacks",
|
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,19 @@ from typing import Literal
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import numpy.typing as npt
|
import numpy.typing as npt
|
||||||
|
|
||||||
from agents.voice import (
|
try:
|
||||||
AudioInput,
|
from agents.voice import (
|
||||||
StreamedAudioInput,
|
AudioInput,
|
||||||
StreamedTranscriptionSession,
|
StreamedAudioInput,
|
||||||
STTModel,
|
StreamedTranscriptionSession,
|
||||||
STTModelSettings,
|
STTModel,
|
||||||
TTSModel,
|
STTModelSettings,
|
||||||
TTSModelSettings,
|
TTSModel,
|
||||||
VoiceWorkflowBase,
|
TTSModelSettings,
|
||||||
)
|
VoiceWorkflowBase,
|
||||||
|
)
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class FakeTTS(TTSModel):
|
class FakeTTS(TTSModel):
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
from agents.voice import StreamedAudioResult
|
try:
|
||||||
|
from agents.voice import StreamedAudioResult
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
async def extract_events(result: StreamedAudioResult) -> tuple[list[str], list[bytes]]:
|
async def extract_events(result: StreamedAudioResult) -> tuple[list[str], list[bytes]]:
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,12 @@ import wave
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from agents import UserError
|
try:
|
||||||
from agents.voice import AudioInput, StreamedAudioInput
|
from agents import UserError
|
||||||
from agents.voice.input import DEFAULT_SAMPLE_RATE, _buffer_to_audio_file
|
from agents.voice import AudioInput, StreamedAudioInput
|
||||||
|
from agents.voice.input import DEFAULT_SAMPLE_RATE, _buffer_to_audio_file
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def test_buffer_to_audio_file_int16():
|
def test_buffer_to_audio_file_int16():
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,15 @@ from unittest.mock import AsyncMock, patch
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from agents.voice import OpenAISTTTranscriptionSession, StreamedAudioInput, STTModelSettings
|
try:
|
||||||
from agents.voice.exceptions import STTWebsocketConnectionError
|
from agents.voice import OpenAISTTTranscriptionSession, StreamedAudioInput, STTModelSettings
|
||||||
from agents.voice.models.openai_stt import EVENT_INACTIVITY_TIMEOUT
|
from agents.voice.exceptions import STTWebsocketConnectionError
|
||||||
|
from agents.voice.models.openai_stt import EVENT_INACTIVITY_TIMEOUT
|
||||||
|
|
||||||
|
from .fake_models import FakeStreamedAudioInput
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
from .fake_models import FakeStreamedAudioInput
|
|
||||||
|
|
||||||
# ===== Helpers =====
|
# ===== Helpers =====
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,10 @@ from typing import Any
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from agents.voice import OpenAITTSModel, TTSModelSettings
|
try:
|
||||||
|
from agents.voice import OpenAITTSModel, TTSModelSettings
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class _FakeStreamResponse:
|
class _FakeStreamResponse:
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,13 @@ import numpy as np
|
||||||
import numpy.typing as npt
|
import numpy.typing as npt
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from agents.voice import AudioInput, TTSModelSettings, VoicePipeline, VoicePipelineConfig
|
try:
|
||||||
|
from agents.voice import AudioInput, TTSModelSettings, VoicePipeline, VoicePipelineConfig
|
||||||
|
|
||||||
from .fake_models import FakeStreamedAudioInput, FakeSTT, FakeTTS, FakeWorkflow
|
from .fake_models import FakeStreamedAudioInput, FakeSTT, FakeTTS, FakeWorkflow
|
||||||
from .helpers import extract_events
|
from .helpers import extract_events
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,14 @@ from agents.items import (
|
||||||
TResponseOutputItem,
|
TResponseOutputItem,
|
||||||
TResponseStreamEvent,
|
TResponseStreamEvent,
|
||||||
)
|
)
|
||||||
from agents.voice import SingleAgentVoiceWorkflow
|
|
||||||
|
|
||||||
from ..fake_model import get_response_obj
|
try:
|
||||||
from ..test_responses import get_function_tool, get_function_tool_call, get_text_message
|
from agents.voice import SingleAgentVoiceWorkflow
|
||||||
|
|
||||||
|
from ..fake_model import get_response_obj
|
||||||
|
from ..test_responses import get_function_tool, get_function_tool_call, get_text_message
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class FakeStreamingModel(Model):
|
class FakeStreamingModel(Model):
|
||||||
|
|
|
||||||
2
uv.lock
2
uv.lock
|
|
@ -1085,6 +1085,7 @@ dev = [
|
||||||
{ name = "sounddevice" },
|
{ name = "sounddevice" },
|
||||||
{ name = "textual" },
|
{ name = "textual" },
|
||||||
{ name = "types-pynput" },
|
{ name = "types-pynput" },
|
||||||
|
{ name = "websockets" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.metadata]
|
[package.metadata]
|
||||||
|
|
@ -1118,6 +1119,7 @@ dev = [
|
||||||
{ name = "sounddevice" },
|
{ name = "sounddevice" },
|
||||||
{ name = "textual" },
|
{ name = "textual" },
|
||||||
{ name = "types-pynput" },
|
{ name = "types-pynput" },
|
||||||
|
{ name = "websockets" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue