openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.92.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/realtime/test_sessions.py

166lines · modeblame

575ff607stainless-app[bot]1 years 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.beta.realtime import SessionCreateResponse
13
14base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
15
16
17class TestSessions:
18parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
19
20@parametrize
21def test_method_create(self, client: OpenAI) -> None:
339d3151stainless-app[bot]1 years ago22session = client.beta.realtime.sessions.create()
575ff607stainless-app[bot]1 years ago23assert_matches_type(SessionCreateResponse, session, path=["response"])
24
25@parametrize
26def test_method_create_with_all_params(self, client: OpenAI) -> None:
27session = client.beta.realtime.sessions.create(
cca09707stainless-app[bot]1 years ago28client_secret={
0673da62stainless-app[bot]1 years ago29"expires_after": {
cca09707stainless-app[bot]1 years ago30"anchor": "created_at",
31"seconds": 0,
32}
33},
575ff607stainless-app[bot]1 years ago34input_audio_format="pcm16",
2b4bc759stainless-app[bot]1 years ago35input_audio_noise_reduction={"type": "near_field"},
fdd52476stainless-app[bot]1 years ago36input_audio_transcription={
37"language": "language",
38"model": "model",
39"prompt": "prompt",
40},
575ff607stainless-app[bot]1 years ago41instructions="instructions",
42max_response_output_tokens=0,
43modalities=["text"],
339d3151stainless-app[bot]1 years ago44model="gpt-4o-realtime-preview",
575ff607stainless-app[bot]1 years ago45output_audio_format="pcm16",
56540b32stainless-app[bot]1 years ago46speed=0.25,
575ff607stainless-app[bot]1 years ago47temperature=0,
48tool_choice="tool_choice",
49tools=[
50{
51"description": "description",
52"name": "name",
53"parameters": {},
54"type": "function",
55}
56],
56540b32stainless-app[bot]1 years ago57tracing="auto",
575ff607stainless-app[bot]1 years ago58turn_detection={
59"create_response": True,
2b4bc759stainless-app[bot]1 years ago60"eagerness": "low",
0c62bebestainless-app[bot]1 years ago61"interrupt_response": True,
575ff607stainless-app[bot]1 years ago62"prefix_padding_ms": 0,
63"silence_duration_ms": 0,
64"threshold": 0,
2b4bc759stainless-app[bot]1 years ago65"type": "server_vad",
575ff607stainless-app[bot]1 years ago66},
2e73b529stainless-app[bot]1 years ago67voice="ash",
575ff607stainless-app[bot]1 years ago68)
69assert_matches_type(SessionCreateResponse, session, path=["response"])
70
71@parametrize
72def test_raw_response_create(self, client: OpenAI) -> None:
339d3151stainless-app[bot]1 years ago73response = client.beta.realtime.sessions.with_raw_response.create()
575ff607stainless-app[bot]1 years ago74
75assert response.is_closed is True
76assert response.http_request.headers.get("X-Stainless-Lang") == "python"
77session = response.parse()
78assert_matches_type(SessionCreateResponse, session, path=["response"])
79
80@parametrize
81def test_streaming_response_create(self, client: OpenAI) -> None:
339d3151stainless-app[bot]1 years ago82with client.beta.realtime.sessions.with_streaming_response.create() as response:
575ff607stainless-app[bot]1 years ago83assert not response.is_closed
84assert response.http_request.headers.get("X-Stainless-Lang") == "python"
85
86session = response.parse()
87assert_matches_type(SessionCreateResponse, session, path=["response"])
88
89assert cast(Any, response.is_closed) is True
90
91
92class TestAsyncSessions:
c62e9907stainless-app[bot]1 years ago93parametrize = pytest.mark.parametrize(
94"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
95)
575ff607stainless-app[bot]1 years ago96
97@parametrize
98async def test_method_create(self, async_client: AsyncOpenAI) -> None:
339d3151stainless-app[bot]1 years ago99session = await async_client.beta.realtime.sessions.create()
575ff607stainless-app[bot]1 years ago100assert_matches_type(SessionCreateResponse, session, path=["response"])
101
102@parametrize
103async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
104session = await async_client.beta.realtime.sessions.create(
cca09707stainless-app[bot]1 years ago105client_secret={
0673da62stainless-app[bot]1 years ago106"expires_after": {
cca09707stainless-app[bot]1 years ago107"anchor": "created_at",
108"seconds": 0,
109}
110},
575ff607stainless-app[bot]1 years ago111input_audio_format="pcm16",
2b4bc759stainless-app[bot]1 years ago112input_audio_noise_reduction={"type": "near_field"},
fdd52476stainless-app[bot]1 years ago113input_audio_transcription={
114"language": "language",
115"model": "model",
116"prompt": "prompt",
117},
575ff607stainless-app[bot]1 years ago118instructions="instructions",
119max_response_output_tokens=0,
120modalities=["text"],
339d3151stainless-app[bot]1 years ago121model="gpt-4o-realtime-preview",
575ff607stainless-app[bot]1 years ago122output_audio_format="pcm16",
56540b32stainless-app[bot]1 years ago123speed=0.25,
575ff607stainless-app[bot]1 years ago124temperature=0,
125tool_choice="tool_choice",
126tools=[
127{
128"description": "description",
129"name": "name",
130"parameters": {},
131"type": "function",
132}
133],
56540b32stainless-app[bot]1 years ago134tracing="auto",
575ff607stainless-app[bot]1 years ago135turn_detection={
136"create_response": True,
2b4bc759stainless-app[bot]1 years ago137"eagerness": "low",
0c62bebestainless-app[bot]1 years ago138"interrupt_response": True,
575ff607stainless-app[bot]1 years ago139"prefix_padding_ms": 0,
140"silence_duration_ms": 0,
141"threshold": 0,
2b4bc759stainless-app[bot]1 years ago142"type": "server_vad",
575ff607stainless-app[bot]1 years ago143},
2e73b529stainless-app[bot]1 years ago144voice="ash",
575ff607stainless-app[bot]1 years ago145)
146assert_matches_type(SessionCreateResponse, session, path=["response"])
147
148@parametrize
149async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
339d3151stainless-app[bot]1 years ago150response = await async_client.beta.realtime.sessions.with_raw_response.create()
575ff607stainless-app[bot]1 years ago151
152assert response.is_closed is True
153assert response.http_request.headers.get("X-Stainless-Lang") == "python"
154session = response.parse()
155assert_matches_type(SessionCreateResponse, session, path=["response"])
156
157@parametrize
158async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
339d3151stainless-app[bot]1 years ago159async with async_client.beta.realtime.sessions.with_streaming_response.create() as response:
575ff607stainless-app[bot]1 years ago160assert not response.is_closed
161assert response.http_request.headers.get("X-Stainless-Lang") == "python"
162
163session = await response.parse()
164assert_matches_type(SessionCreateResponse, session, path=["response"])
165
166assert cast(Any, response.is_closed) is True