openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.77.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/audio/test_transcriptions.py

222lines · 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.audio import TranscriptionCreateResponse
13
14base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
15
16
17class TestTranscriptions:
18 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
19
20 @parametrize
21 def test_method_create_overload_1(self, client: OpenAI) -> None:
22 transcription = client.audio.transcriptions.create(
23 file=b"raw file contents",
24 model="gpt-4o-transcribe",
25 )
26 assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
27
28 @parametrize
29 def test_method_create_with_all_params_overload_1(self, client: OpenAI) -> None:
30 transcription = client.audio.transcriptions.create(
31 file=b"raw file contents",
32 model="gpt-4o-transcribe",
33 include=["logprobs"],
34 language="language",
35 prompt="prompt",
36 response_format="json",
37 stream=False,
38 temperature=0,
39 timestamp_granularities=["word"],
40 )
41 assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
42
43 @parametrize
44 def test_raw_response_create_overload_1(self, client: OpenAI) -> None:
45 response = client.audio.transcriptions.with_raw_response.create(
46 file=b"raw file contents",
47 model="gpt-4o-transcribe",
48 )
49
50 assert response.is_closed is True
51 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
52 transcription = response.parse()
53 assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
54
55 @parametrize
56 def test_streaming_response_create_overload_1(self, client: OpenAI) -> None:
57 with client.audio.transcriptions.with_streaming_response.create(
58 file=b"raw file contents",
59 model="gpt-4o-transcribe",
60 ) as response:
61 assert not response.is_closed
62 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
63
64 transcription = response.parse()
65 assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
66
67 assert cast(Any, response.is_closed) is True
68
69 @parametrize
70 def test_method_create_overload_2(self, client: OpenAI) -> None:
71 transcription_stream = client.audio.transcriptions.create(
72 file=b"raw file contents",
73 model="gpt-4o-transcribe",
74 stream=True,
75 )
76 transcription_stream.response.close()
77
78 @parametrize
79 def test_method_create_with_all_params_overload_2(self, client: OpenAI) -> None:
80 transcription_stream = client.audio.transcriptions.create(
81 file=b"raw file contents",
82 model="gpt-4o-transcribe",
83 stream=True,
84 include=["logprobs"],
85 language="language",
86 prompt="prompt",
87 response_format="json",
88 temperature=0,
89 timestamp_granularities=["word"],
90 )
91 transcription_stream.response.close()
92
93 @parametrize
94 def test_raw_response_create_overload_2(self, client: OpenAI) -> None:
95 response = client.audio.transcriptions.with_raw_response.create(
96 file=b"raw file contents",
97 model="gpt-4o-transcribe",
98 stream=True,
99 )
100
101 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
102 stream = response.parse()
103 stream.close()
104
105 @parametrize
106 def test_streaming_response_create_overload_2(self, client: OpenAI) -> None:
107 with client.audio.transcriptions.with_streaming_response.create(
108 file=b"raw file contents",
109 model="gpt-4o-transcribe",
110 stream=True,
111 ) as response:
112 assert not response.is_closed
113 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
114
115 stream = response.parse()
116 stream.close()
117
118 assert cast(Any, response.is_closed) is True
119
120
121class TestAsyncTranscriptions:
122 parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
123
124 @parametrize
125 async def test_method_create_overload_1(self, async_client: AsyncOpenAI) -> None:
126 transcription = await async_client.audio.transcriptions.create(
127 file=b"raw file contents",
128 model="gpt-4o-transcribe",
129 )
130 assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
131
132 @parametrize
133 async def test_method_create_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
134 transcription = await async_client.audio.transcriptions.create(
135 file=b"raw file contents",
136 model="gpt-4o-transcribe",
137 include=["logprobs"],
138 language="language",
139 prompt="prompt",
140 response_format="json",
141 stream=False,
142 temperature=0,
143 timestamp_granularities=["word"],
144 )
145 assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
146
147 @parametrize
148 async def test_raw_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
149 response = await async_client.audio.transcriptions.with_raw_response.create(
150 file=b"raw file contents",
151 model="gpt-4o-transcribe",
152 )
153
154 assert response.is_closed is True
155 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
156 transcription = response.parse()
157 assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
158
159 @parametrize
160 async def test_streaming_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
161 async with async_client.audio.transcriptions.with_streaming_response.create(
162 file=b"raw file contents",
163 model="gpt-4o-transcribe",
164 ) as response:
165 assert not response.is_closed
166 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
167
168 transcription = await response.parse()
169 assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
170
171 assert cast(Any, response.is_closed) is True
172
173 @parametrize
174 async def test_method_create_overload_2(self, async_client: AsyncOpenAI) -> None:
175 transcription_stream = await async_client.audio.transcriptions.create(
176 file=b"raw file contents",
177 model="gpt-4o-transcribe",
178 stream=True,
179 )
180 await transcription_stream.response.aclose()
181
182 @parametrize
183 async def test_method_create_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None:
184 transcription_stream = await async_client.audio.transcriptions.create(
185 file=b"raw file contents",
186 model="gpt-4o-transcribe",
187 stream=True,
188 include=["logprobs"],
189 language="language",
190 prompt="prompt",
191 response_format="json",
192 temperature=0,
193 timestamp_granularities=["word"],
194 )
195 await transcription_stream.response.aclose()
196
197 @parametrize
198 async def test_raw_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
199 response = await async_client.audio.transcriptions.with_raw_response.create(
200 file=b"raw file contents",
201 model="gpt-4o-transcribe",
202 stream=True,
203 )
204
205 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
206 stream = response.parse()
207 await stream.close()
208
209 @parametrize
210 async def test_streaming_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
211 async with async_client.audio.transcriptions.with_streaming_response.create(
212 file=b"raw file contents",
213 model="gpt-4o-transcribe",
214 stream=True,
215 ) as response:
216 assert not response.is_closed
217 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
218
219 stream = await response.parse()
220 await stream.close()
221
222 assert cast(Any, response.is_closed) is True
223