openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.2.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/audio/test_transcriptions.py

87lines · modeblame

08b8179aDavid Schnurr2 years ago1# 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:
19strict_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
20loose_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
21parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
22
23@parametrize
24def test_method_create(self, client: OpenAI) -> None:
25transcription = client.audio.transcriptions.create(
26file=b"raw file contents",
27model="whisper-1",
28)
29assert_matches_type(Transcription, transcription, path=["response"])
30
31@parametrize
32def test_method_create_with_all_params(self, client: OpenAI) -> None:
33transcription = client.audio.transcriptions.create(
34file=b"raw file contents",
35model="whisper-1",
36language="string",
37prompt="string",
38response_format="json",
39temperature=0,
40)
41assert_matches_type(Transcription, transcription, path=["response"])
42
43@parametrize
44def test_raw_response_create(self, client: OpenAI) -> None:
45response = client.audio.transcriptions.with_raw_response.create(
46file=b"raw file contents",
47model="whisper-1",
48)
49assert response.http_request.headers.get("X-Stainless-Lang") == "python"
50transcription = response.parse()
51assert_matches_type(Transcription, transcription, path=["response"])
52
53
54class TestAsyncTranscriptions:
55strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
56loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
57parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
58
59@parametrize
60async def test_method_create(self, client: AsyncOpenAI) -> None:
61transcription = await client.audio.transcriptions.create(
62file=b"raw file contents",
63model="whisper-1",
64)
65assert_matches_type(Transcription, transcription, path=["response"])
66
67@parametrize
68async def test_method_create_with_all_params(self, client: AsyncOpenAI) -> None:
69transcription = await client.audio.transcriptions.create(
70file=b"raw file contents",
71model="whisper-1",
72language="string",
73prompt="string",
74response_format="json",
75temperature=0,
76)
77assert_matches_type(Transcription, transcription, path=["response"])
78
79@parametrize
80async def test_raw_response_create(self, client: AsyncOpenAI) -> None:
81response = await client.audio.transcriptions.with_raw_response.create(
82file=b"raw file contents",
83model="whisper-1",
84)
85assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86transcription = response.parse()
87assert_matches_type(Transcription, transcription, path=["response"])