openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.86.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 · 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:
98d779fbStainless Bot2 years ago124parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
08b8179aDavid Schnurr2 years ago125
126@parametrize
2b4bc759stainless-app[bot]1 years ago127async def test_method_create_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago128transcription = await async_client.audio.transcriptions.create(
08b8179aDavid Schnurr2 years ago129file=b"raw file contents",
2b4bc759stainless-app[bot]1 years ago130model="gpt-4o-transcribe",
08b8179aDavid Schnurr2 years ago131)
adb6da3aRobert Craigie1 years ago132assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago133
134@parametrize
2b4bc759stainless-app[bot]1 years ago135async def test_method_create_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago136transcription = await async_client.audio.transcriptions.create(
08b8179aDavid Schnurr2 years ago137file=b"raw file contents",
2b4bc759stainless-app[bot]1 years ago138model="gpt-4o-transcribe",
28d60d9estainless-app[bot]1 years ago139chunking_strategy="auto",
2b4bc759stainless-app[bot]1 years ago140include=["logprobs"],
141language="language",
142prompt="prompt",
08b8179aDavid Schnurr2 years ago143response_format="json",
2b4bc759stainless-app[bot]1 years ago144stream=False,
08b8179aDavid Schnurr2 years ago145temperature=0,
dd19d4f9Stainless Bot1 years ago146timestamp_granularities=["word"],
08b8179aDavid Schnurr2 years ago147)
adb6da3aRobert Craigie1 years ago148assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago149
150@parametrize
2b4bc759stainless-app[bot]1 years ago151async def test_raw_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago152response = await async_client.audio.transcriptions.with_raw_response.create(
08b8179aDavid Schnurr2 years ago153file=b"raw file contents",
2b4bc759stainless-app[bot]1 years ago154model="gpt-4o-transcribe",
08b8179aDavid Schnurr2 years ago155)
86379b44Stainless Bot2 years ago156
157assert response.is_closed is True
08b8179aDavid Schnurr2 years ago158assert response.http_request.headers.get("X-Stainless-Lang") == "python"
159transcription = response.parse()
adb6da3aRobert Craigie1 years ago160assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
86379b44Stainless Bot2 years ago161
162@parametrize
2b4bc759stainless-app[bot]1 years ago163async def test_streaming_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
98d779fbStainless Bot2 years ago164async with async_client.audio.transcriptions.with_streaming_response.create(
86379b44Stainless Bot2 years ago165file=b"raw file contents",
2b4bc759stainless-app[bot]1 years ago166model="gpt-4o-transcribe",
86379b44Stainless Bot2 years ago167) as response:
168assert not response.is_closed
169assert response.http_request.headers.get("X-Stainless-Lang") == "python"
170
171transcription = await response.parse()
adb6da3aRobert Craigie1 years ago172assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
86379b44Stainless Bot2 years ago173
174assert cast(Any, response.is_closed) is True
2b4bc759stainless-app[bot]1 years ago175
176@parametrize
177async def test_method_create_overload_2(self, async_client: AsyncOpenAI) -> None:
178transcription_stream = await async_client.audio.transcriptions.create(
179file=b"raw file contents",
180model="gpt-4o-transcribe",
181stream=True,
182)
183await transcription_stream.response.aclose()
184
185@parametrize
186async def test_method_create_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None:
187transcription_stream = await async_client.audio.transcriptions.create(
188file=b"raw file contents",
189model="gpt-4o-transcribe",
190stream=True,
28d60d9estainless-app[bot]1 years ago191chunking_strategy="auto",
2b4bc759stainless-app[bot]1 years ago192include=["logprobs"],
193language="language",
194prompt="prompt",
195response_format="json",
196temperature=0,
197timestamp_granularities=["word"],
198)
199await transcription_stream.response.aclose()
200
201@parametrize
202async def test_raw_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
203response = await async_client.audio.transcriptions.with_raw_response.create(
204file=b"raw file contents",
205model="gpt-4o-transcribe",
206stream=True,
207)
208
209assert response.http_request.headers.get("X-Stainless-Lang") == "python"
210stream = response.parse()
211await stream.close()
212
213@parametrize
214async def test_streaming_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
215async with async_client.audio.transcriptions.with_streaming_response.create(
216file=b"raw file contents",
217model="gpt-4o-transcribe",
218stream=True,
219) as response:
220assert not response.is_closed
221assert response.http_request.headers.get("X-Stainless-Lang") == "python"
222
223stream = await response.parse()
224await stream.close()
225
226assert cast(Any, response.is_closed) is True