openai/openai-python

Public

mirrored fromhttps://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.1.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/audio/test_transcriptions.py

87lines · modecode

1# File generated from our OpenAPI spec by Stainless.
2
3from __future__ import annotations
4
5import os
6
7import pytest
8
9from openai import OpenAI, AsyncOpenAI
10from tests.utils import assert_matches_type
11from openai._client import OpenAI, AsyncOpenAI
12from openai.types.audio import Transcription
13
14base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
15api_key = "My API Key"
16
17
18class TestTranscriptions:
19 strict_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
20 loose_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
21 parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
22
23 @parametrize
24 def test_method_create(self, client: OpenAI) -> None:
25 transcription = client.audio.transcriptions.create(
26 file=b"raw file contents",
27 model="whisper-1",
28 )
29 assert_matches_type(Transcription, transcription, path=["response"])
30
31 @parametrize
32 def test_method_create_with_all_params(self, client: OpenAI) -> None:
33 transcription = client.audio.transcriptions.create(
34 file=b"raw file contents",
35 model="whisper-1",
36 language="string",
37 prompt="string",
38 response_format="json",
39 temperature=0,
40 )
41 assert_matches_type(Transcription, transcription, path=["response"])
42
43 @parametrize
44 def test_raw_response_create(self, client: OpenAI) -> None:
45 response = client.audio.transcriptions.with_raw_response.create(
46 file=b"raw file contents",
47 model="whisper-1",
48 )
49 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
50 transcription = response.parse()
51 assert_matches_type(Transcription, transcription, path=["response"])
52
53
54class TestAsyncTranscriptions:
55 strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
56 loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
57 parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
58
59 @parametrize
60 async def test_method_create(self, client: AsyncOpenAI) -> None:
61 transcription = await client.audio.transcriptions.create(
62 file=b"raw file contents",
63 model="whisper-1",
64 )
65 assert_matches_type(Transcription, transcription, path=["response"])
66
67 @parametrize
68 async def test_method_create_with_all_params(self, client: AsyncOpenAI) -> None:
69 transcription = await client.audio.transcriptions.create(
70 file=b"raw file contents",
71 model="whisper-1",
72 language="string",
73 prompt="string",
74 response_format="json",
75 temperature=0,
76 )
77 assert_matches_type(Transcription, transcription, path=["response"])
78
79 @parametrize
80 async def test_raw_response_create(self, client: AsyncOpenAI) -> None:
81 response = await client.audio.transcriptions.with_raw_response.create(
82 file=b"raw file contents",
83 model="whisper-1",
84 )
85 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86 transcription = response.parse()
87 assert_matches_type(Transcription, transcription, path=["response"])
88