openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
tests/api_resources/audio/test_transcriptions.py
236lines · modeblame
5cfb125aStainless Bot2 years ago | 1 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
08b8179aDavid Schnurr2 years ago | 2 | |
| 3 | from __future__ import annotations | |
| 4 | | |
| 5 | import os | |
86379b44Stainless Bot2 years ago | 6 | from typing import Any, cast |
08b8179aDavid Schnurr2 years ago | 7 | |
| 8 | import pytest | |
| 9 | | |
| 10 | from openai import OpenAI, AsyncOpenAI | |
| 11 | from tests.utils import assert_matches_type | |
adb6da3aRobert Craigie1 years ago | 12 | from openai.types.audio import TranscriptionCreateResponse |
08b8179aDavid Schnurr2 years ago | 13 | |
| 14 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") | |
| 15 | | |
| 16 | | |
| 17 | class TestTranscriptions: | |
98d779fbStainless Bot2 years ago | 18 | parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) |
08b8179aDavid Schnurr2 years ago | 19 | |
| 20 | @parametrize | |
2b4bc759stainless-app[bot]1 years ago | 21 | def test_method_create_overload_1(self, client: OpenAI) -> None: |
08b8179aDavid Schnurr2 years ago | 22 | transcription = client.audio.transcriptions.create( |
0a4ca536stainless-app[bot]3 months ago | 23 | file=b"Example data", |
2b4bc759stainless-app[bot]1 years ago | 24 | model="gpt-4o-transcribe", |
08b8179aDavid Schnurr2 years ago | 25 | ) |
adb6da3aRobert Craigie1 years ago | 26 | assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"]) |
08b8179aDavid Schnurr2 years ago | 27 | |
| 28 | @parametrize | |
2b4bc759stainless-app[bot]1 years ago | 29 | def test_method_create_with_all_params_overload_1(self, client: OpenAI) -> None: |
08b8179aDavid Schnurr2 years ago | 30 | transcription = client.audio.transcriptions.create( |
0a4ca536stainless-app[bot]3 months ago | 31 | file=b"Example data", |
2b4bc759stainless-app[bot]1 years ago | 32 | model="gpt-4o-transcribe", |
28d60d9estainless-app[bot]1 years ago | 33 | chunking_strategy="auto", |
2b4bc759stainless-app[bot]1 years ago | 34 | include=["logprobs"], |
25cbb74fstainless-app[bot]8 months ago | 35 | known_speaker_names=["string"], |
| 36 | known_speaker_references=["string"], | |
2b4bc759stainless-app[bot]1 years ago | 37 | language="language", |
| 38 | prompt="prompt", | |
08b8179aDavid Schnurr2 years ago | 39 | response_format="json", |
2b4bc759stainless-app[bot]1 years ago | 40 | stream=False, |
08b8179aDavid Schnurr2 years ago | 41 | temperature=0, |
dd19d4f9Stainless Bot1 years ago | 42 | timestamp_granularities=["word"], |
08b8179aDavid Schnurr2 years ago | 43 | ) |
adb6da3aRobert Craigie1 years ago | 44 | assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"]) |
08b8179aDavid Schnurr2 years ago | 45 | |
| 46 | @parametrize | |
2b4bc759stainless-app[bot]1 years ago | 47 | def test_raw_response_create_overload_1(self, client: OpenAI) -> None: |
08b8179aDavid Schnurr2 years ago | 48 | response = client.audio.transcriptions.with_raw_response.create( |
0a4ca536stainless-app[bot]3 months ago | 49 | file=b"Example data", |
2b4bc759stainless-app[bot]1 years ago | 50 | model="gpt-4o-transcribe", |
08b8179aDavid Schnurr2 years ago | 51 | ) |
86379b44Stainless Bot2 years ago | 52 | |
| 53 | assert response.is_closed is True | |
08b8179aDavid Schnurr2 years ago | 54 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 55 | transcription = response.parse() | |
adb6da3aRobert Craigie1 years ago | 56 | assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"]) |
08b8179aDavid Schnurr2 years ago | 57 | |
86379b44Stainless Bot2 years ago | 58 | @parametrize |
2b4bc759stainless-app[bot]1 years ago | 59 | def test_streaming_response_create_overload_1(self, client: OpenAI) -> None: |
86379b44Stainless Bot2 years ago | 60 | with client.audio.transcriptions.with_streaming_response.create( |
0a4ca536stainless-app[bot]3 months ago | 61 | file=b"Example data", |
2b4bc759stainless-app[bot]1 years ago | 62 | model="gpt-4o-transcribe", |
86379b44Stainless Bot2 years ago | 63 | ) as response: |
| 64 | assert not response.is_closed | |
| 65 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 66 | | |
| 67 | transcription = response.parse() | |
adb6da3aRobert Craigie1 years ago | 68 | assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"]) |
86379b44Stainless Bot2 years ago | 69 | |
| 70 | assert cast(Any, response.is_closed) is True | |
| 71 | | |
2b4bc759stainless-app[bot]1 years ago | 72 | @parametrize |
| 73 | def test_method_create_overload_2(self, client: OpenAI) -> None: | |
| 74 | transcription_stream = client.audio.transcriptions.create( | |
0a4ca536stainless-app[bot]3 months ago | 75 | file=b"Example data", |
2b4bc759stainless-app[bot]1 years ago | 76 | model="gpt-4o-transcribe", |
| 77 | stream=True, | |
| 78 | ) | |
| 79 | transcription_stream.response.close() | |
| 80 | | |
| 81 | @parametrize | |
| 82 | def test_method_create_with_all_params_overload_2(self, client: OpenAI) -> None: | |
| 83 | transcription_stream = client.audio.transcriptions.create( | |
0a4ca536stainless-app[bot]3 months ago | 84 | file=b"Example data", |
2b4bc759stainless-app[bot]1 years ago | 85 | model="gpt-4o-transcribe", |
| 86 | stream=True, | |
28d60d9estainless-app[bot]1 years ago | 87 | chunking_strategy="auto", |
2b4bc759stainless-app[bot]1 years ago | 88 | include=["logprobs"], |
25cbb74fstainless-app[bot]8 months ago | 89 | known_speaker_names=["string"], |
| 90 | known_speaker_references=["string"], | |
2b4bc759stainless-app[bot]1 years ago | 91 | language="language", |
| 92 | prompt="prompt", | |
| 93 | response_format="json", | |
| 94 | temperature=0, | |
| 95 | timestamp_granularities=["word"], | |
| 96 | ) | |
| 97 | transcription_stream.response.close() | |
| 98 | | |
| 99 | @parametrize | |
| 100 | def test_raw_response_create_overload_2(self, client: OpenAI) -> None: | |
| 101 | response = client.audio.transcriptions.with_raw_response.create( | |
0a4ca536stainless-app[bot]3 months ago | 102 | file=b"Example data", |
2b4bc759stainless-app[bot]1 years ago | 103 | model="gpt-4o-transcribe", |
| 104 | stream=True, | |
| 105 | ) | |
| 106 | | |
| 107 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 108 | stream = response.parse() | |
| 109 | stream.close() | |
| 110 | | |
| 111 | @parametrize | |
| 112 | def test_streaming_response_create_overload_2(self, client: OpenAI) -> None: | |
| 113 | with client.audio.transcriptions.with_streaming_response.create( | |
0a4ca536stainless-app[bot]3 months ago | 114 | file=b"Example data", |
2b4bc759stainless-app[bot]1 years ago | 115 | model="gpt-4o-transcribe", |
| 116 | stream=True, | |
| 117 | ) as response: | |
| 118 | assert not response.is_closed | |
| 119 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 120 | | |
| 121 | stream = response.parse() | |
| 122 | stream.close() | |
| 123 | | |
| 124 | assert cast(Any, response.is_closed) is True | |
| 125 | | |
08b8179aDavid Schnurr2 years ago | 126 | |
| 127 | class TestAsyncTranscriptions: | |
c62e9907stainless-app[bot]1 years ago | 128 | parametrize = pytest.mark.parametrize( |
| 129 | "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] | |
| 130 | ) | |
08b8179aDavid Schnurr2 years ago | 131 | |
| 132 | @parametrize | |
2b4bc759stainless-app[bot]1 years ago | 133 | async def test_method_create_overload_1(self, async_client: AsyncOpenAI) -> None: |
98d779fbStainless Bot2 years ago | 134 | transcription = await async_client.audio.transcriptions.create( |
0a4ca536stainless-app[bot]3 months ago | 135 | file=b"Example data", |
2b4bc759stainless-app[bot]1 years ago | 136 | model="gpt-4o-transcribe", |
08b8179aDavid Schnurr2 years ago | 137 | ) |
adb6da3aRobert Craigie1 years ago | 138 | assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"]) |
08b8179aDavid Schnurr2 years ago | 139 | |
| 140 | @parametrize | |
2b4bc759stainless-app[bot]1 years ago | 141 | async def test_method_create_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None: |
98d779fbStainless Bot2 years ago | 142 | transcription = await async_client.audio.transcriptions.create( |
0a4ca536stainless-app[bot]3 months ago | 143 | file=b"Example data", |
2b4bc759stainless-app[bot]1 years ago | 144 | model="gpt-4o-transcribe", |
28d60d9estainless-app[bot]1 years ago | 145 | chunking_strategy="auto", |
2b4bc759stainless-app[bot]1 years ago | 146 | include=["logprobs"], |
25cbb74fstainless-app[bot]8 months ago | 147 | known_speaker_names=["string"], |
| 148 | known_speaker_references=["string"], | |
2b4bc759stainless-app[bot]1 years ago | 149 | language="language", |
| 150 | prompt="prompt", | |
08b8179aDavid Schnurr2 years ago | 151 | response_format="json", |
2b4bc759stainless-app[bot]1 years ago | 152 | stream=False, |
08b8179aDavid Schnurr2 years ago | 153 | temperature=0, |
dd19d4f9Stainless Bot1 years ago | 154 | timestamp_granularities=["word"], |
08b8179aDavid Schnurr2 years ago | 155 | ) |
adb6da3aRobert Craigie1 years ago | 156 | assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"]) |
08b8179aDavid Schnurr2 years ago | 157 | |
| 158 | @parametrize | |
2b4bc759stainless-app[bot]1 years ago | 159 | async def test_raw_response_create_overload_1(self, async_client: AsyncOpenAI) -> None: |
98d779fbStainless Bot2 years ago | 160 | response = await async_client.audio.transcriptions.with_raw_response.create( |
0a4ca536stainless-app[bot]3 months ago | 161 | file=b"Example data", |
2b4bc759stainless-app[bot]1 years ago | 162 | model="gpt-4o-transcribe", |
08b8179aDavid Schnurr2 years ago | 163 | ) |
86379b44Stainless Bot2 years ago | 164 | |
| 165 | assert response.is_closed is True | |
08b8179aDavid Schnurr2 years ago | 166 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 167 | transcription = response.parse() | |
adb6da3aRobert Craigie1 years ago | 168 | assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"]) |
86379b44Stainless Bot2 years ago | 169 | |
| 170 | @parametrize | |
2b4bc759stainless-app[bot]1 years ago | 171 | async def test_streaming_response_create_overload_1(self, async_client: AsyncOpenAI) -> None: |
98d779fbStainless Bot2 years ago | 172 | async with async_client.audio.transcriptions.with_streaming_response.create( |
0a4ca536stainless-app[bot]3 months ago | 173 | file=b"Example data", |
2b4bc759stainless-app[bot]1 years ago | 174 | model="gpt-4o-transcribe", |
86379b44Stainless Bot2 years ago | 175 | ) as response: |
| 176 | assert not response.is_closed | |
| 177 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 178 | | |
| 179 | transcription = await response.parse() | |
adb6da3aRobert Craigie1 years ago | 180 | assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"]) |
86379b44Stainless Bot2 years ago | 181 | |
| 182 | assert cast(Any, response.is_closed) is True | |
2b4bc759stainless-app[bot]1 years ago | 183 | |
| 184 | @parametrize | |
| 185 | async def test_method_create_overload_2(self, async_client: AsyncOpenAI) -> None: | |
| 186 | transcription_stream = await async_client.audio.transcriptions.create( | |
0a4ca536stainless-app[bot]3 months ago | 187 | file=b"Example data", |
2b4bc759stainless-app[bot]1 years ago | 188 | model="gpt-4o-transcribe", |
| 189 | stream=True, | |
| 190 | ) | |
| 191 | await transcription_stream.response.aclose() | |
| 192 | | |
| 193 | @parametrize | |
| 194 | async def test_method_create_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None: | |
| 195 | transcription_stream = await async_client.audio.transcriptions.create( | |
0a4ca536stainless-app[bot]3 months ago | 196 | file=b"Example data", |
2b4bc759stainless-app[bot]1 years ago | 197 | model="gpt-4o-transcribe", |
| 198 | stream=True, | |
28d60d9estainless-app[bot]1 years ago | 199 | chunking_strategy="auto", |
2b4bc759stainless-app[bot]1 years ago | 200 | include=["logprobs"], |
25cbb74fstainless-app[bot]8 months ago | 201 | known_speaker_names=["string"], |
| 202 | known_speaker_references=["string"], | |
2b4bc759stainless-app[bot]1 years ago | 203 | language="language", |
| 204 | prompt="prompt", | |
| 205 | response_format="json", | |
| 206 | temperature=0, | |
| 207 | timestamp_granularities=["word"], | |
| 208 | ) | |
| 209 | await transcription_stream.response.aclose() | |
| 210 | | |
| 211 | @parametrize | |
| 212 | async def test_raw_response_create_overload_2(self, async_client: AsyncOpenAI) -> None: | |
| 213 | response = await async_client.audio.transcriptions.with_raw_response.create( | |
0a4ca536stainless-app[bot]3 months ago | 214 | file=b"Example data", |
2b4bc759stainless-app[bot]1 years ago | 215 | model="gpt-4o-transcribe", |
| 216 | stream=True, | |
| 217 | ) | |
| 218 | | |
| 219 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 220 | stream = response.parse() | |
| 221 | await stream.close() | |
| 222 | | |
| 223 | @parametrize | |
| 224 | async def test_streaming_response_create_overload_2(self, async_client: AsyncOpenAI) -> None: | |
| 225 | async with async_client.audio.transcriptions.with_streaming_response.create( | |
0a4ca536stainless-app[bot]3 months ago | 226 | file=b"Example data", |
2b4bc759stainless-app[bot]1 years ago | 227 | model="gpt-4o-transcribe", |
| 228 | stream=True, | |
| 229 | ) as response: | |
| 230 | assert not response.is_closed | |
| 231 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 232 | | |
| 233 | stream = await response.parse() | |
| 234 | await stream.close() | |
| 235 | | |
| 236 | assert cast(Any, response.is_closed) is True |