mistralai 1.9.2__py3-none-any.whl → 1.9.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mistralai/_version.py +2 -2
- mistralai/accesses.py +2 -0
- mistralai/audio.py +18 -0
- mistralai/beta.py +1 -1
- mistralai/conversations.py +2 -2
- mistralai/documents.py +2 -0
- mistralai/libraries.py +3 -1
- mistralai/mistral_jobs.py +14 -2
- mistralai/models/__init__.py +125 -2
- mistralai/models/audiochunk.py +20 -0
- mistralai/models/audiotranscriptionrequest.py +97 -0
- mistralai/models/audiotranscriptionrequeststream.py +97 -0
- mistralai/models/basemodelcard.py +3 -3
- mistralai/models/batchjobin.py +7 -4
- mistralai/models/batchjobout.py +10 -3
- mistralai/models/classifierftmodelout.py +6 -0
- mistralai/models/completionargs.py +3 -2
- mistralai/models/completionftmodelout.py +6 -0
- mistralai/models/contentchunk.py +6 -0
- mistralai/models/fileschema.py +8 -2
- mistralai/models/jobs_api_routes_batch_get_batch_jobsop.py +8 -1
- mistralai/models/messageoutputcontentchunks.py +8 -1
- mistralai/models/outputcontentchunks.py +8 -1
- mistralai/models/retrievefileout.py +8 -2
- mistralai/models/thinkchunk.py +35 -0
- mistralai/models/timestampgranularity.py +7 -0
- mistralai/models/transcriptionresponse.py +79 -0
- mistralai/models/transcriptionsegmentchunk.py +41 -0
- mistralai/models/transcriptionstreamdone.py +85 -0
- mistralai/models/transcriptionstreamevents.py +58 -0
- mistralai/models/transcriptionstreameventtypes.py +12 -0
- mistralai/models/transcriptionstreamlanguage.py +35 -0
- mistralai/models/transcriptionstreamsegmentdelta.py +41 -0
- mistralai/models/transcriptionstreamtextdelta.py +35 -0
- mistralai/models/uploadfileout.py +8 -2
- mistralai/models/usageinfo.py +65 -8
- mistralai/sdk.py +3 -0
- mistralai/transcriptions.py +480 -0
- {mistralai-1.9.2.dist-info → mistralai-1.9.6.dist-info}/METADATA +11 -1
- {mistralai-1.9.2.dist-info → mistralai-1.9.6.dist-info}/RECORD +42 -28
- mistralai/version.py +0 -7
- {mistralai-1.9.2.dist-info → mistralai-1.9.6.dist-info}/LICENSE +0 -0
- {mistralai-1.9.2.dist-info → mistralai-1.9.6.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from mistralai.types import BaseModel
|
|
5
|
+
import pydantic
|
|
6
|
+
from pydantic import ConfigDict
|
|
7
|
+
from typing import Any, Dict, Literal, Optional
|
|
8
|
+
from typing_extensions import NotRequired, TypedDict
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
TranscriptionStreamSegmentDeltaType = Literal["transcription.segment"]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TranscriptionStreamSegmentDeltaTypedDict(TypedDict):
|
|
15
|
+
text: str
|
|
16
|
+
start: float
|
|
17
|
+
end: float
|
|
18
|
+
type: NotRequired[TranscriptionStreamSegmentDeltaType]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class TranscriptionStreamSegmentDelta(BaseModel):
|
|
22
|
+
model_config = ConfigDict(
|
|
23
|
+
populate_by_name=True, arbitrary_types_allowed=True, extra="allow"
|
|
24
|
+
)
|
|
25
|
+
__pydantic_extra__: Dict[str, Any] = pydantic.Field(init=False)
|
|
26
|
+
|
|
27
|
+
text: str
|
|
28
|
+
|
|
29
|
+
start: float
|
|
30
|
+
|
|
31
|
+
end: float
|
|
32
|
+
|
|
33
|
+
type: Optional[TranscriptionStreamSegmentDeltaType] = "transcription.segment"
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def additional_properties(self):
|
|
37
|
+
return self.__pydantic_extra__
|
|
38
|
+
|
|
39
|
+
@additional_properties.setter
|
|
40
|
+
def additional_properties(self, value):
|
|
41
|
+
self.__pydantic_extra__ = value # pyright: ignore[reportIncompatibleVariableOverride]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from mistralai.types import BaseModel
|
|
5
|
+
import pydantic
|
|
6
|
+
from pydantic import ConfigDict
|
|
7
|
+
from typing import Any, Dict, Literal, Optional
|
|
8
|
+
from typing_extensions import NotRequired, TypedDict
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
TranscriptionStreamTextDeltaType = Literal["transcription.text.delta"]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TranscriptionStreamTextDeltaTypedDict(TypedDict):
|
|
15
|
+
text: str
|
|
16
|
+
type: NotRequired[TranscriptionStreamTextDeltaType]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TranscriptionStreamTextDelta(BaseModel):
|
|
20
|
+
model_config = ConfigDict(
|
|
21
|
+
populate_by_name=True, arbitrary_types_allowed=True, extra="allow"
|
|
22
|
+
)
|
|
23
|
+
__pydantic_extra__: Dict[str, Any] = pydantic.Field(init=False)
|
|
24
|
+
|
|
25
|
+
text: str
|
|
26
|
+
|
|
27
|
+
type: Optional[TranscriptionStreamTextDeltaType] = "transcription.text.delta"
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def additional_properties(self):
|
|
31
|
+
return self.__pydantic_extra__
|
|
32
|
+
|
|
33
|
+
@additional_properties.setter
|
|
34
|
+
def additional_properties(self, value):
|
|
35
|
+
self.__pydantic_extra__ = value # pyright: ignore[reportIncompatibleVariableOverride]
|
|
@@ -27,6 +27,8 @@ class UploadFileOutTypedDict(TypedDict):
|
|
|
27
27
|
sample_type: SampleType
|
|
28
28
|
source: Source
|
|
29
29
|
num_lines: NotRequired[Nullable[int]]
|
|
30
|
+
mimetype: NotRequired[Nullable[str]]
|
|
31
|
+
signature: NotRequired[Nullable[str]]
|
|
30
32
|
|
|
31
33
|
|
|
32
34
|
class UploadFileOut(BaseModel):
|
|
@@ -53,10 +55,14 @@ class UploadFileOut(BaseModel):
|
|
|
53
55
|
|
|
54
56
|
num_lines: OptionalNullable[int] = UNSET
|
|
55
57
|
|
|
58
|
+
mimetype: OptionalNullable[str] = UNSET
|
|
59
|
+
|
|
60
|
+
signature: OptionalNullable[str] = UNSET
|
|
61
|
+
|
|
56
62
|
@model_serializer(mode="wrap")
|
|
57
63
|
def serialize_model(self, handler):
|
|
58
|
-
optional_fields = ["num_lines"]
|
|
59
|
-
nullable_fields = ["num_lines"]
|
|
64
|
+
optional_fields = ["num_lines", "mimetype", "signature"]
|
|
65
|
+
nullable_fields = ["num_lines", "mimetype", "signature"]
|
|
60
66
|
null_default_fields = []
|
|
61
67
|
|
|
62
68
|
serialized = handler(self)
|
mistralai/models/usageinfo.py
CHANGED
|
@@ -1,19 +1,76 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
|
-
from mistralai.types import BaseModel
|
|
5
|
-
|
|
4
|
+
from mistralai.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
|
|
5
|
+
import pydantic
|
|
6
|
+
from pydantic import ConfigDict, model_serializer
|
|
7
|
+
from typing import Any, Dict, Optional
|
|
8
|
+
from typing_extensions import NotRequired, TypedDict
|
|
6
9
|
|
|
7
10
|
|
|
8
11
|
class UsageInfoTypedDict(TypedDict):
|
|
9
|
-
prompt_tokens: int
|
|
10
|
-
completion_tokens: int
|
|
11
|
-
total_tokens: int
|
|
12
|
+
prompt_tokens: NotRequired[int]
|
|
13
|
+
completion_tokens: NotRequired[int]
|
|
14
|
+
total_tokens: NotRequired[int]
|
|
15
|
+
prompt_audio_seconds: NotRequired[Nullable[int]]
|
|
12
16
|
|
|
13
17
|
|
|
14
18
|
class UsageInfo(BaseModel):
|
|
15
|
-
|
|
19
|
+
model_config = ConfigDict(
|
|
20
|
+
populate_by_name=True, arbitrary_types_allowed=True, extra="allow"
|
|
21
|
+
)
|
|
22
|
+
__pydantic_extra__: Dict[str, Any] = pydantic.Field(init=False)
|
|
16
23
|
|
|
17
|
-
|
|
24
|
+
prompt_tokens: Optional[int] = 0
|
|
18
25
|
|
|
19
|
-
|
|
26
|
+
completion_tokens: Optional[int] = 0
|
|
27
|
+
|
|
28
|
+
total_tokens: Optional[int] = 0
|
|
29
|
+
|
|
30
|
+
prompt_audio_seconds: OptionalNullable[int] = UNSET
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def additional_properties(self):
|
|
34
|
+
return self.__pydantic_extra__
|
|
35
|
+
|
|
36
|
+
@additional_properties.setter
|
|
37
|
+
def additional_properties(self, value):
|
|
38
|
+
self.__pydantic_extra__ = value # pyright: ignore[reportIncompatibleVariableOverride]
|
|
39
|
+
|
|
40
|
+
@model_serializer(mode="wrap")
|
|
41
|
+
def serialize_model(self, handler):
|
|
42
|
+
optional_fields = [
|
|
43
|
+
"prompt_tokens",
|
|
44
|
+
"completion_tokens",
|
|
45
|
+
"total_tokens",
|
|
46
|
+
"prompt_audio_seconds",
|
|
47
|
+
]
|
|
48
|
+
nullable_fields = ["prompt_audio_seconds"]
|
|
49
|
+
null_default_fields = []
|
|
50
|
+
|
|
51
|
+
serialized = handler(self)
|
|
52
|
+
|
|
53
|
+
m = {}
|
|
54
|
+
|
|
55
|
+
for n, f in type(self).model_fields.items():
|
|
56
|
+
k = f.alias or n
|
|
57
|
+
val = serialized.get(k)
|
|
58
|
+
serialized.pop(k, None)
|
|
59
|
+
|
|
60
|
+
optional_nullable = k in optional_fields and k in nullable_fields
|
|
61
|
+
is_set = (
|
|
62
|
+
self.__pydantic_fields_set__.intersection({n})
|
|
63
|
+
or k in null_default_fields
|
|
64
|
+
) # pylint: disable=no-member
|
|
65
|
+
|
|
66
|
+
if val is not None and val != UNSET_SENTINEL:
|
|
67
|
+
m[k] = val
|
|
68
|
+
elif val != UNSET_SENTINEL and (
|
|
69
|
+
not k in optional_fields or (optional_nullable and is_set)
|
|
70
|
+
):
|
|
71
|
+
m[k] = val
|
|
72
|
+
|
|
73
|
+
for k, v in serialized.items():
|
|
74
|
+
m[k] = v
|
|
75
|
+
|
|
76
|
+
return m
|
mistralai/sdk.py
CHANGED
|
@@ -15,6 +15,7 @@ import weakref
|
|
|
15
15
|
|
|
16
16
|
if TYPE_CHECKING:
|
|
17
17
|
from mistralai.agents import Agents
|
|
18
|
+
from mistralai.audio import Audio
|
|
18
19
|
from mistralai.batch import Batch
|
|
19
20
|
from mistralai.beta import Beta
|
|
20
21
|
from mistralai.chat import Chat
|
|
@@ -49,6 +50,7 @@ class Mistral(BaseSDK):
|
|
|
49
50
|
r"""Classifiers API."""
|
|
50
51
|
ocr: "Ocr"
|
|
51
52
|
r"""OCR API"""
|
|
53
|
+
audio: "Audio"
|
|
52
54
|
_sub_sdk_map = {
|
|
53
55
|
"models": ("mistralai.models_", "Models"),
|
|
54
56
|
"beta": ("mistralai.beta", "Beta"),
|
|
@@ -61,6 +63,7 @@ class Mistral(BaseSDK):
|
|
|
61
63
|
"embeddings": ("mistralai.embeddings", "Embeddings"),
|
|
62
64
|
"classifiers": ("mistralai.classifiers", "Classifiers"),
|
|
63
65
|
"ocr": ("mistralai.ocr", "Ocr"),
|
|
66
|
+
"audio": ("mistralai.audio", "Audio"),
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
def __init__(
|
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from .basesdk import BaseSDK
|
|
4
|
+
from mistralai import models, utils
|
|
5
|
+
from mistralai._hooks import HookContext
|
|
6
|
+
from mistralai.types import OptionalNullable, UNSET
|
|
7
|
+
from mistralai.utils import eventstreaming, get_security_from_env
|
|
8
|
+
from typing import List, Mapping, Optional, Union
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Transcriptions(BaseSDK):
|
|
12
|
+
r"""API for audio transcription."""
|
|
13
|
+
|
|
14
|
+
def complete(
|
|
15
|
+
self,
|
|
16
|
+
*,
|
|
17
|
+
model: str,
|
|
18
|
+
file: Optional[Union[models.File, models.FileTypedDict]] = None,
|
|
19
|
+
file_url: OptionalNullable[str] = UNSET,
|
|
20
|
+
file_id: OptionalNullable[str] = UNSET,
|
|
21
|
+
language: OptionalNullable[str] = UNSET,
|
|
22
|
+
temperature: OptionalNullable[float] = UNSET,
|
|
23
|
+
timestamp_granularities: Optional[List[models.TimestampGranularity]] = None,
|
|
24
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
25
|
+
server_url: Optional[str] = None,
|
|
26
|
+
timeout_ms: Optional[int] = None,
|
|
27
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
28
|
+
) -> models.TranscriptionResponse:
|
|
29
|
+
r"""Create Transcription
|
|
30
|
+
|
|
31
|
+
:param model:
|
|
32
|
+
:param file:
|
|
33
|
+
:param file_url: Url of a file to be transcribed
|
|
34
|
+
:param file_id: ID of a file uploaded to /v1/files
|
|
35
|
+
:param language: Language of the audio, e.g. 'en'. Providing the language can boost accuracy.
|
|
36
|
+
:param temperature:
|
|
37
|
+
:param timestamp_granularities: Granularities of timestamps to include in the response.
|
|
38
|
+
:param retries: Override the default retry configuration for this method
|
|
39
|
+
:param server_url: Override the default server URL for this method
|
|
40
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
41
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
42
|
+
"""
|
|
43
|
+
base_url = None
|
|
44
|
+
url_variables = None
|
|
45
|
+
if timeout_ms is None:
|
|
46
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
47
|
+
|
|
48
|
+
if server_url is not None:
|
|
49
|
+
base_url = server_url
|
|
50
|
+
else:
|
|
51
|
+
base_url = self._get_url(base_url, url_variables)
|
|
52
|
+
|
|
53
|
+
request = models.AudioTranscriptionRequest(
|
|
54
|
+
model=model,
|
|
55
|
+
file=utils.get_pydantic_model(file, Optional[models.File]),
|
|
56
|
+
file_url=file_url,
|
|
57
|
+
file_id=file_id,
|
|
58
|
+
language=language,
|
|
59
|
+
temperature=temperature,
|
|
60
|
+
timestamp_granularities=timestamp_granularities,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
req = self._build_request(
|
|
64
|
+
method="POST",
|
|
65
|
+
path="/v1/audio/transcriptions",
|
|
66
|
+
base_url=base_url,
|
|
67
|
+
url_variables=url_variables,
|
|
68
|
+
request=request,
|
|
69
|
+
request_body_required=True,
|
|
70
|
+
request_has_path_params=False,
|
|
71
|
+
request_has_query_params=True,
|
|
72
|
+
user_agent_header="user-agent",
|
|
73
|
+
accept_header_value="application/json",
|
|
74
|
+
http_headers=http_headers,
|
|
75
|
+
security=self.sdk_configuration.security,
|
|
76
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
77
|
+
request, False, False, "multipart", models.AudioTranscriptionRequest
|
|
78
|
+
),
|
|
79
|
+
timeout_ms=timeout_ms,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
if retries == UNSET:
|
|
83
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
84
|
+
retries = self.sdk_configuration.retry_config
|
|
85
|
+
|
|
86
|
+
retry_config = None
|
|
87
|
+
if isinstance(retries, utils.RetryConfig):
|
|
88
|
+
retry_config = (retries, ["429", "500", "502", "503", "504"])
|
|
89
|
+
|
|
90
|
+
http_res = self.do_request(
|
|
91
|
+
hook_ctx=HookContext(
|
|
92
|
+
config=self.sdk_configuration,
|
|
93
|
+
base_url=base_url or "",
|
|
94
|
+
operation_id="audio_api_v1_transcriptions_post",
|
|
95
|
+
oauth2_scopes=[],
|
|
96
|
+
security_source=get_security_from_env(
|
|
97
|
+
self.sdk_configuration.security, models.Security
|
|
98
|
+
),
|
|
99
|
+
),
|
|
100
|
+
request=req,
|
|
101
|
+
error_status_codes=["4XX", "5XX"],
|
|
102
|
+
retry_config=retry_config,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
106
|
+
return utils.unmarshal_json(http_res.text, models.TranscriptionResponse)
|
|
107
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
108
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
109
|
+
raise models.SDKError(
|
|
110
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
111
|
+
)
|
|
112
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
113
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
114
|
+
raise models.SDKError(
|
|
115
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
content_type = http_res.headers.get("Content-Type")
|
|
119
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
120
|
+
raise models.SDKError(
|
|
121
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
122
|
+
http_res.status_code,
|
|
123
|
+
http_res_text,
|
|
124
|
+
http_res,
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
async def complete_async(
|
|
128
|
+
self,
|
|
129
|
+
*,
|
|
130
|
+
model: str,
|
|
131
|
+
file: Optional[Union[models.File, models.FileTypedDict]] = None,
|
|
132
|
+
file_url: OptionalNullable[str] = UNSET,
|
|
133
|
+
file_id: OptionalNullable[str] = UNSET,
|
|
134
|
+
language: OptionalNullable[str] = UNSET,
|
|
135
|
+
temperature: OptionalNullable[float] = UNSET,
|
|
136
|
+
timestamp_granularities: Optional[List[models.TimestampGranularity]] = None,
|
|
137
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
138
|
+
server_url: Optional[str] = None,
|
|
139
|
+
timeout_ms: Optional[int] = None,
|
|
140
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
141
|
+
) -> models.TranscriptionResponse:
|
|
142
|
+
r"""Create Transcription
|
|
143
|
+
|
|
144
|
+
:param model:
|
|
145
|
+
:param file:
|
|
146
|
+
:param file_url: Url of a file to be transcribed
|
|
147
|
+
:param file_id: ID of a file uploaded to /v1/files
|
|
148
|
+
:param language: Language of the audio, e.g. 'en'. Providing the language can boost accuracy.
|
|
149
|
+
:param temperature:
|
|
150
|
+
:param timestamp_granularities: Granularities of timestamps to include in the response.
|
|
151
|
+
:param retries: Override the default retry configuration for this method
|
|
152
|
+
:param server_url: Override the default server URL for this method
|
|
153
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
154
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
155
|
+
"""
|
|
156
|
+
base_url = None
|
|
157
|
+
url_variables = None
|
|
158
|
+
if timeout_ms is None:
|
|
159
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
160
|
+
|
|
161
|
+
if server_url is not None:
|
|
162
|
+
base_url = server_url
|
|
163
|
+
else:
|
|
164
|
+
base_url = self._get_url(base_url, url_variables)
|
|
165
|
+
|
|
166
|
+
request = models.AudioTranscriptionRequest(
|
|
167
|
+
model=model,
|
|
168
|
+
file=utils.get_pydantic_model(file, Optional[models.File]),
|
|
169
|
+
file_url=file_url,
|
|
170
|
+
file_id=file_id,
|
|
171
|
+
language=language,
|
|
172
|
+
temperature=temperature,
|
|
173
|
+
timestamp_granularities=timestamp_granularities,
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
req = self._build_request_async(
|
|
177
|
+
method="POST",
|
|
178
|
+
path="/v1/audio/transcriptions",
|
|
179
|
+
base_url=base_url,
|
|
180
|
+
url_variables=url_variables,
|
|
181
|
+
request=request,
|
|
182
|
+
request_body_required=True,
|
|
183
|
+
request_has_path_params=False,
|
|
184
|
+
request_has_query_params=True,
|
|
185
|
+
user_agent_header="user-agent",
|
|
186
|
+
accept_header_value="application/json",
|
|
187
|
+
http_headers=http_headers,
|
|
188
|
+
security=self.sdk_configuration.security,
|
|
189
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
190
|
+
request, False, False, "multipart", models.AudioTranscriptionRequest
|
|
191
|
+
),
|
|
192
|
+
timeout_ms=timeout_ms,
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
if retries == UNSET:
|
|
196
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
197
|
+
retries = self.sdk_configuration.retry_config
|
|
198
|
+
|
|
199
|
+
retry_config = None
|
|
200
|
+
if isinstance(retries, utils.RetryConfig):
|
|
201
|
+
retry_config = (retries, ["429", "500", "502", "503", "504"])
|
|
202
|
+
|
|
203
|
+
http_res = await self.do_request_async(
|
|
204
|
+
hook_ctx=HookContext(
|
|
205
|
+
config=self.sdk_configuration,
|
|
206
|
+
base_url=base_url or "",
|
|
207
|
+
operation_id="audio_api_v1_transcriptions_post",
|
|
208
|
+
oauth2_scopes=[],
|
|
209
|
+
security_source=get_security_from_env(
|
|
210
|
+
self.sdk_configuration.security, models.Security
|
|
211
|
+
),
|
|
212
|
+
),
|
|
213
|
+
request=req,
|
|
214
|
+
error_status_codes=["4XX", "5XX"],
|
|
215
|
+
retry_config=retry_config,
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
219
|
+
return utils.unmarshal_json(http_res.text, models.TranscriptionResponse)
|
|
220
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
221
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
222
|
+
raise models.SDKError(
|
|
223
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
224
|
+
)
|
|
225
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
226
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
227
|
+
raise models.SDKError(
|
|
228
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
content_type = http_res.headers.get("Content-Type")
|
|
232
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
233
|
+
raise models.SDKError(
|
|
234
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
235
|
+
http_res.status_code,
|
|
236
|
+
http_res_text,
|
|
237
|
+
http_res,
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
def stream(
|
|
241
|
+
self,
|
|
242
|
+
*,
|
|
243
|
+
model: str,
|
|
244
|
+
file: Optional[Union[models.File, models.FileTypedDict]] = None,
|
|
245
|
+
file_url: OptionalNullable[str] = UNSET,
|
|
246
|
+
file_id: OptionalNullable[str] = UNSET,
|
|
247
|
+
language: OptionalNullable[str] = UNSET,
|
|
248
|
+
temperature: OptionalNullable[float] = UNSET,
|
|
249
|
+
timestamp_granularities: Optional[List[models.TimestampGranularity]] = None,
|
|
250
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
251
|
+
server_url: Optional[str] = None,
|
|
252
|
+
timeout_ms: Optional[int] = None,
|
|
253
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
254
|
+
) -> eventstreaming.EventStream[models.TranscriptionStreamEvents]:
|
|
255
|
+
r"""Create streaming transcription (SSE)
|
|
256
|
+
|
|
257
|
+
:param model:
|
|
258
|
+
:param file:
|
|
259
|
+
:param file_url: Url of a file to be transcribed
|
|
260
|
+
:param file_id: ID of a file uploaded to /v1/files
|
|
261
|
+
:param language: Language of the audio, e.g. 'en'. Providing the language can boost accuracy.
|
|
262
|
+
:param temperature:
|
|
263
|
+
:param timestamp_granularities: Granularities of timestamps to include in the response.
|
|
264
|
+
:param retries: Override the default retry configuration for this method
|
|
265
|
+
:param server_url: Override the default server URL for this method
|
|
266
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
267
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
268
|
+
"""
|
|
269
|
+
base_url = None
|
|
270
|
+
url_variables = None
|
|
271
|
+
if timeout_ms is None:
|
|
272
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
273
|
+
|
|
274
|
+
if server_url is not None:
|
|
275
|
+
base_url = server_url
|
|
276
|
+
else:
|
|
277
|
+
base_url = self._get_url(base_url, url_variables)
|
|
278
|
+
|
|
279
|
+
request = models.AudioTranscriptionRequestStream(
|
|
280
|
+
model=model,
|
|
281
|
+
file=utils.get_pydantic_model(file, Optional[models.File]),
|
|
282
|
+
file_url=file_url,
|
|
283
|
+
file_id=file_id,
|
|
284
|
+
language=language,
|
|
285
|
+
temperature=temperature,
|
|
286
|
+
timestamp_granularities=timestamp_granularities,
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
req = self._build_request(
|
|
290
|
+
method="POST",
|
|
291
|
+
path="/v1/audio/transcriptions#stream",
|
|
292
|
+
base_url=base_url,
|
|
293
|
+
url_variables=url_variables,
|
|
294
|
+
request=request,
|
|
295
|
+
request_body_required=True,
|
|
296
|
+
request_has_path_params=False,
|
|
297
|
+
request_has_query_params=True,
|
|
298
|
+
user_agent_header="user-agent",
|
|
299
|
+
accept_header_value="text/event-stream",
|
|
300
|
+
http_headers=http_headers,
|
|
301
|
+
security=self.sdk_configuration.security,
|
|
302
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
303
|
+
request,
|
|
304
|
+
False,
|
|
305
|
+
False,
|
|
306
|
+
"multipart",
|
|
307
|
+
models.AudioTranscriptionRequestStream,
|
|
308
|
+
),
|
|
309
|
+
timeout_ms=timeout_ms,
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
if retries == UNSET:
|
|
313
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
314
|
+
retries = self.sdk_configuration.retry_config
|
|
315
|
+
|
|
316
|
+
retry_config = None
|
|
317
|
+
if isinstance(retries, utils.RetryConfig):
|
|
318
|
+
retry_config = (retries, ["429", "500", "502", "503", "504"])
|
|
319
|
+
|
|
320
|
+
http_res = self.do_request(
|
|
321
|
+
hook_ctx=HookContext(
|
|
322
|
+
config=self.sdk_configuration,
|
|
323
|
+
base_url=base_url or "",
|
|
324
|
+
operation_id="audio_api_v1_transcriptions_post_stream",
|
|
325
|
+
oauth2_scopes=[],
|
|
326
|
+
security_source=get_security_from_env(
|
|
327
|
+
self.sdk_configuration.security, models.Security
|
|
328
|
+
),
|
|
329
|
+
),
|
|
330
|
+
request=req,
|
|
331
|
+
error_status_codes=["4XX", "5XX"],
|
|
332
|
+
stream=True,
|
|
333
|
+
retry_config=retry_config,
|
|
334
|
+
)
|
|
335
|
+
|
|
336
|
+
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
337
|
+
return eventstreaming.EventStream(
|
|
338
|
+
http_res,
|
|
339
|
+
lambda raw: utils.unmarshal_json(raw, models.TranscriptionStreamEvents),
|
|
340
|
+
)
|
|
341
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
342
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
343
|
+
raise models.SDKError(
|
|
344
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
345
|
+
)
|
|
346
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
347
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
348
|
+
raise models.SDKError(
|
|
349
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
content_type = http_res.headers.get("Content-Type")
|
|
353
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
354
|
+
raise models.SDKError(
|
|
355
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
356
|
+
http_res.status_code,
|
|
357
|
+
http_res_text,
|
|
358
|
+
http_res,
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
async def stream_async(
|
|
362
|
+
self,
|
|
363
|
+
*,
|
|
364
|
+
model: str,
|
|
365
|
+
file: Optional[Union[models.File, models.FileTypedDict]] = None,
|
|
366
|
+
file_url: OptionalNullable[str] = UNSET,
|
|
367
|
+
file_id: OptionalNullable[str] = UNSET,
|
|
368
|
+
language: OptionalNullable[str] = UNSET,
|
|
369
|
+
temperature: OptionalNullable[float] = UNSET,
|
|
370
|
+
timestamp_granularities: Optional[List[models.TimestampGranularity]] = None,
|
|
371
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
372
|
+
server_url: Optional[str] = None,
|
|
373
|
+
timeout_ms: Optional[int] = None,
|
|
374
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
375
|
+
) -> eventstreaming.EventStreamAsync[models.TranscriptionStreamEvents]:
|
|
376
|
+
r"""Create streaming transcription (SSE)
|
|
377
|
+
|
|
378
|
+
:param model:
|
|
379
|
+
:param file:
|
|
380
|
+
:param file_url: Url of a file to be transcribed
|
|
381
|
+
:param file_id: ID of a file uploaded to /v1/files
|
|
382
|
+
:param language: Language of the audio, e.g. 'en'. Providing the language can boost accuracy.
|
|
383
|
+
:param temperature:
|
|
384
|
+
:param timestamp_granularities: Granularities of timestamps to include in the response.
|
|
385
|
+
:param retries: Override the default retry configuration for this method
|
|
386
|
+
:param server_url: Override the default server URL for this method
|
|
387
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
388
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
389
|
+
"""
|
|
390
|
+
base_url = None
|
|
391
|
+
url_variables = None
|
|
392
|
+
if timeout_ms is None:
|
|
393
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
394
|
+
|
|
395
|
+
if server_url is not None:
|
|
396
|
+
base_url = server_url
|
|
397
|
+
else:
|
|
398
|
+
base_url = self._get_url(base_url, url_variables)
|
|
399
|
+
|
|
400
|
+
request = models.AudioTranscriptionRequestStream(
|
|
401
|
+
model=model,
|
|
402
|
+
file=utils.get_pydantic_model(file, Optional[models.File]),
|
|
403
|
+
file_url=file_url,
|
|
404
|
+
file_id=file_id,
|
|
405
|
+
language=language,
|
|
406
|
+
temperature=temperature,
|
|
407
|
+
timestamp_granularities=timestamp_granularities,
|
|
408
|
+
)
|
|
409
|
+
|
|
410
|
+
req = self._build_request_async(
|
|
411
|
+
method="POST",
|
|
412
|
+
path="/v1/audio/transcriptions#stream",
|
|
413
|
+
base_url=base_url,
|
|
414
|
+
url_variables=url_variables,
|
|
415
|
+
request=request,
|
|
416
|
+
request_body_required=True,
|
|
417
|
+
request_has_path_params=False,
|
|
418
|
+
request_has_query_params=True,
|
|
419
|
+
user_agent_header="user-agent",
|
|
420
|
+
accept_header_value="text/event-stream",
|
|
421
|
+
http_headers=http_headers,
|
|
422
|
+
security=self.sdk_configuration.security,
|
|
423
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
424
|
+
request,
|
|
425
|
+
False,
|
|
426
|
+
False,
|
|
427
|
+
"multipart",
|
|
428
|
+
models.AudioTranscriptionRequestStream,
|
|
429
|
+
),
|
|
430
|
+
timeout_ms=timeout_ms,
|
|
431
|
+
)
|
|
432
|
+
|
|
433
|
+
if retries == UNSET:
|
|
434
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
435
|
+
retries = self.sdk_configuration.retry_config
|
|
436
|
+
|
|
437
|
+
retry_config = None
|
|
438
|
+
if isinstance(retries, utils.RetryConfig):
|
|
439
|
+
retry_config = (retries, ["429", "500", "502", "503", "504"])
|
|
440
|
+
|
|
441
|
+
http_res = await self.do_request_async(
|
|
442
|
+
hook_ctx=HookContext(
|
|
443
|
+
config=self.sdk_configuration,
|
|
444
|
+
base_url=base_url or "",
|
|
445
|
+
operation_id="audio_api_v1_transcriptions_post_stream",
|
|
446
|
+
oauth2_scopes=[],
|
|
447
|
+
security_source=get_security_from_env(
|
|
448
|
+
self.sdk_configuration.security, models.Security
|
|
449
|
+
),
|
|
450
|
+
),
|
|
451
|
+
request=req,
|
|
452
|
+
error_status_codes=["4XX", "5XX"],
|
|
453
|
+
stream=True,
|
|
454
|
+
retry_config=retry_config,
|
|
455
|
+
)
|
|
456
|
+
|
|
457
|
+
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
458
|
+
return eventstreaming.EventStreamAsync(
|
|
459
|
+
http_res,
|
|
460
|
+
lambda raw: utils.unmarshal_json(raw, models.TranscriptionStreamEvents),
|
|
461
|
+
)
|
|
462
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
463
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
464
|
+
raise models.SDKError(
|
|
465
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
466
|
+
)
|
|
467
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
468
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
469
|
+
raise models.SDKError(
|
|
470
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
471
|
+
)
|
|
472
|
+
|
|
473
|
+
content_type = http_res.headers.get("Content-Type")
|
|
474
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
475
|
+
raise models.SDKError(
|
|
476
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
477
|
+
http_res.status_code,
|
|
478
|
+
http_res_text,
|
|
479
|
+
http_res,
|
|
480
|
+
)
|