openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.104.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/audio/test_transcriptions.py

228lines · modeblame

5cfb125aStainless Bot2 years ago1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
08b8179aDavid Schnurr2 years ago2
3from __future__ import annotations
4
5import os
86379b44Stainless Bot2 years ago6from typing import Any, cast
08b8179aDavid Schnurr2 years ago7
8import pytest
9
10from openai import OpenAI, AsyncOpenAI
11from tests.utils import assert_matches_type
adb6da3aRobert Craigie1 years ago12from openai.types.audio import TranscriptionCreateResponse
08b8179aDavid Schnurr2 years ago13
14base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
15
16
17class TestTranscriptions:
98d779fbStainless Bot2 years ago18parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
08b8179aDavid Schnurr2 years ago19
20@parametrize
2b4bc759stainless-app[bot]1 years ago21def test_method_create_overload_1(self, client: OpenAI) -> None:
08b8179aDavid Schnurr2 years ago22transcription = client.audio.transcriptions.create(
23file=b"raw file contents",
2b4bc759stainless-app[bot]1 years ago24model="gpt-4o-transcribe",
08b8179aDavid Schnurr2 years ago25)
adb6da3aRobert Craigie1 years ago26assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago27
28@parametrize
2b4bc759stainless-app[bot]1 years ago29def test_method_create_with_all_params_overload_1(self, client: OpenAI) -> None:
08b8179aDavid Schnurr2 years ago30transcription = client.audio.transcriptions.create(
31file=b"raw file contents",
2b4bc759stainless-app[bot]1 years ago32model="gpt-4o-transcribe",
28d60d9estainless-app[bot]1 years ago33chunking_strategy="auto",
2b4bc759stainless-app[bot]1 years ago34include=["logprobs"],
35language="language",
36prompt="prompt",
08b8179aDavid Schnurr2 years ago37response_format="json",
2b4bc759stainless-app[bot]1 years ago38stream=False,
08b8179aDavid Schnurr2 years ago39temperature=0,
dd19d4f9Stainless Bot1 years ago40timestamp_granularities=["word"],
08b8179aDavid Schnurr2 years ago41)
adb6da3aRobert Craigie1 years ago42assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago43
44@parametrize
2b4bc759stainless-app[bot]1 years ago45def test_raw_response_create_overload_1(self, client: OpenAI) -> None:
08b8179aDavid Schnurr2 years ago46response = client.audio.transcriptions.with_raw_response.create(
47file=b"raw file contents",
2b4bc759stainless-app[bot]1 years ago48model="gpt-4o-transcribe",
08b8179aDavid Schnurr2 years ago49)
86379b44Stainless Bot2 years ago50
51assert response.is_closed is True
08b8179aDavid Schnurr2 years ago52assert response.http_request.headers.get("X-Stainless-Lang") == "python"
53transcription = response.parse()
adb6da3aRobert Craigie1 years ago54assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago55
86379b44Stainless Bot2 years ago56@parametrize
2b4bc759stainless-app[bot]1 years ago57def test_streaming_response_create_overload_1(self, client: OpenAI) -> None:
86379b44Stainless Bot2 years ago58with client.audio.transcriptions.with_streaming_response.create(
59file=b"raw file contents",
2b4bc759stainless-app[bot]1 years ago60model="gpt-4o-transcribe",
86379b44Stainless Bot2 years ago61) as response:
62assert not response.is_closed
63assert response.http_request.headers.get("X-Stainless-Lang") == "python"
64
65transcription = response.parse()
adb6da3aRobert Craigie1 years ago66assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
86379b44Stainless Bot2 years ago67
68assert cast(Any, response.is_closed) is True
69
2b4bc759stainless-app[bot]1 years ago70@parametrize
71def test_method_create_overload_2(self, client: OpenAI) -> None:
72transcription_stream = client.audio.transcriptions.create(
73file=b"raw file contents",
74model="gpt-4o-transcribe",
75stream=True,
76)
77transcription_stream.response.close()
78
79@parametrize
80def test_method_create_with_all_params_overload_2(self, client: OpenAI) -> None:
81transcription_stream = client.audio.transcriptions.create(
82file=b"raw file contents",
83model="gpt-4o-transcribe",
84stream=True,
28d60d9estainless-app[bot]1 years ago85chunking_strategy="auto",
2b4bc759stainless-app[bot]1 years ago86include=["logprobs"],
87language="language",
88prompt="prompt",
89response_format="json",
90temperature=0,
91timestamp_granularities=["word"],
92)
93transcription_stream.response.close()
94
95@parametrize
96def test_raw_response_create_overload_2(self, client: OpenAI) -> None:
97response = client.audio.transcriptions.with_raw_response.create(
98file=b"raw file contents",
99model="gpt-4o-transcribe",
100stream=True,
101)
102
103assert response.http_request.headers.get("X-Stainless-Lang") == "python"
104stream = response.parse()
105stream.close()
106
107@parametrize
108def test_streaming_response_create_overload_2(self, client: OpenAI) -> None:
109with client.audio.transcriptions.with_streaming_response.create(
110file=b"raw file contents",
111model="gpt-4o-transcribe",
112stream=True,
113) as response:
114assert not response.is_closed
115assert response.http_request.headers.get("X-Stainless-Lang") == "python"
116
117stream = response.parse()
118stream.close()
119
120assert cast(Any, response.is_closed) is True
121
08b8179aDavid Schnurr2 years ago122
123class TestAsyncTranscriptions:
c62e9907stainless-app[bot]1 years ago124parametrize = pytest.mark.parametrize(
125"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
126)
08b8179aDavid Schnurr2 years ago127
128@parametrize
2b4bc759stainless-app[bot]1 years ago129async def test_method_create_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago130transcription = await async_client.audio.transcriptions.create(
08b8179aDavid Schnurr2 years ago131file=b"raw file contents",
2b4bc759stainless-app[bot]1 years ago132model="gpt-4o-transcribe",
08b8179aDavid Schnurr2 years ago133)
adb6da3aRobert Craigie1 years ago134assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago135
136@parametrize
2b4bc759stainless-app[bot]1 years ago137async def test_method_create_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago138transcription = await async_client.audio.transcriptions.create(
08b8179aDavid Schnurr2 years ago139file=b"raw file contents",
2b4bc759stainless-app[bot]1 years ago140model="gpt-4o-transcribe",
28d60d9estainless-app[bot]1 years ago141chunking_strategy="auto",
2b4bc759stainless-app[bot]1 years ago142include=["logprobs"],
143language="language",
144prompt="prompt",
08b8179aDavid Schnurr2 years ago145response_format="json",
2b4bc759stainless-app[bot]1 years ago146stream=False,
08b8179aDavid Schnurr2 years ago147temperature=0,
dd19d4f9Stainless Bot1 years ago148timestamp_granularities=["word"],
08b8179aDavid Schnurr2 years ago149)
adb6da3aRobert Craigie1 years ago150assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago151
152@parametrize
2b4bc759stainless-app[bot]1 years ago153async def test_raw_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago154response = await async_client.audio.transcriptions.with_raw_response.create(
08b8179aDavid Schnurr2 years ago155file=b"raw file contents",
2b4bc759stainless-app[bot]1 years ago156model="gpt-4o-transcribe",
08b8179aDavid Schnurr2 years ago157)
86379b44Stainless Bot2 years ago158
159assert response.is_closed is True
08b8179aDavid Schnurr2 years ago160assert response.http_request.headers.get("X-Stainless-Lang") == "python"
161transcription = response.parse()
adb6da3aRobert Craigie1 years ago162assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
86379b44Stainless Bot2 years ago163
164@parametrize
2b4bc759stainless-app[bot]1 years ago165async def test_streaming_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago166async with async_client.audio.transcriptions.with_streaming_response.create(
86379b44Stainless Bot2 years ago167file=b"raw file contents",
2b4bc759stainless-app[bot]1 years ago168model="gpt-4o-transcribe",
86379b44Stainless Bot2 years ago169) as response:
170assert not response.is_closed
171assert response.http_request.headers.get("X-Stainless-Lang") == "python"
172
173transcription = await response.parse()
adb6da3aRobert Craigie1 years ago174assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
86379b44Stainless Bot2 years ago175
176assert cast(Any, response.is_closed) is True
2b4bc759stainless-app[bot]1 years ago177
178@parametrize
179async def test_method_create_overload_2(self, async_client: AsyncOpenAI) -> None:
180transcription_stream = await async_client.audio.transcriptions.create(
181file=b"raw file contents",
182model="gpt-4o-transcribe",
183stream=True,
184)
185await transcription_stream.response.aclose()
186
187@parametrize
188async def test_method_create_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None:
189transcription_stream = await async_client.audio.transcriptions.create(
190file=b"raw file contents",
191model="gpt-4o-transcribe",
192stream=True,
28d60d9estainless-app[bot]1 years ago193chunking_strategy="auto",
2b4bc759stainless-app[bot]1 years ago194include=["logprobs"],
195language="language",
196prompt="prompt",
197response_format="json",
198temperature=0,
199timestamp_granularities=["word"],
200)
201await transcription_stream.response.aclose()
202
203@parametrize
204async def test_raw_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
205response = await async_client.audio.transcriptions.with_raw_response.create(
206file=b"raw file contents",
207model="gpt-4o-transcribe",
208stream=True,
209)
210
211assert response.http_request.headers.get("X-Stainless-Lang") == "python"
212stream = response.parse()
213await stream.close()
214
215@parametrize
216async def test_streaming_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
217async with async_client.audio.transcriptions.with_streaming_response.create(
218file=b"raw file contents",
219model="gpt-4o-transcribe",
220stream=True,
221) as response:
222assert not response.is_closed
223assert response.http_request.headers.get("X-Stainless-Lang") == "python"
224
225stream = await response.parse()
226await stream.close()
227
228assert cast(Any, response.is_closed) is True