Skip to content

Commit 1f3f478

Browse files
fix(client): correct types for transcriptions / translations (#1757)
1 parent 763972e commit 1f3f478

13 files changed

+228
-59
lines changed

Diff for: .stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 68
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-17ddd746c775ca4d4fbe64e5621ac30756ef09c061ff6313190b6ec162222d4c.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-71e58a77027c67e003fdd1b1ac8ac11557d8bfabc7666d1a827c6b1ca8ab98b5.yml

Diff for: api.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,30 @@ from openai.types import AudioModel, AudioResponseFormat
121121
Types:
122122

123123
```python
124-
from openai.types.audio import Transcription
124+
from openai.types.audio import (
125+
Transcription,
126+
TranscriptionSegment,
127+
TranscriptionVerbose,
128+
TranscriptionWord,
129+
TranscriptionCreateResponse,
130+
)
125131
```
126132

127133
Methods:
128134

129-
- <code title="post /audio/transcriptions">client.audio.transcriptions.<a href="./src/openai/resources/audio/transcriptions.py">create</a>(\*\*<a href="src/openai/types/audio/transcription_create_params.py">params</a>) -> <a href="./src/openai/types/audio/transcription.py">Transcription</a></code>
135+
- <code title="post /audio/transcriptions">client.audio.transcriptions.<a href="./src/openai/resources/audio/transcriptions.py">create</a>(\*\*<a href="src/openai/types/audio/transcription_create_params.py">params</a>) -> <a href="./src/openai/types/audio/transcription_create_response.py">TranscriptionCreateResponse</a></code>
130136

131137
## Translations
132138

133139
Types:
134140

135141
```python
136-
from openai.types.audio import Translation
142+
from openai.types.audio import Translation, TranslationVerbose, TranslationCreateResponse
137143
```
138144

139145
Methods:
140146

141-
- <code title="post /audio/translations">client.audio.translations.<a href="./src/openai/resources/audio/translations.py">create</a>(\*\*<a href="src/openai/types/audio/translation_create_params.py">params</a>) -> <a href="./src/openai/types/audio/translation.py">Translation</a></code>
147+
- <code title="post /audio/translations">client.audio.translations.<a href="./src/openai/resources/audio/translations.py">create</a>(\*\*<a href="src/openai/types/audio/translation_create_params.py">params</a>) -> <a href="./src/openai/types/audio/translation_create_response.py">TranslationCreateResponse</a></code>
142148

143149
## Speech
144150

Diff for: src/openai/resources/audio/transcriptions.py

+28-18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import List, Union, Mapping, cast
5+
from typing import Any, List, Union, Mapping, cast
66
from typing_extensions import Literal
77

88
import httpx
@@ -22,8 +22,8 @@
2222
from ...types.audio import transcription_create_params
2323
from ..._base_client import make_request_options
2424
from ...types.audio_model import AudioModel
25-
from ...types.audio.transcription import Transcription
2625
from ...types.audio_response_format import AudioResponseFormat
26+
from ...types.audio.transcription_create_response import TranscriptionCreateResponse
2727

2828
__all__ = ["Transcriptions", "AsyncTranscriptions"]
2929

@@ -64,7 +64,7 @@ def create(
6464
extra_query: Query | None = None,
6565
extra_body: Body | None = None,
6666
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
67-
) -> Transcription:
67+
) -> TranscriptionCreateResponse:
6868
"""
6969
Transcribes audio into the input language.
7070
@@ -124,14 +124,19 @@ def create(
124124
# sent to the server will contain a `boundary` parameter, e.g.
125125
# multipart/form-data; boundary=---abc--
126126
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
127-
return self._post(
128-
"/audio/transcriptions",
129-
body=maybe_transform(body, transcription_create_params.TranscriptionCreateParams),
130-
files=files,
131-
options=make_request_options(
132-
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
127+
return cast(
128+
TranscriptionCreateResponse,
129+
self._post(
130+
"/audio/transcriptions",
131+
body=maybe_transform(body, transcription_create_params.TranscriptionCreateParams),
132+
files=files,
133+
options=make_request_options(
134+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
135+
),
136+
cast_to=cast(
137+
Any, TranscriptionCreateResponse
138+
), # Union types cannot be passed in as arguments in the type system
133139
),
134-
cast_to=Transcription,
135140
)
136141

137142

@@ -171,7 +176,7 @@ async def create(
171176
extra_query: Query | None = None,
172177
extra_body: Body | None = None,
173178
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
174-
) -> Transcription:
179+
) -> TranscriptionCreateResponse:
175180
"""
176181
Transcribes audio into the input language.
177182
@@ -231,14 +236,19 @@ async def create(
231236
# sent to the server will contain a `boundary` parameter, e.g.
232237
# multipart/form-data; boundary=---abc--
233238
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
234-
return await self._post(
235-
"/audio/transcriptions",
236-
body=await async_maybe_transform(body, transcription_create_params.TranscriptionCreateParams),
237-
files=files,
238-
options=make_request_options(
239-
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
239+
return cast(
240+
TranscriptionCreateResponse,
241+
await self._post(
242+
"/audio/transcriptions",
243+
body=await async_maybe_transform(body, transcription_create_params.TranscriptionCreateParams),
244+
files=files,
245+
options=make_request_options(
246+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
247+
),
248+
cast_to=cast(
249+
Any, TranscriptionCreateResponse
250+
), # Union types cannot be passed in as arguments in the type system
240251
),
241-
cast_to=Transcription,
242252
)
243253

244254

Diff for: src/openai/resources/audio/translations.py

+28-18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Union, Mapping, cast
5+
from typing import Any, Union, Mapping, cast
66

77
import httpx
88

@@ -21,8 +21,8 @@
2121
from ...types.audio import translation_create_params
2222
from ..._base_client import make_request_options
2323
from ...types.audio_model import AudioModel
24-
from ...types.audio.translation import Translation
2524
from ...types.audio_response_format import AudioResponseFormat
25+
from ...types.audio.translation_create_response import TranslationCreateResponse
2626

2727
__all__ = ["Translations", "AsyncTranslations"]
2828

@@ -61,7 +61,7 @@ def create(
6161
extra_query: Query | None = None,
6262
extra_body: Body | None = None,
6363
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
64-
) -> Translation:
64+
) -> TranslationCreateResponse:
6565
"""
6666
Translates audio into English.
6767
@@ -108,14 +108,19 @@ def create(
108108
# sent to the server will contain a `boundary` parameter, e.g.
109109
# multipart/form-data; boundary=---abc--
110110
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
111-
return self._post(
112-
"/audio/translations",
113-
body=maybe_transform(body, translation_create_params.TranslationCreateParams),
114-
files=files,
115-
options=make_request_options(
116-
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
111+
return cast(
112+
TranslationCreateResponse,
113+
self._post(
114+
"/audio/translations",
115+
body=maybe_transform(body, translation_create_params.TranslationCreateParams),
116+
files=files,
117+
options=make_request_options(
118+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
119+
),
120+
cast_to=cast(
121+
Any, TranslationCreateResponse
122+
), # Union types cannot be passed in as arguments in the type system
117123
),
118-
cast_to=Translation,
119124
)
120125

121126

@@ -153,7 +158,7 @@ async def create(
153158
extra_query: Query | None = None,
154159
extra_body: Body | None = None,
155160
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
156-
) -> Translation:
161+
) -> TranslationCreateResponse:
157162
"""
158163
Translates audio into English.
159164
@@ -200,14 +205,19 @@ async def create(
200205
# sent to the server will contain a `boundary` parameter, e.g.
201206
# multipart/form-data; boundary=---abc--
202207
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
203-
return await self._post(
204-
"/audio/translations",
205-
body=await async_maybe_transform(body, translation_create_params.TranslationCreateParams),
206-
files=files,
207-
options=make_request_options(
208-
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
208+
return cast(
209+
TranslationCreateResponse,
210+
await self._post(
211+
"/audio/translations",
212+
body=await async_maybe_transform(body, translation_create_params.TranslationCreateParams),
213+
files=files,
214+
options=make_request_options(
215+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
216+
),
217+
cast_to=cast(
218+
Any, TranslationCreateResponse
219+
), # Union types cannot be passed in as arguments in the type system
209220
),
210-
cast_to=Translation,
211221
)
212222

213223

Diff for: src/openai/types/audio/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
from .translation import Translation as Translation
66
from .speech_model import SpeechModel as SpeechModel
77
from .transcription import Transcription as Transcription
8+
from .transcription_word import TranscriptionWord as TranscriptionWord
9+
from .translation_verbose import TranslationVerbose as TranslationVerbose
810
from .speech_create_params import SpeechCreateParams as SpeechCreateParams
11+
from .transcription_segment import TranscriptionSegment as TranscriptionSegment
12+
from .transcription_verbose import TranscriptionVerbose as TranscriptionVerbose
913
from .translation_create_params import TranslationCreateParams as TranslationCreateParams
1014
from .transcription_create_params import TranscriptionCreateParams as TranscriptionCreateParams
15+
from .translation_create_response import TranslationCreateResponse as TranslationCreateResponse
16+
from .transcription_create_response import TranscriptionCreateResponse as TranscriptionCreateResponse
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import Union
4+
from typing_extensions import TypeAlias
5+
6+
from .transcription import Transcription
7+
from .transcription_verbose import TranscriptionVerbose
8+
9+
__all__ = ["TranscriptionCreateResponse"]
10+
11+
TranscriptionCreateResponse: TypeAlias = Union[Transcription, TranscriptionVerbose]

Diff for: src/openai/types/audio/transcription_segment.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import List
4+
5+
from ..._models import BaseModel
6+
7+
__all__ = ["TranscriptionSegment"]
8+
9+
10+
class TranscriptionSegment(BaseModel):
11+
id: int
12+
"""Unique identifier of the segment."""
13+
14+
avg_logprob: float
15+
"""Average logprob of the segment.
16+
17+
If the value is lower than -1, consider the logprobs failed.
18+
"""
19+
20+
compression_ratio: float
21+
"""Compression ratio of the segment.
22+
23+
If the value is greater than 2.4, consider the compression failed.
24+
"""
25+
26+
end: float
27+
"""End time of the segment in seconds."""
28+
29+
no_speech_prob: float
30+
"""Probability of no speech in the segment.
31+
32+
If the value is higher than 1.0 and the `avg_logprob` is below -1, consider this
33+
segment silent.
34+
"""
35+
36+
seek: int
37+
"""Seek offset of the segment."""
38+
39+
start: float
40+
"""Start time of the segment in seconds."""
41+
42+
temperature: float
43+
"""Temperature parameter used for generating the segment."""
44+
45+
text: str
46+
"""Text content of the segment."""
47+
48+
tokens: List[int]
49+
"""Array of token IDs for the text content."""

Diff for: src/openai/types/audio/transcription_verbose.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import List, Optional
4+
5+
from ..._models import BaseModel
6+
from .transcription_word import TranscriptionWord
7+
from .transcription_segment import TranscriptionSegment
8+
9+
__all__ = ["TranscriptionVerbose"]
10+
11+
12+
class TranscriptionVerbose(BaseModel):
13+
duration: str
14+
"""The duration of the input audio."""
15+
16+
language: str
17+
"""The language of the input audio."""
18+
19+
text: str
20+
"""The transcribed text."""
21+
22+
segments: Optional[List[TranscriptionSegment]] = None
23+
"""Segments of the transcribed text and their corresponding details."""
24+
25+
words: Optional[List[TranscriptionWord]] = None
26+
"""Extracted words and their corresponding timestamps."""

Diff for: src/openai/types/audio/transcription_word.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
4+
5+
from ..._models import BaseModel
6+
7+
__all__ = ["TranscriptionWord"]
8+
9+
10+
class TranscriptionWord(BaseModel):
11+
end: float
12+
"""End time of the word in seconds."""
13+
14+
start: float
15+
"""Start time of the word in seconds."""
16+
17+
word: str
18+
"""The text content of the word."""
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import Union
4+
from typing_extensions import TypeAlias
5+
6+
from .translation import Translation
7+
from .translation_verbose import TranslationVerbose
8+
9+
__all__ = ["TranslationCreateResponse"]
10+
11+
TranslationCreateResponse: TypeAlias = Union[Translation, TranslationVerbose]

Diff for: src/openai/types/audio/translation_verbose.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import List, Optional
4+
5+
from ..._models import BaseModel
6+
from .transcription_segment import TranscriptionSegment
7+
8+
__all__ = ["TranslationVerbose"]
9+
10+
11+
class TranslationVerbose(BaseModel):
12+
duration: str
13+
"""The duration of the input audio."""
14+
15+
language: str
16+
"""The language of the output translation (always `english`)."""
17+
18+
text: str
19+
"""The translated text."""
20+
21+
segments: Optional[List[TranscriptionSegment]] = None
22+
"""Segments of the translated text and their corresponding details."""

0 commit comments

Comments
 (0)