openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.63.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/audio/test_transcriptions.py

116lines · 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
21def test_method_create(self, client: OpenAI) -> None:
22transcription = client.audio.transcriptions.create(
23file=b"raw file contents",
24model="whisper-1",
25)
adb6da3aRobert Craigie1 years ago26assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago27
28@parametrize
29def test_method_create_with_all_params(self, client: OpenAI) -> None:
30transcription = client.audio.transcriptions.create(
31file=b"raw file contents",
32model="whisper-1",
33language="string",
34prompt="string",
35response_format="json",
36temperature=0,
dd19d4f9Stainless Bot1 years ago37timestamp_granularities=["word"],
08b8179aDavid Schnurr2 years ago38)
adb6da3aRobert Craigie1 years ago39assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago40
41@parametrize
42def test_raw_response_create(self, client: OpenAI) -> None:
43response = client.audio.transcriptions.with_raw_response.create(
44file=b"raw file contents",
45model="whisper-1",
46)
86379b44Stainless Bot2 years ago47
48assert response.is_closed is True
08b8179aDavid Schnurr2 years ago49assert response.http_request.headers.get("X-Stainless-Lang") == "python"
50transcription = response.parse()
adb6da3aRobert Craigie1 years ago51assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago52
86379b44Stainless Bot2 years ago53@parametrize
54def test_streaming_response_create(self, client: OpenAI) -> None:
55with client.audio.transcriptions.with_streaming_response.create(
56file=b"raw file contents",
57model="whisper-1",
58) as response:
59assert not response.is_closed
60assert response.http_request.headers.get("X-Stainless-Lang") == "python"
61
62transcription = response.parse()
adb6da3aRobert Craigie1 years ago63assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
86379b44Stainless Bot2 years ago64
65assert cast(Any, response.is_closed) is True
66
08b8179aDavid Schnurr2 years ago67
68class TestAsyncTranscriptions:
98d779fbStainless Bot2 years ago69parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
08b8179aDavid Schnurr2 years ago70
71@parametrize
98d779fbStainless Bot2 years ago72async def test_method_create(self, async_client: AsyncOpenAI) -> None:
73transcription = await async_client.audio.transcriptions.create(
08b8179aDavid Schnurr2 years ago74file=b"raw file contents",
75model="whisper-1",
76)
adb6da3aRobert Craigie1 years ago77assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago78
79@parametrize
98d779fbStainless Bot2 years ago80async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
81transcription = await async_client.audio.transcriptions.create(
08b8179aDavid Schnurr2 years ago82file=b"raw file contents",
83model="whisper-1",
84language="string",
85prompt="string",
86response_format="json",
87temperature=0,
dd19d4f9Stainless Bot1 years ago88timestamp_granularities=["word"],
08b8179aDavid Schnurr2 years ago89)
adb6da3aRobert Craigie1 years ago90assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
08b8179aDavid Schnurr2 years ago91
92@parametrize
98d779fbStainless Bot2 years ago93async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
94response = await async_client.audio.transcriptions.with_raw_response.create(
08b8179aDavid Schnurr2 years ago95file=b"raw file contents",
96model="whisper-1",
97)
86379b44Stainless Bot2 years ago98
99assert response.is_closed is True
08b8179aDavid Schnurr2 years ago100assert response.http_request.headers.get("X-Stainless-Lang") == "python"
101transcription = response.parse()
adb6da3aRobert Craigie1 years ago102assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
86379b44Stainless Bot2 years ago103
104@parametrize
98d779fbStainless Bot2 years ago105async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
106async with async_client.audio.transcriptions.with_streaming_response.create(
86379b44Stainless Bot2 years ago107file=b"raw file contents",
108model="whisper-1",
109) as response:
110assert not response.is_closed
111assert response.http_request.headers.get("X-Stainless-Lang") == "python"
112
113transcription = await response.parse()
adb6da3aRobert Craigie1 years ago114assert_matches_type(TranscriptionCreateResponse, transcription, path=["response"])
86379b44Stainless Bot2 years ago115
116assert cast(Any, response.is_closed) is True