openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v2.38.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

210lines · 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"type": "realtime",
34"audio": {
35"input": {
0296375fstainless-app[bot]9 months ago36"format": {
37"rate": 24000,
38"type": "audio/pcm",
39},
3d3d16abstainless-app[bot]9 months ago40"noise_reduction": {"type": "near_field"},
41"transcription": {
8fe0ab87stainless-app[bot]1 months ago42"delay": "minimal",
3d3d16abstainless-app[bot]9 months ago43"language": "language",
e507a4ebstainless-app[bot]2 months ago44"model": "whisper-1",
3d3d16abstainless-app[bot]9 months ago45"prompt": "prompt",
46},
47"turn_detection": {
4756247cstainless-app[bot]9 months ago48"type": "server_vad",
3d3d16abstainless-app[bot]9 months ago49"create_response": True,
4756247cstainless-app[bot]9 months ago50"idle_timeout_ms": 5000,
3d3d16abstainless-app[bot]9 months ago51"interrupt_response": True,
52"prefix_padding_ms": 0,
53"silence_duration_ms": 0,
54"threshold": 0,
55},
56},
57"output": {
0296375fstainless-app[bot]9 months ago58"format": {
59"rate": 24000,
60"type": "audio/pcm",
61},
3d3d16abstainless-app[bot]9 months ago62"speed": 0.25,
e507a4ebstainless-app[bot]2 months ago63"voice": "alloy",
3d3d16abstainless-app[bot]9 months ago64},
65},
66"include": ["item.input_audio_transcription.logprobs"],
67"instructions": "instructions",
e507a4ebstainless-app[bot]2 months ago68"max_output_tokens": "inf",
69"model": "gpt-realtime",
3d3d16abstainless-app[bot]9 months ago70"output_modalities": ["text"],
8fe0ab87stainless-app[bot]1 months ago71"parallel_tool_calls": True,
3d3d16abstainless-app[bot]9 months ago72"prompt": {
73"id": "id",
74"variables": {"foo": "string"},
75"version": "version",
76},
8fe0ab87stainless-app[bot]1 months ago77"reasoning": {"effort": "minimal"},
3d3d16abstainless-app[bot]9 months ago78"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)
91assert_matches_type(ClientSecretCreateResponse, client_secret, path=["response"])
92
93@parametrize
94def test_raw_response_create(self, client: OpenAI) -> None:
95response = client.realtime.client_secrets.with_raw_response.create()
96
97assert response.is_closed is True
98assert response.http_request.headers.get("X-Stainless-Lang") == "python"
99client_secret = response.parse()
100assert_matches_type(ClientSecretCreateResponse, client_secret, path=["response"])
101
102@parametrize
103def test_streaming_response_create(self, client: OpenAI) -> None:
104with client.realtime.client_secrets.with_streaming_response.create() as response:
105assert not response.is_closed
106assert response.http_request.headers.get("X-Stainless-Lang") == "python"
107
108client_secret = response.parse()
109assert_matches_type(ClientSecretCreateResponse, client_secret, path=["response"])
110
111assert cast(Any, response.is_closed) is True
112
113
114class TestAsyncClientSecrets:
115parametrize = pytest.mark.parametrize(
116"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
117)
118
119@parametrize
120async def test_method_create(self, async_client: AsyncOpenAI) -> None:
121client_secret = await async_client.realtime.client_secrets.create()
122assert_matches_type(ClientSecretCreateResponse, client_secret, path=["response"])
123
124@parametrize
125async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
126client_secret = await async_client.realtime.client_secrets.create(
127expires_after={
128"anchor": "created_at",
129"seconds": 10,
130},
131session={
132"type": "realtime",
133"audio": {
134"input": {
0296375fstainless-app[bot]9 months ago135"format": {
136"rate": 24000,
137"type": "audio/pcm",
138},
3d3d16abstainless-app[bot]9 months ago139"noise_reduction": {"type": "near_field"},
140"transcription": {
8fe0ab87stainless-app[bot]1 months ago141"delay": "minimal",
3d3d16abstainless-app[bot]9 months ago142"language": "language",
e507a4ebstainless-app[bot]2 months ago143"model": "whisper-1",
3d3d16abstainless-app[bot]9 months ago144"prompt": "prompt",
145},
146"turn_detection": {
4756247cstainless-app[bot]9 months ago147"type": "server_vad",
3d3d16abstainless-app[bot]9 months ago148"create_response": True,
4756247cstainless-app[bot]9 months ago149"idle_timeout_ms": 5000,
3d3d16abstainless-app[bot]9 months ago150"interrupt_response": True,
151"prefix_padding_ms": 0,
152"silence_duration_ms": 0,
153"threshold": 0,
154},
155},
156"output": {
0296375fstainless-app[bot]9 months ago157"format": {
158"rate": 24000,
159"type": "audio/pcm",
160},
3d3d16abstainless-app[bot]9 months ago161"speed": 0.25,
e507a4ebstainless-app[bot]2 months ago162"voice": "alloy",
3d3d16abstainless-app[bot]9 months ago163},
164},
165"include": ["item.input_audio_transcription.logprobs"],
166"instructions": "instructions",
e507a4ebstainless-app[bot]2 months ago167"max_output_tokens": "inf",
168"model": "gpt-realtime",
3d3d16abstainless-app[bot]9 months ago169"output_modalities": ["text"],
8fe0ab87stainless-app[bot]1 months ago170"parallel_tool_calls": True,
3d3d16abstainless-app[bot]9 months ago171"prompt": {
172"id": "id",
173"variables": {"foo": "string"},
174"version": "version",
175},
8fe0ab87stainless-app[bot]1 months ago176"reasoning": {"effort": "minimal"},
3d3d16abstainless-app[bot]9 months ago177"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)
190assert_matches_type(ClientSecretCreateResponse, client_secret, path=["response"])
191
192@parametrize
193async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
194response = await async_client.realtime.client_secrets.with_raw_response.create()
195
196assert response.is_closed is True
197assert response.http_request.headers.get("X-Stainless-Lang") == "python"
198client_secret = response.parse()
199assert_matches_type(ClientSecretCreateResponse, client_secret, path=["response"])
200
201@parametrize
202async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
203async with async_client.realtime.client_secrets.with_streaming_response.create() as response:
204assert not response.is_closed
205assert response.http_request.headers.get("X-Stainless-Lang") == "python"
206
207client_secret = await response.parse()
208assert_matches_type(ClientSecretCreateResponse, client_secret, path=["response"])
209
210assert cast(Any, response.is_closed) is True