openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.8.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/audio/test_transcriptions.py

120lines · 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._client import OpenAI, AsyncOpenAI
13from openai.types.audio import Transcription
14
15base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
16api_key = "My API Key"
17
18
19class TestTranscriptions:
20 strict_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
21 loose_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
22 parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
23
24 @parametrize
25 def test_method_create(self, client: OpenAI) -> None:
26 transcription = client.audio.transcriptions.create(
27 file=b"raw file contents",
28 model="whisper-1",
29 )
30 assert_matches_type(Transcription, transcription, path=["response"])
31
32 @parametrize
33 def test_method_create_with_all_params(self, client: OpenAI) -> None:
34 transcription = client.audio.transcriptions.create(
35 file=b"raw file contents",
36 model="whisper-1",
37 language="string",
38 prompt="string",
39 response_format="json",
40 temperature=0,
41 )
42 assert_matches_type(Transcription, transcription, path=["response"])
43
44 @parametrize
45 def test_raw_response_create(self, client: OpenAI) -> None:
46 response = client.audio.transcriptions.with_raw_response.create(
47 file=b"raw file contents",
48 model="whisper-1",
49 )
50
51 assert response.is_closed is True
52 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
53 transcription = response.parse()
54 assert_matches_type(Transcription, transcription, path=["response"])
55
56 @parametrize
57 def test_streaming_response_create(self, client: OpenAI) -> None:
58 with client.audio.transcriptions.with_streaming_response.create(
59 file=b"raw file contents",
60 model="whisper-1",
61 ) as response:
62 assert not response.is_closed
63 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
64
65 transcription = response.parse()
66 assert_matches_type(Transcription, transcription, path=["response"])
67
68 assert cast(Any, response.is_closed) is True
69
70
71class TestAsyncTranscriptions:
72 strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
73 loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
74 parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
75
76 @parametrize
77 async def test_method_create(self, client: AsyncOpenAI) -> None:
78 transcription = await client.audio.transcriptions.create(
79 file=b"raw file contents",
80 model="whisper-1",
81 )
82 assert_matches_type(Transcription, transcription, path=["response"])
83
84 @parametrize
85 async def test_method_create_with_all_params(self, client: AsyncOpenAI) -> None:
86 transcription = await client.audio.transcriptions.create(
87 file=b"raw file contents",
88 model="whisper-1",
89 language="string",
90 prompt="string",
91 response_format="json",
92 temperature=0,
93 )
94 assert_matches_type(Transcription, transcription, path=["response"])
95
96 @parametrize
97 async def test_raw_response_create(self, client: AsyncOpenAI) -> None:
98 response = await client.audio.transcriptions.with_raw_response.create(
99 file=b"raw file contents",
100 model="whisper-1",
101 )
102
103 assert response.is_closed is True
104 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
105 transcription = response.parse()
106 assert_matches_type(Transcription, transcription, path=["response"])
107
108 @parametrize
109 async def test_streaming_response_create(self, client: AsyncOpenAI) -> None:
110 async with client.audio.transcriptions.with_streaming_response.create(
111 file=b"raw file contents",
112 model="whisper-1",
113 ) as response:
114 assert not response.is_closed
115 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
116
117 transcription = await response.parse()
118 assert_matches_type(Transcription, transcription, path=["response"])
119
120 assert cast(Any, response.is_closed) is True