openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
next

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/audio/test_transcriptions.py

236lines · 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(
0a4ca536stainless-app[bot]3 months ago23file=b"Example data",
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(
0a4ca536stainless-app[bot]3 months ago31file=b"Example data",
2b4bc759stainless-app[bot]1 years ago32model="gpt-4o-transcribe",
28d60d9estainless-app[bot]1 years ago33chunking_strategy="auto",
2b4bc759stainless-app[bot]1 years ago34include=["logprobs"],
25cbb74fstainless-app[bot]8 months ago35known_speaker_names=["string"],
36known_speaker_references=["string"],
2b4bc759stainless-app[bot]1 years ago37language="language",
38prompt="prompt",
08b8179aDavid Schnurr2 years ago39response_format="json",
2b4bc759stainless-app[bot]1 years ago40stream=False,
08b8179aDavid Schnurr2 years ago41temperature=0,
dd19d4f9Stainless Bot1 years ago42timestamp_granularities=["word"],
08b8179aDavid Schnurr2 years ago43)
adb6da3aRobert Craigie1 years ago44assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago45
46@parametrize
2b4bc759stainless-app[bot]1 years ago47def test_raw_response_create_overload_1(self, client: OpenAI) -> None:
08b8179aDavid Schnurr2 years ago48response = client.audio.transcriptions.with_raw_response.create(
0a4ca536stainless-app[bot]3 months ago49file=b"Example data",
2b4bc759stainless-app[bot]1 years ago50model="gpt-4o-transcribe",
08b8179aDavid Schnurr2 years ago51)
86379b44Stainless Bot2 years ago52
53assert response.is_closed is True
08b8179aDavid Schnurr2 years ago54assert response.http_request.headers.get("X-Stainless-Lang") == "python"
55transcription = response.parse()
adb6da3aRobert Craigie1 years ago56assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago57
86379b44Stainless Bot2 years ago58@parametrize
2b4bc759stainless-app[bot]1 years ago59def test_streaming_response_create_overload_1(self, client: OpenAI) -> None:
86379b44Stainless Bot2 years ago60with client.audio.transcriptions.with_streaming_response.create(
0a4ca536stainless-app[bot]3 months ago61file=b"Example data",
2b4bc759stainless-app[bot]1 years ago62model="gpt-4o-transcribe",
86379b44Stainless Bot2 years ago63) as response:
64assert not response.is_closed
65assert response.http_request.headers.get("X-Stainless-Lang") == "python"
66
67transcription = response.parse()
adb6da3aRobert Craigie1 years ago68assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
86379b44Stainless Bot2 years ago69
70assert cast(Any, response.is_closed) is True
71
2b4bc759stainless-app[bot]1 years ago72@parametrize
73def test_method_create_overload_2(self, client: OpenAI) -> None:
74transcription_stream = client.audio.transcriptions.create(
0a4ca536stainless-app[bot]3 months ago75file=b"Example data",
2b4bc759stainless-app[bot]1 years ago76model="gpt-4o-transcribe",
77stream=True,
78)
79transcription_stream.response.close()
80
81@parametrize
82def test_method_create_with_all_params_overload_2(self, client: OpenAI) -> None:
83transcription_stream = client.audio.transcriptions.create(
0a4ca536stainless-app[bot]3 months ago84file=b"Example data",
2b4bc759stainless-app[bot]1 years ago85model="gpt-4o-transcribe",
86stream=True,
28d60d9estainless-app[bot]1 years ago87chunking_strategy="auto",
2b4bc759stainless-app[bot]1 years ago88include=["logprobs"],
25cbb74fstainless-app[bot]8 months ago89known_speaker_names=["string"],
90known_speaker_references=["string"],
2b4bc759stainless-app[bot]1 years ago91language="language",
92prompt="prompt",
93response_format="json",
94temperature=0,
95timestamp_granularities=["word"],
96)
97transcription_stream.response.close()
98
99@parametrize
100def test_raw_response_create_overload_2(self, client: OpenAI) -> None:
101response = client.audio.transcriptions.with_raw_response.create(
0a4ca536stainless-app[bot]3 months ago102file=b"Example data",
2b4bc759stainless-app[bot]1 years ago103model="gpt-4o-transcribe",
104stream=True,
105)
106
107assert response.http_request.headers.get("X-Stainless-Lang") == "python"
108stream = response.parse()
109stream.close()
110
111@parametrize
112def test_streaming_response_create_overload_2(self, client: OpenAI) -> None:
113with client.audio.transcriptions.with_streaming_response.create(
0a4ca536stainless-app[bot]3 months ago114file=b"Example data",
2b4bc759stainless-app[bot]1 years ago115model="gpt-4o-transcribe",
116stream=True,
117) as response:
118assert not response.is_closed
119assert response.http_request.headers.get("X-Stainless-Lang") == "python"
120
121stream = response.parse()
122stream.close()
123
124assert cast(Any, response.is_closed) is True
125
08b8179aDavid Schnurr2 years ago126
127class TestAsyncTranscriptions:
c62e9907stainless-app[bot]1 years ago128parametrize = pytest.mark.parametrize(
129"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
130)
08b8179aDavid Schnurr2 years ago131
132@parametrize
2b4bc759stainless-app[bot]1 years ago133async def test_method_create_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago134transcription = await async_client.audio.transcriptions.create(
0a4ca536stainless-app[bot]3 months ago135file=b"Example data",
2b4bc759stainless-app[bot]1 years ago136model="gpt-4o-transcribe",
08b8179aDavid Schnurr2 years ago137)
adb6da3aRobert Craigie1 years ago138assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago139
140@parametrize
2b4bc759stainless-app[bot]1 years ago141async def test_method_create_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago142transcription = await async_client.audio.transcriptions.create(
0a4ca536stainless-app[bot]3 months ago143file=b"Example data",
2b4bc759stainless-app[bot]1 years ago144model="gpt-4o-transcribe",
28d60d9estainless-app[bot]1 years ago145chunking_strategy="auto",
2b4bc759stainless-app[bot]1 years ago146include=["logprobs"],
25cbb74fstainless-app[bot]8 months ago147known_speaker_names=["string"],
148known_speaker_references=["string"],
2b4bc759stainless-app[bot]1 years ago149language="language",
150prompt="prompt",
08b8179aDavid Schnurr2 years ago151response_format="json",
2b4bc759stainless-app[bot]1 years ago152stream=False,
08b8179aDavid Schnurr2 years ago153temperature=0,
dd19d4f9Stainless Bot1 years ago154timestamp_granularities=["word"],
08b8179aDavid Schnurr2 years ago155)
adb6da3aRobert Craigie1 years ago156assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago157
158@parametrize
2b4bc759stainless-app[bot]1 years ago159async def test_raw_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago160response = await async_client.audio.transcriptions.with_raw_response.create(
0a4ca536stainless-app[bot]3 months ago161file=b"Example data",
2b4bc759stainless-app[bot]1 years ago162model="gpt-4o-transcribe",
08b8179aDavid Schnurr2 years ago163)
86379b44Stainless Bot2 years ago164
165assert response.is_closed is True
08b8179aDavid Schnurr2 years ago166assert response.http_request.headers.get("X-Stainless-Lang") == "python"
167transcription = response.parse()
adb6da3aRobert Craigie1 years ago168assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
86379b44Stainless Bot2 years ago169
170@parametrize
2b4bc759stainless-app[bot]1 years ago171async def test_streaming_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago172async with async_client.audio.transcriptions.with_streaming_response.create(
0a4ca536stainless-app[bot]3 months ago173file=b"Example data",
2b4bc759stainless-app[bot]1 years ago174model="gpt-4o-transcribe",
86379b44Stainless Bot2 years ago175) as response:
176assert not response.is_closed
177assert response.http_request.headers.get("X-Stainless-Lang") == "python"
178
179transcription = await response.parse()
adb6da3aRobert Craigie1 years ago180assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
86379b44Stainless Bot2 years ago181
182assert cast(Any, response.is_closed) is True
2b4bc759stainless-app[bot]1 years ago183
184@parametrize
185async def test_method_create_overload_2(self, async_client: AsyncOpenAI) -> None:
186transcription_stream = await async_client.audio.transcriptions.create(
0a4ca536stainless-app[bot]3 months ago187file=b"Example data",
2b4bc759stainless-app[bot]1 years ago188model="gpt-4o-transcribe",
189stream=True,
190)
191await transcription_stream.response.aclose()
192
193@parametrize
194async def test_method_create_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None:
195transcription_stream = await async_client.audio.transcriptions.create(
0a4ca536stainless-app[bot]3 months ago196file=b"Example data",
2b4bc759stainless-app[bot]1 years ago197model="gpt-4o-transcribe",
198stream=True,
28d60d9estainless-app[bot]1 years ago199chunking_strategy="auto",
2b4bc759stainless-app[bot]1 years ago200include=["logprobs"],
25cbb74fstainless-app[bot]8 months ago201known_speaker_names=["string"],
202known_speaker_references=["string"],
2b4bc759stainless-app[bot]1 years ago203language="language",
204prompt="prompt",
205response_format="json",
206temperature=0,
207timestamp_granularities=["word"],
208)
209await transcription_stream.response.aclose()
210
211@parametrize
212async def test_raw_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
213response = await async_client.audio.transcriptions.with_raw_response.create(
0a4ca536stainless-app[bot]3 months ago214file=b"Example data",
2b4bc759stainless-app[bot]1 years ago215model="gpt-4o-transcribe",
216stream=True,
217)
218
219assert response.http_request.headers.get("X-Stainless-Lang") == "python"
220stream = response.parse()
221await stream.close()
222
223@parametrize
224async def test_streaming_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
225async with async_client.audio.transcriptions.with_streaming_response.create(
0a4ca536stainless-app[bot]3 months ago226file=b"Example data",
2b4bc759stainless-app[bot]1 years ago227model="gpt-4o-transcribe",
228stream=True,
229) as response:
230assert not response.is_closed
231assert response.http_request.headers.get("X-Stainless-Lang") == "python"
232
233stream = await response.parse()
234await stream.close()
235
236assert cast(Any, response.is_closed) is True