openai/openai-python

Public

mirrored fromhttps://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.97.2

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tests/api_resources/beta/realtime/test_transcription_sessions.py

134lines · modecode

1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3from __future__ import annotations
4
5import os
6from typing import Any, cast
7
8import pytest
9
10from openai import OpenAI, AsyncOpenAI
11from tests.utils import assert_matches_type
12from openai.types.beta.realtime import TranscriptionSession
13
14base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
15
16
17class TestTranscriptionSessions:
18 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
19
20 @parametrize
21 def test_method_create(self, client: OpenAI) -> None:
22 transcription_session = client.beta.realtime.transcription_sessions.create()
23 assert_matches_type(TranscriptionSession, transcription_session, path=["response"])
24
25 @parametrize
26 def test_method_create_with_all_params(self, client: OpenAI) -> None:
27 transcription_session = client.beta.realtime.transcription_sessions.create(
28 client_secret={
29 "expires_at": {
30 "anchor": "created_at",
31 "seconds": 0,
32 }
33 },
34 include=["string"],
35 input_audio_format="pcm16",
36 input_audio_noise_reduction={"type": "near_field"},
37 input_audio_transcription={
38 "language": "language",
39 "model": "gpt-4o-transcribe",
40 "prompt": "prompt",
41 },
42 modalities=["text"],
43 turn_detection={
44 "create_response": True,
45 "eagerness": "low",
46 "interrupt_response": True,
47 "prefix_padding_ms": 0,
48 "silence_duration_ms": 0,
49 "threshold": 0,
50 "type": "server_vad",
51 },
52 )
53 assert_matches_type(TranscriptionSession, transcription_session, path=["response"])
54
55 @parametrize
56 def test_raw_response_create(self, client: OpenAI) -> None:
57 response = client.beta.realtime.transcription_sessions.with_raw_response.create()
58
59 assert response.is_closed is True
60 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
61 transcription_session = response.parse()
62 assert_matches_type(TranscriptionSession, transcription_session, path=["response"])
63
64 @parametrize
65 def test_streaming_response_create(self, client: OpenAI) -> None:
66 with client.beta.realtime.transcription_sessions.with_streaming_response.create() as response:
67 assert not response.is_closed
68 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
69
70 transcription_session = response.parse()
71 assert_matches_type(TranscriptionSession, transcription_session, path=["response"])
72
73 assert cast(Any, response.is_closed) is True
74
75
76class TestAsyncTranscriptionSessions:
77 parametrize = pytest.mark.parametrize(
78 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
79 )
80
81 @parametrize
82 async def test_method_create(self, async_client: AsyncOpenAI) -> None:
83 transcription_session = await async_client.beta.realtime.transcription_sessions.create()
84 assert_matches_type(TranscriptionSession, transcription_session, path=["response"])
85
86 @parametrize
87 async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
88 transcription_session = await async_client.beta.realtime.transcription_sessions.create(
89 client_secret={
90 "expires_at": {
91 "anchor": "created_at",
92 "seconds": 0,
93 }
94 },
95 include=["string"],
96 input_audio_format="pcm16",
97 input_audio_noise_reduction={"type": "near_field"},
98 input_audio_transcription={
99 "language": "language",
100 "model": "gpt-4o-transcribe",
101 "prompt": "prompt",
102 },
103 modalities=["text"],
104 turn_detection={
105 "create_response": True,
106 "eagerness": "low",
107 "interrupt_response": True,
108 "prefix_padding_ms": 0,
109 "silence_duration_ms": 0,
110 "threshold": 0,
111 "type": "server_vad",
112 },
113 )
114 assert_matches_type(TranscriptionSession, transcription_session, path=["response"])
115
116 @parametrize
117 async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
118 response = await async_client.beta.realtime.transcription_sessions.with_raw_response.create()
119
120 assert response.is_closed is True
121 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
122 transcription_session = response.parse()
123 assert_matches_type(TranscriptionSession, transcription_session, path=["response"])
124
125 @parametrize
126 async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
127 async with async_client.beta.realtime.transcription_sessions.with_streaming_response.create() as response:
128 assert not response.is_closed
129 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
130
131 transcription_session = await response.parse()
132 assert_matches_type(TranscriptionSession, transcription_session, path=["response"])
133
134 assert cast(Any, response.is_closed) is True
135