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/audio/test_transcriptions.py

222lines · 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",
33include=["logprobs"],
34language="language",
35prompt="prompt",
08b8179aDavid Schnurr2 years ago36response_format="json",
2b4bc759stainless-app[bot]1 years ago37stream=False,
08b8179aDavid Schnurr2 years ago38temperature=0,
dd19d4f9Stainless Bot1 years ago39timestamp_granularities=["word"],
08b8179aDavid Schnurr2 years ago40)
adb6da3aRobert Craigie1 years ago41assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago42
43@parametrize
2b4bc759stainless-app[bot]1 years ago44def test_raw_response_create_overload_1(self, client: OpenAI) -> None:
08b8179aDavid Schnurr2 years ago45response = client.audio.transcriptions.with_raw_response.create(
46file=b"raw file contents",
2b4bc759stainless-app[bot]1 years ago47model="gpt-4o-transcribe",
08b8179aDavid Schnurr2 years ago48)
86379b44Stainless Bot2 years ago49
50assert response.is_closed is True
08b8179aDavid Schnurr2 years ago51assert response.http_request.headers.get("X-Stainless-Lang") == "python"
52transcription = response.parse()
adb6da3aRobert Craigie1 years ago53assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago54
86379b44Stainless Bot2 years ago55@parametrize
2b4bc759stainless-app[bot]1 years ago56def test_streaming_response_create_overload_1(self, client: OpenAI) -> None:
86379b44Stainless Bot2 years ago57with client.audio.transcriptions.with_streaming_response.create(
58file=b"raw file contents",
2b4bc759stainless-app[bot]1 years ago59model="gpt-4o-transcribe",
86379b44Stainless Bot2 years ago60) as response:
61assert not response.is_closed
62assert response.http_request.headers.get("X-Stainless-Lang") == "python"
63
64transcription = response.parse()
adb6da3aRobert Craigie1 years ago65assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
86379b44Stainless Bot2 years ago66
67assert cast(Any, response.is_closed) is True
68
2b4bc759stainless-app[bot]1 years ago69@parametrize
70def test_method_create_overload_2(self, client: OpenAI) -> None:
71transcription_stream = client.audio.transcriptions.create(
72file=b"raw file contents",
73model="gpt-4o-transcribe",
74stream=True,
75)
76transcription_stream.response.close()
77
78@parametrize
79def test_method_create_with_all_params_overload_2(self, client: OpenAI) -> None:
80transcription_stream = client.audio.transcriptions.create(
81file=b"raw file contents",
82model="gpt-4o-transcribe",
83stream=True,
84include=["logprobs"],
85language="language",
86prompt="prompt",
87response_format="json",
88temperature=0,
89timestamp_granularities=["word"],
90)
91transcription_stream.response.close()
92
93@parametrize
94def test_raw_response_create_overload_2(self, client: OpenAI) -> None:
95response = client.audio.transcriptions.with_raw_response.create(
96file=b"raw file contents",
97model="gpt-4o-transcribe",
98stream=True,
99)
100
101assert response.http_request.headers.get("X-Stainless-Lang") == "python"
102stream = response.parse()
103stream.close()
104
105@parametrize
106def test_streaming_response_create_overload_2(self, client: OpenAI) -> None:
107with client.audio.transcriptions.with_streaming_response.create(
108file=b"raw file contents",
109model="gpt-4o-transcribe",
110stream=True,
111) as response:
112assert not response.is_closed
113assert response.http_request.headers.get("X-Stainless-Lang") == "python"
114
115stream = response.parse()
116stream.close()
117
118assert cast(Any, response.is_closed) is True
119
08b8179aDavid Schnurr2 years ago120
121class TestAsyncTranscriptions:
98d779fbStainless Bot2 years ago122parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
08b8179aDavid Schnurr2 years ago123
124@parametrize
2b4bc759stainless-app[bot]1 years ago125async def test_method_create_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago126transcription = await async_client.audio.transcriptions.create(
08b8179aDavid Schnurr2 years ago127file=b"raw file contents",
2b4bc759stainless-app[bot]1 years ago128model="gpt-4o-transcribe",
08b8179aDavid Schnurr2 years ago129)
adb6da3aRobert Craigie1 years ago130assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago131
132@parametrize
2b4bc759stainless-app[bot]1 years ago133async def test_method_create_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago134transcription = await async_client.audio.transcriptions.create(
08b8179aDavid Schnurr2 years ago135file=b"raw file contents",
2b4bc759stainless-app[bot]1 years ago136model="gpt-4o-transcribe",
137include=["logprobs"],
138language="language",
139prompt="prompt",
08b8179aDavid Schnurr2 years ago140response_format="json",
2b4bc759stainless-app[bot]1 years ago141stream=False,
08b8179aDavid Schnurr2 years ago142temperature=0,
dd19d4f9Stainless Bot1 years ago143timestamp_granularities=["word"],
08b8179aDavid Schnurr2 years ago144)
adb6da3aRobert Craigie1 years ago145assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago146
147@parametrize
2b4bc759stainless-app[bot]1 years ago148async def test_raw_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago149response = await async_client.audio.transcriptions.with_raw_response.create(
08b8179aDavid Schnurr2 years ago150file=b"raw file contents",
2b4bc759stainless-app[bot]1 years ago151model="gpt-4o-transcribe",
08b8179aDavid Schnurr2 years ago152)
86379b44Stainless Bot2 years ago153
154assert response.is_closed is True
08b8179aDavid Schnurr2 years ago155assert response.http_request.headers.get("X-Stainless-Lang") == "python"
156transcription = response.parse()
adb6da3aRobert Craigie1 years ago157assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
86379b44Stainless Bot2 years ago158
159@parametrize
2b4bc759stainless-app[bot]1 years ago160async def test_streaming_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago161async with async_client.audio.transcriptions.with_streaming_response.create(
86379b44Stainless Bot2 years ago162file=b"raw file contents",
2b4bc759stainless-app[bot]1 years ago163model="gpt-4o-transcribe",
86379b44Stainless Bot2 years ago164) as response:
165assert not response.is_closed
166assert response.http_request.headers.get("X-Stainless-Lang") == "python"
167
168transcription = await response.parse()
adb6da3aRobert Craigie1 years ago169assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
86379b44Stainless Bot2 years ago170
171assert cast(Any, response.is_closed) is True
2b4bc759stainless-app[bot]1 years ago172
173@parametrize
174async def test_method_create_overload_2(self, async_client: AsyncOpenAI) -> None:
175transcription_stream = await async_client.audio.transcriptions.create(
176file=b"raw file contents",
177model="gpt-4o-transcribe",
178stream=True,
179)
180await transcription_stream.response.aclose()
181
182@parametrize
183async def test_method_create_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None:
184transcription_stream = await async_client.audio.transcriptions.create(
185file=b"raw file contents",
186model="gpt-4o-transcribe",
187stream=True,
188include=["logprobs"],
189language="language",
190prompt="prompt",
191response_format="json",
192temperature=0,
193timestamp_granularities=["word"],
194)
195await transcription_stream.response.aclose()
196
197@parametrize
198async def test_raw_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
199response = await async_client.audio.transcriptions.with_raw_response.create(
200file=b"raw file contents",
201model="gpt-4o-transcribe",
202stream=True,
203)
204
205assert response.http_request.headers.get("X-Stainless-Lang") == "python"
206stream = response.parse()
207await stream.close()
208
209@parametrize
210async def test_streaming_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
211async with async_client.audio.transcriptions.with_streaming_response.create(
212file=b"raw file contents",
213model="gpt-4o-transcribe",
214stream=True,
215) as response:
216assert not response.is_closed
217assert response.http_request.headers.get("X-Stainless-Lang") == "python"
218
219stream = await response.parse()
220await stream.close()
221
222assert cast(Any, response.is_closed) is True