openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
codex/bedrock-thin-provider-rewrite

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/realtime/test_client_secrets.py

210lines · modecode

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