openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.104.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/realtime/test_client_secrets.py

208lines · modeblame

3d3d16abstainless-app[bot]9 months ago1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
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.realtime import ClientSecretCreateResponse
13
14base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
15
16
17class TestClientSecrets:
18parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
19
20@parametrize
21def test_method_create(self, client: OpenAI) -> None:
22client_secret = client.realtime.client_secrets.create()
23assert_matches_type(ClientSecretCreateResponse, client_secret, path=["response"])
24
25@parametrize
26def test_method_create_with_all_params(self, client: OpenAI) -> None:
27client_secret = client.realtime.client_secrets.create(
28expires_after={
29"anchor": "created_at",
30"seconds": 10,
31},
32session={
33"model": "string",
34"type": "realtime",
35"audio": {
36"input": {
37"format": "pcm16",
38"noise_reduction": {"type": "near_field"},
39"transcription": {
40"language": "language",
41"model": "whisper-1",
42"prompt": "prompt",
43},
44"turn_detection": {
45"create_response": True,
46"eagerness": "low",
47"idle_timeout_ms": 0,
48"interrupt_response": True,
49"prefix_padding_ms": 0,
50"silence_duration_ms": 0,
51"threshold": 0,
52"type": "server_vad",
53},
54},
55"output": {
56"format": "pcm16",
57"speed": 0.25,
58"voice": "ash",
59},
60},
61"client_secret": {
62"expires_after": {
63"anchor": "created_at",
64"seconds": 0,
65}
66},
67"include": ["item.input_audio_transcription.logprobs"],
68"instructions": "instructions",
69"max_output_tokens": 0,
70"output_modalities": ["text"],
71"prompt": {
72"id": "id",
73"variables": {"foo": "string"},
74"version": "version",
75},
76"temperature": 0,
77"tool_choice": "none",
78"tools": [
79{
80"description": "description",
81"name": "name",
82"parameters": {},
83"type": "function",
84}
85],
86"tracing": "auto",
87"truncation": "auto",
88},
89)
90assert_matches_type(ClientSecretCreateResponse, client_secret, path=["response"])
91
92@parametrize
93def test_raw_response_create(self, client: OpenAI) -> None:
94response = client.realtime.client_secrets.with_raw_response.create()
95
96assert response.is_closed is True
97assert response.http_request.headers.get("X-Stainless-Lang") == "python"
98client_secret = response.parse()
99assert_matches_type(ClientSecretCreateResponse, client_secret, path=["response"])
100
101@parametrize
102def test_streaming_response_create(self, client: OpenAI) -> None:
103with client.realtime.client_secrets.with_streaming_response.create() as response:
104assert not response.is_closed
105assert response.http_request.headers.get("X-Stainless-Lang") == "python"
106
107client_secret = response.parse()
108assert_matches_type(ClientSecretCreateResponse, client_secret, path=["response"])
109
110assert cast(Any, response.is_closed) is True
111
112
113class TestAsyncClientSecrets:
114parametrize = pytest.mark.parametrize(
115"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
116)
117
118@parametrize
119async def test_method_create(self, async_client: AsyncOpenAI) -> None:
120client_secret = await async_client.realtime.client_secrets.create()
121assert_matches_type(ClientSecretCreateResponse, client_secret, path=["response"])
122
123@parametrize
124async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
125client_secret = await async_client.realtime.client_secrets.create(
126expires_after={
127"anchor": "created_at",
128"seconds": 10,
129},
130session={
131"model": "string",
132"type": "realtime",
133"audio": {
134"input": {
135"format": "pcm16",
136"noise_reduction": {"type": "near_field"},
137"transcription": {
138"language": "language",
139"model": "whisper-1",
140"prompt": "prompt",
141},
142"turn_detection": {
143"create_response": True,
144"eagerness": "low",
145"idle_timeout_ms": 0,
146"interrupt_response": True,
147"prefix_padding_ms": 0,
148"silence_duration_ms": 0,
149"threshold": 0,
150"type": "server_vad",
151},
152},
153"output": {
154"format": "pcm16",
155"speed": 0.25,
156"voice": "ash",
157},
158},
159"client_secret": {
160"expires_after": {
161"anchor": "created_at",
162"seconds": 0,
163}
164},
165"include": ["item.input_audio_transcription.logprobs"],
166"instructions": "instructions",
167"max_output_tokens": 0,
168"output_modalities": ["text"],
169"prompt": {
170"id": "id",
171"variables": {"foo": "string"},
172"version": "version",
173},
174"temperature": 0,
175"tool_choice": "none",
176"tools": [
177{
178"description": "description",
179"name": "name",
180"parameters": {},
181"type": "function",
182}
183],
184"tracing": "auto",
185"truncation": "auto",
186},
187)
188assert_matches_type(ClientSecretCreateResponse, client_secret, path=["response"])
189
190@parametrize
191async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
192response = await async_client.realtime.client_secrets.with_raw_response.create()
193
194assert response.is_closed is True
195assert response.http_request.headers.get("X-Stainless-Lang") == "python"
196client_secret = response.parse()
197assert_matches_type(ClientSecretCreateResponse, client_secret, path=["response"])
198
199@parametrize
200async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
201async with async_client.realtime.client_secrets.with_streaming_response.create() as response:
202assert not response.is_closed
203assert response.http_request.headers.get("X-Stainless-Lang") == "python"
204
205client_secret = await response.parse()
206assert_matches_type(ClientSecretCreateResponse, client_secret, path=["response"])
207
208assert cast(Any, response.is_closed) is True