openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.3.7

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/audio/test_translations.py

85lines · 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 Translation
13
14base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
15api_key = "My API Key"
16
17
18class TestTranslations:
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 translation = client.audio.translations.create(
26 file=b"raw file contents",
27 model="whisper-1",
28 )
29 assert_matches_type(Translation, translation, path=["response"])
30
31 @parametrize
32 def test_method_create_with_all_params(self, client: OpenAI) -> None:
33 translation = client.audio.translations.create(
34 file=b"raw file contents",
35 model="whisper-1",
36 prompt="string",
37 response_format="string",
38 temperature=0,
39 )
40 assert_matches_type(Translation, translation, path=["response"])
41
42 @parametrize
43 def test_raw_response_create(self, client: OpenAI) -> None:
44 response = client.audio.translations.with_raw_response.create(
45 file=b"raw file contents",
46 model="whisper-1",
47 )
48 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
49 translation = response.parse()
50 assert_matches_type(Translation, translation, path=["response"])
51
52
53class TestAsyncTranslations:
54 strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
55 loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
56 parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
57
58 @parametrize
59 async def test_method_create(self, client: AsyncOpenAI) -> None:
60 translation = await client.audio.translations.create(
61 file=b"raw file contents",
62 model="whisper-1",
63 )
64 assert_matches_type(Translation, translation, path=["response"])
65
66 @parametrize
67 async def test_method_create_with_all_params(self, client: AsyncOpenAI) -> None:
68 translation = await client.audio.translations.create(
69 file=b"raw file contents",
70 model="whisper-1",
71 prompt="string",
72 response_format="string",
73 temperature=0,
74 )
75 assert_matches_type(Translation, translation, path=["response"])
76
77 @parametrize
78 async def test_raw_response_create(self, client: AsyncOpenAI) -> None:
79 response = await client.audio.translations.with_raw_response.create(
80 file=b"raw file contents",
81 model="whisper-1",
82 )
83 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
84 translation = response.parse()
85 assert_matches_type(Translation, translation, path=["response"])
86