openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.107.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/realtime/test_client_secrets.py

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