openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.9.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/audio/test_transcriptions.py

114lines · modeblame

08b8179aDavid Schnurr2 years ago1# File generated from our OpenAPI spec by Stainless.
2
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
12from openai.types.audio import Transcription
13
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)
26assert_matches_type(Transcription, transcription, path=["response"])
27
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,
37)
38assert_matches_type(Transcription, transcription, path=["response"])
39
40@parametrize
41def test_raw_response_create(self, client: OpenAI) -> None:
42response = client.audio.transcriptions.with_raw_response.create(
43file=b"raw file contents",
44model="whisper-1",
45)
86379b44Stainless Bot2 years ago46
47assert response.is_closed is True
08b8179aDavid Schnurr2 years ago48assert response.http_request.headers.get("X-Stainless-Lang") == "python"
49transcription = response.parse()
50assert_matches_type(Transcription, transcription, path=["response"])
51
86379b44Stainless Bot2 years ago52@parametrize
53def test_streaming_response_create(self, client: OpenAI) -> None:
54with client.audio.transcriptions.with_streaming_response.create(
55file=b"raw file contents",
56model="whisper-1",
57) as response:
58assert not response.is_closed
59assert response.http_request.headers.get("X-Stainless-Lang") == "python"
60
61transcription = response.parse()
62assert_matches_type(Transcription, transcription, path=["response"])
63
64assert cast(Any, response.is_closed) is True
65
08b8179aDavid Schnurr2 years ago66
67class TestAsyncTranscriptions:
98d779fbStainless Bot2 years ago68parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
08b8179aDavid Schnurr2 years ago69
70@parametrize
98d779fbStainless Bot2 years ago71async def test_method_create(self, async_client: AsyncOpenAI) -> None:
72transcription = await async_client.audio.transcriptions.create(
08b8179aDavid Schnurr2 years ago73file=b"raw file contents",
74model="whisper-1",
75)
76assert_matches_type(Transcription, transcription, path=["response"])
77
78@parametrize
98d779fbStainless Bot2 years ago79async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
80transcription = await async_client.audio.transcriptions.create(
08b8179aDavid Schnurr2 years ago81file=b"raw file contents",
82model="whisper-1",
83language="string",
84prompt="string",
85response_format="json",
86temperature=0,
87)
88assert_matches_type(Transcription, transcription, path=["response"])
89
90@parametrize
98d779fbStainless Bot2 years ago91async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
92response = await async_client.audio.transcriptions.with_raw_response.create(
08b8179aDavid Schnurr2 years ago93file=b"raw file contents",
94model="whisper-1",
95)
86379b44Stainless Bot2 years ago96
97assert response.is_closed is True
08b8179aDavid Schnurr2 years ago98assert response.http_request.headers.get("X-Stainless-Lang") == "python"
99transcription = response.parse()
100assert_matches_type(Transcription, transcription, path=["response"])
86379b44Stainless Bot2 years ago101
102@parametrize
98d779fbStainless Bot2 years ago103async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
104async with async_client.audio.transcriptions.with_streaming_response.create(
86379b44Stainless Bot2 years ago105file=b"raw file contents",
106model="whisper-1",
107) as response:
108assert not response.is_closed
109assert response.http_request.headers.get("X-Stainless-Lang") == "python"
110
111transcription = await response.parse()
112assert_matches_type(Transcription, transcription, path=["response"])
113
114assert cast(Any, response.is_closed) is True