openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.78.1

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

120lines · 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 include=["string"],
29 input_audio_format="pcm16",
30 input_audio_noise_reduction={"type": "near_field"},
31 input_audio_transcription={
32 "language": "language",
33 "model": "gpt-4o-transcribe",
34 "prompt": "prompt",
35 },
36 modalities=["text"],
37 turn_detection={
38 "create_response": True,
39 "eagerness": "low",
40 "interrupt_response": True,
41 "prefix_padding_ms": 0,
42 "silence_duration_ms": 0,
43 "threshold": 0,
44 "type": "server_vad",
45 },
46 )
47 assert_matches_type(TranscriptionSession, transcription_session, path=["response"])
48
49 @parametrize
50 def test_raw_response_create(self, client: OpenAI) -> None:
51 response = client.beta.realtime.transcription_sessions.with_raw_response.create()
52
53 assert response.is_closed is True
54 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
55 transcription_session = response.parse()
56 assert_matches_type(TranscriptionSession, transcription_session, path=["response"])
57
58 @parametrize
59 def test_streaming_response_create(self, client: OpenAI) -> None:
60 with client.beta.realtime.transcription_sessions.with_streaming_response.create() as response:
61 assert not response.is_closed
62 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
63
64 transcription_session = response.parse()
65 assert_matches_type(TranscriptionSession, transcription_session, path=["response"])
66
67 assert cast(Any, response.is_closed) is True
68
69
70class TestAsyncTranscriptionSessions:
71 parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
72
73 @parametrize
74 async def test_method_create(self, async_client: AsyncOpenAI) -> None:
75 transcription_session = await async_client.beta.realtime.transcription_sessions.create()
76 assert_matches_type(TranscriptionSession, transcription_session, path=["response"])
77
78 @parametrize
79 async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
80 transcription_session = await async_client.beta.realtime.transcription_sessions.create(
81 include=["string"],
82 input_audio_format="pcm16",
83 input_audio_noise_reduction={"type": "near_field"},
84 input_audio_transcription={
85 "language": "language",
86 "model": "gpt-4o-transcribe",
87 "prompt": "prompt",
88 },
89 modalities=["text"],
90 turn_detection={
91 "create_response": True,
92 "eagerness": "low",
93 "interrupt_response": True,
94 "prefix_padding_ms": 0,
95 "silence_duration_ms": 0,
96 "threshold": 0,
97 "type": "server_vad",
98 },
99 )
100 assert_matches_type(TranscriptionSession, transcription_session, path=["response"])
101
102 @parametrize
103 async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
104 response = await async_client.beta.realtime.transcription_sessions.with_raw_response.create()
105
106 assert response.is_closed is True
107 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
108 transcription_session = response.parse()
109 assert_matches_type(TranscriptionSession, transcription_session, path=["response"])
110
111 @parametrize
112 async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
113 async with async_client.beta.realtime.transcription_sessions.with_streaming_response.create() as response:
114 assert not response.is_closed
115 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
116
117 transcription_session = await response.parse()
118 assert_matches_type(TranscriptionSession, transcription_session, path=["response"])
119
120 assert cast(Any, response.is_closed) is True
121