openai/openai-python

Public

mirrored from https://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.86.0

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

132lines · 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("async_client", [False, True], indirect=True, ids=["loose", "strict"])
78
79 @parametrize
80 async def test_method_create(self, async_client: AsyncOpenAI) -> None:
81 transcription_session = await async_client.beta.realtime.transcription_sessions.create()
82 assert_matches_type(TranscriptionSession, transcription_session, path=["response"])
83
84 @parametrize
85 async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
86 transcription_session = await async_client.beta.realtime.transcription_sessions.create(
87 client_secret={
88 "expires_at": {
89 "anchor": "created_at",
90 "seconds": 0,
91 }
92 },
93 include=["string"],
94 input_audio_format="pcm16",
95 input_audio_noise_reduction={"type": "near_field"},
96 input_audio_transcription={
97 "language": "language",
98 "model": "gpt-4o-transcribe",
99 "prompt": "prompt",
100 },
101 modalities=["text"],
102 turn_detection={
103 "create_response": True,
104 "eagerness": "low",
105 "interrupt_response": True,
106 "prefix_padding_ms": 0,
107 "silence_duration_ms": 0,
108 "threshold": 0,
109 "type": "server_vad",
110 },
111 )
112 assert_matches_type(TranscriptionSession, transcription_session, path=["response"])
113
114 @parametrize
115 async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
116 response = await async_client.beta.realtime.transcription_sessions.with_raw_response.create()
117
118 assert response.is_closed is True
119 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
120 transcription_session = response.parse()
121 assert_matches_type(TranscriptionSession, transcription_session, path=["response"])
122
123 @parametrize
124 async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
125 async with async_client.beta.realtime.transcription_sessions.with_streaming_response.create() as response:
126 assert not response.is_closed
127 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
128
129 transcription_session = await response.parse()
130 assert_matches_type(TranscriptionSession, transcription_session, path=["response"])
131
132 assert cast(Any, response.is_closed) is True
133