openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
tests/api_resources/audio/test_transcriptions.py
114lines · modeblame
08b8179aDavid Schnurr2 years ago | 1 | # File generated from our OpenAPI spec by Stainless. |
| 2 | | |
| 3 | from __future__ import annotations | |
| 4 | | |
| 5 | import os | |
86379b44Stainless Bot2 years ago | 6 | from typing import Any, cast |
08b8179aDavid Schnurr2 years ago | 7 | |
| 8 | import pytest | |
| 9 | | |
| 10 | from openai import OpenAI, AsyncOpenAI | |
| 11 | from tests.utils import assert_matches_type | |
| 12 | from openai.types.audio import Transcription | |
| 13 | | |
| 14 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") | |
| 15 | | |
| 16 | | |
| 17 | class TestTranscriptions: | |
98d779fbStainless Bot2 years ago | 18 | parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) |
08b8179aDavid Schnurr2 years ago | 19 | |
| 20 | @parametrize | |
| 21 | def test_method_create(self, client: OpenAI) -> None: | |
| 22 | transcription = client.audio.transcriptions.create( | |
| 23 | file=b"raw file contents", | |
| 24 | model="whisper-1", | |
| 25 | ) | |
| 26 | assert_matches_type(Transcription, transcription, path=["response"]) | |
| 27 | | |
| 28 | @parametrize | |
| 29 | def test_method_create_with_all_params(self, client: OpenAI) -> None: | |
| 30 | transcription = client.audio.transcriptions.create( | |
| 31 | file=b"raw file contents", | |
| 32 | model="whisper-1", | |
| 33 | language="string", | |
| 34 | prompt="string", | |
| 35 | response_format="json", | |
| 36 | temperature=0, | |
| 37 | ) | |
| 38 | assert_matches_type(Transcription, transcription, path=["response"]) | |
| 39 | | |
| 40 | @parametrize | |
| 41 | def test_raw_response_create(self, client: OpenAI) -> None: | |
| 42 | response = client.audio.transcriptions.with_raw_response.create( | |
| 43 | file=b"raw file contents", | |
| 44 | model="whisper-1", | |
| 45 | ) | |
86379b44Stainless Bot2 years ago | 46 | |
| 47 | assert response.is_closed is True | |
08b8179aDavid Schnurr2 years ago | 48 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 49 | transcription = response.parse() | |
| 50 | assert_matches_type(Transcription, transcription, path=["response"]) | |
| 51 | | |
86379b44Stainless Bot2 years ago | 52 | @parametrize |
| 53 | def test_streaming_response_create(self, client: OpenAI) -> None: | |
| 54 | with client.audio.transcriptions.with_streaming_response.create( | |
| 55 | file=b"raw file contents", | |
| 56 | model="whisper-1", | |
| 57 | ) as response: | |
| 58 | assert not response.is_closed | |
| 59 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 60 | | |
| 61 | transcription = response.parse() | |
| 62 | assert_matches_type(Transcription, transcription, path=["response"]) | |
| 63 | | |
| 64 | assert cast(Any, response.is_closed) is True | |
| 65 | | |
08b8179aDavid Schnurr2 years ago | 66 | |
| 67 | class TestAsyncTranscriptions: | |
98d779fbStainless Bot2 years ago | 68 | parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) |
08b8179aDavid Schnurr2 years ago | 69 | |
| 70 | @parametrize | |
98d779fbStainless Bot2 years ago | 71 | async def test_method_create(self, async_client: AsyncOpenAI) -> None: |
| 72 | transcription = await async_client.audio.transcriptions.create( | |
08b8179aDavid Schnurr2 years ago | 73 | file=b"raw file contents", |
| 74 | model="whisper-1", | |
| 75 | ) | |
| 76 | assert_matches_type(Transcription, transcription, path=["response"]) | |
| 77 | | |
| 78 | @parametrize | |
98d779fbStainless Bot2 years ago | 79 | async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 80 | transcription = await async_client.audio.transcriptions.create( | |
08b8179aDavid Schnurr2 years ago | 81 | file=b"raw file contents", |
| 82 | model="whisper-1", | |
| 83 | language="string", | |
| 84 | prompt="string", | |
| 85 | response_format="json", | |
| 86 | temperature=0, | |
| 87 | ) | |
| 88 | assert_matches_type(Transcription, transcription, path=["response"]) | |
| 89 | | |
| 90 | @parametrize | |
98d779fbStainless Bot2 years ago | 91 | async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None: |
| 92 | response = await async_client.audio.transcriptions.with_raw_response.create( | |
08b8179aDavid Schnurr2 years ago | 93 | file=b"raw file contents", |
| 94 | model="whisper-1", | |
| 95 | ) | |
86379b44Stainless Bot2 years ago | 96 | |
| 97 | assert response.is_closed is True | |
08b8179aDavid Schnurr2 years ago | 98 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 99 | transcription = response.parse() | |
| 100 | assert_matches_type(Transcription, transcription, path=["response"]) | |
86379b44Stainless Bot2 years ago | 101 | |
| 102 | @parametrize | |
98d779fbStainless Bot2 years ago | 103 | async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None: |
| 104 | async with async_client.audio.transcriptions.with_streaming_response.create( | |
86379b44Stainless Bot2 years ago | 105 | file=b"raw file contents", |
| 106 | model="whisper-1", | |
| 107 | ) as response: | |
| 108 | assert not response.is_closed | |
| 109 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 110 | | |
| 111 | transcription = await response.parse() | |
| 112 | assert_matches_type(Transcription, transcription, path=["response"]) | |
| 113 | | |
| 114 | assert cast(Any, response.is_closed) is True |