openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.85.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/audio/test_transcriptions.py

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