openai/openai-python

Public

mirrored fromhttps://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 · modecode

1# File generated from our OpenAPI spec by Stainless.
2
3from __future__ import annotations
4
5import os
6from typing import Any, cast
7
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:
18 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
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 )
46
47 assert response.is_closed is True
48 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
49 transcription = response.parse()
50 assert_matches_type(Transcription, transcription, path=["response"])
51
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
66
67class TestAsyncTranscriptions:
68 parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
69
70 @parametrize
71 async def test_method_create(self, async_client: AsyncOpenAI) -> None:
72 transcription = await async_client.audio.transcriptions.create(
73 file=b"raw file contents",
74 model="whisper-1",
75 )
76 assert_matches_type(Transcription, transcription, path=["response"])
77
78 @parametrize
79 async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
80 transcription = await async_client.audio.transcriptions.create(
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
91 async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
92 response = await async_client.audio.transcriptions.with_raw_response.create(
93 file=b"raw file contents",
94 model="whisper-1",
95 )
96
97 assert response.is_closed is True
98 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
99 transcription = response.parse()
100 assert_matches_type(Transcription, transcription, path=["response"])
101
102 @parametrize
103 async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
104 async with async_client.audio.transcriptions.with_streaming_response.create(
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
115