deapi-sdk 0.6.1__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.
- deapi_sdk/__init__.py +409 -0
- deapi_sdk/_cards.py +313 -0
- deapi_sdk/_client.py +411 -0
- deapi_sdk/_config.py +77 -0
- deapi_sdk/_constants.py +61 -0
- deapi_sdk/_download.py +37 -0
- deapi_sdk/_exceptions.py +184 -0
- deapi_sdk/_files.py +59 -0
- deapi_sdk/_payload.py +50 -0
- deapi_sdk/_polling.py +157 -0
- deapi_sdk/_realtime/__init__.py +7 -0
- deapi_sdk/_realtime/_discovery.py +43 -0
- deapi_sdk/_realtime/_engine.py +419 -0
- deapi_sdk/_realtime/_protocol.py +152 -0
- deapi_sdk/_realtime/_session.py +529 -0
- deapi_sdk/_types.py +31 -0
- deapi_sdk/_version.py +3 -0
- deapi_sdk/py.typed +0 -0
- deapi_sdk/resources/__init__.py +35 -0
- deapi_sdk/resources/account.py +149 -0
- deapi_sdk/resources/audio.py +386 -0
- deapi_sdk/resources/embeddings.py +116 -0
- deapi_sdk/resources/images.py +616 -0
- deapi_sdk/resources/keys.py +277 -0
- deapi_sdk/resources/models.py +161 -0
- deapi_sdk/resources/ocr.py +152 -0
- deapi_sdk/resources/prompts.py +137 -0
- deapi_sdk/resources/transcription.py +308 -0
- deapi_sdk/resources/video.py +985 -0
- deapi_sdk/transcript.py +142 -0
- deapi_sdk/types/__init__.py +68 -0
- deapi_sdk/types/account.py +115 -0
- deapi_sdk/types/audio.py +35 -0
- deapi_sdk/types/common.py +174 -0
- deapi_sdk/types/embeddings.py +11 -0
- deapi_sdk/types/images.py +40 -0
- deapi_sdk/types/keys.py +53 -0
- deapi_sdk/types/ocr.py +14 -0
- deapi_sdk/types/prompts.py +26 -0
- deapi_sdk/types/transcription.py +14 -0
- deapi_sdk/types/video.py +84 -0
- deapi_sdk/types/websocket.py +36 -0
- deapi_sdk/webhook.py +159 -0
- deapi_sdk-0.6.1.dist-info/METADATA +644 -0
- deapi_sdk-0.6.1.dist-info/RECORD +47 -0
- deapi_sdk-0.6.1.dist-info/WHEEL +4 -0
- deapi_sdk-0.6.1.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from deapi_sdk._client import AsyncHTTPClient, SyncHTTPClient
|
|
6
|
+
from deapi_sdk._files import FileInput, normalize_file
|
|
7
|
+
from deapi_sdk.types.common import PriceResult
|
|
8
|
+
from deapi_sdk.types.prompts import EnhancePromptResult
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Prompts:
|
|
12
|
+
"""Sync prompt booster resource.
|
|
13
|
+
|
|
14
|
+
All prompt boosting goes through one endpoint that takes a ``type``
|
|
15
|
+
discriminator (e.g. ``"images.generations"``, ``"videos.animations"``,
|
|
16
|
+
``"audio.speech"``).
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def __init__(self, client: SyncHTTPClient) -> None:
|
|
20
|
+
self._client = client
|
|
21
|
+
|
|
22
|
+
def enhance(
|
|
23
|
+
self,
|
|
24
|
+
*,
|
|
25
|
+
prompt: str,
|
|
26
|
+
type: str,
|
|
27
|
+
model_slug: str,
|
|
28
|
+
negative_prompt: str | None = None,
|
|
29
|
+
image: FileInput | None = None,
|
|
30
|
+
) -> EnhancePromptResult:
|
|
31
|
+
"""Enhance a prompt via the unified v2 endpoint.
|
|
32
|
+
|
|
33
|
+
``type`` uses dot-notation matching the API resource (e.g.
|
|
34
|
+
``"images.generations"``, ``"images.edits"``, ``"videos.animations"``,
|
|
35
|
+
``"videos.generations"``, ``"audio.speech"``, ``"audio.music"``).
|
|
36
|
+
``image`` is required for ``images.edits`` and ``videos.animations``. Other types
|
|
37
|
+
(upscales, background removal, OCR, transcription, embeddings) are rejected with 422;
|
|
38
|
+
see ``deapi_sdk.types.prompts.PromptBoosterType``. The returned ``negative_prompt``
|
|
39
|
+
is ignored by models without negative-prompt support.
|
|
40
|
+
"""
|
|
41
|
+
url = self._client._resolve_endpoint("prompts_enhance")
|
|
42
|
+
files = _build_enhance_parts(
|
|
43
|
+
prompt=prompt, type=type, model_slug=model_slug,
|
|
44
|
+
negative_prompt=negative_prompt, image=image,
|
|
45
|
+
)
|
|
46
|
+
resp = self._client.post(url, files=files)
|
|
47
|
+
return EnhancePromptResult.model_validate(resp.get("data", resp))
|
|
48
|
+
|
|
49
|
+
def enhance_price(
|
|
50
|
+
self,
|
|
51
|
+
*,
|
|
52
|
+
prompt: str,
|
|
53
|
+
type: str,
|
|
54
|
+
model_slug: str,
|
|
55
|
+
negative_prompt: str | None = None,
|
|
56
|
+
image: FileInput | None = None,
|
|
57
|
+
) -> PriceResult:
|
|
58
|
+
"""Calculate price for prompt enhancement."""
|
|
59
|
+
url = self._client._resolve_endpoint("prompts_enhance_price")
|
|
60
|
+
files = _build_enhance_parts(
|
|
61
|
+
prompt=prompt, type=type, model_slug=model_slug,
|
|
62
|
+
negative_prompt=negative_prompt, image=image,
|
|
63
|
+
)
|
|
64
|
+
resp = self._client.post(url, files=files)
|
|
65
|
+
return PriceResult.model_validate(resp.get("data", resp))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class AsyncPrompts:
|
|
69
|
+
"""Async prompt booster resource."""
|
|
70
|
+
|
|
71
|
+
def __init__(self, client: AsyncHTTPClient) -> None:
|
|
72
|
+
self._client = client
|
|
73
|
+
|
|
74
|
+
async def enhance(
|
|
75
|
+
self,
|
|
76
|
+
*,
|
|
77
|
+
prompt: str,
|
|
78
|
+
type: str,
|
|
79
|
+
model_slug: str,
|
|
80
|
+
negative_prompt: str | None = None,
|
|
81
|
+
image: FileInput | None = None,
|
|
82
|
+
) -> EnhancePromptResult:
|
|
83
|
+
url = self._client._resolve_endpoint("prompts_enhance")
|
|
84
|
+
files = _build_enhance_parts(
|
|
85
|
+
prompt=prompt, type=type, model_slug=model_slug,
|
|
86
|
+
negative_prompt=negative_prompt, image=image,
|
|
87
|
+
)
|
|
88
|
+
resp = await self._client.post(url, files=files)
|
|
89
|
+
return EnhancePromptResult.model_validate(resp.get("data", resp))
|
|
90
|
+
|
|
91
|
+
async def enhance_price(
|
|
92
|
+
self,
|
|
93
|
+
*,
|
|
94
|
+
prompt: str,
|
|
95
|
+
type: str,
|
|
96
|
+
model_slug: str,
|
|
97
|
+
negative_prompt: str | None = None,
|
|
98
|
+
image: FileInput | None = None,
|
|
99
|
+
) -> PriceResult:
|
|
100
|
+
url = self._client._resolve_endpoint("prompts_enhance_price")
|
|
101
|
+
files = _build_enhance_parts(
|
|
102
|
+
prompt=prompt, type=type, model_slug=model_slug,
|
|
103
|
+
negative_prompt=negative_prompt, image=image,
|
|
104
|
+
)
|
|
105
|
+
resp = await self._client.post(url, files=files)
|
|
106
|
+
return PriceResult.model_validate(resp.get("data", resp))
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# --- Private helpers ---
|
|
110
|
+
|
|
111
|
+
def _build_enhance_parts(
|
|
112
|
+
*,
|
|
113
|
+
prompt: str,
|
|
114
|
+
type: str,
|
|
115
|
+
model_slug: str,
|
|
116
|
+
negative_prompt: str | None = None,
|
|
117
|
+
image: FileInput | None = None,
|
|
118
|
+
) -> list[tuple[str, Any]]:
|
|
119
|
+
"""Build the multipart form parts for the unified prompt enhancer.
|
|
120
|
+
|
|
121
|
+
The v2 ``prompts/enhancements`` endpoint declares ``multipart/form-data``
|
|
122
|
+
as its only content type in the OpenAPI spec, so we must force multipart
|
|
123
|
+
encoding even when no image is sent. httpx triggers multipart encoding
|
|
124
|
+
when ``files=`` is non-empty — passing text fields as ``(name, (None, value))``
|
|
125
|
+
tuples in ``files=`` is the documented httpx pattern for mixing text parts
|
|
126
|
+
with file parts in a single multipart request.
|
|
127
|
+
"""
|
|
128
|
+
parts: list[tuple[str, Any]] = [
|
|
129
|
+
("prompt", (None, prompt)),
|
|
130
|
+
("type", (None, type)),
|
|
131
|
+
("model_slug", (None, model_slug)),
|
|
132
|
+
]
|
|
133
|
+
if negative_prompt is not None:
|
|
134
|
+
parts.append(("negative_prompt", (None, negative_prompt)))
|
|
135
|
+
if image is not None:
|
|
136
|
+
parts.append(("image", normalize_file(image, "image")))
|
|
137
|
+
return parts
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from deapi_sdk._client import AsyncHTTPClient, SyncHTTPClient
|
|
6
|
+
from deapi_sdk._download import adownload_text, download_text
|
|
7
|
+
from deapi_sdk._files import FileInput, normalize_file
|
|
8
|
+
from deapi_sdk._payload import drop_none, form_bool, webhook_fields
|
|
9
|
+
from deapi_sdk._polling import AsyncJob, Job
|
|
10
|
+
from deapi_sdk.transcript import Transcript, parse_transcript
|
|
11
|
+
from deapi_sdk.types.common import JobResult, PriceResult
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _transcription_fields(
|
|
15
|
+
*,
|
|
16
|
+
model: str,
|
|
17
|
+
include_ts: bool | None,
|
|
18
|
+
ts_level: str | None,
|
|
19
|
+
diarize: bool | None,
|
|
20
|
+
lang: str | None,
|
|
21
|
+
include_metadata: bool | None,
|
|
22
|
+
) -> dict[str, Any]:
|
|
23
|
+
"""Fields shared by the job and price payloads (None values dropped).
|
|
24
|
+
|
|
25
|
+
``ts_level`` and ``diarize`` only mean something with timestamps on (the API
|
|
26
|
+
drops ``ts_level`` silently without them), so asking for either turns
|
|
27
|
+
``include_ts`` on unless the caller set it explicitly.
|
|
28
|
+
"""
|
|
29
|
+
if include_ts is None and (ts_level or diarize):
|
|
30
|
+
include_ts = True
|
|
31
|
+
return drop_none({
|
|
32
|
+
"model": model,
|
|
33
|
+
"include_ts": include_ts,
|
|
34
|
+
"ts_level": ts_level,
|
|
35
|
+
"diarize": diarize,
|
|
36
|
+
"lang": lang,
|
|
37
|
+
"include_metadata": include_metadata,
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _form(fields: dict[str, Any]) -> dict[str, Any]:
|
|
42
|
+
"""Encode bools for a multipart body."""
|
|
43
|
+
return {k: form_bool(v) if isinstance(v, bool) else v for k, v in fields.items()}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _check_source(source_url: str | None, source_file: FileInput | None) -> None:
|
|
47
|
+
if source_url is not None and source_file is not None:
|
|
48
|
+
raise ValueError("Provide either 'source_url' or 'source_file', not both.")
|
|
49
|
+
if source_url is None and source_file is None:
|
|
50
|
+
raise ValueError("Either 'source_url' or 'source_file' is required.")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _build_create(
|
|
54
|
+
*,
|
|
55
|
+
source_url: str | None,
|
|
56
|
+
source_file: FileInput | None,
|
|
57
|
+
model: str,
|
|
58
|
+
include_ts: bool | None,
|
|
59
|
+
ts_level: str | None,
|
|
60
|
+
diarize: bool | None,
|
|
61
|
+
lang: str | None,
|
|
62
|
+
include_metadata: bool | None,
|
|
63
|
+
return_result_in_response: bool | None,
|
|
64
|
+
webhook_url: str | None,
|
|
65
|
+
webhook_secret: str | None,
|
|
66
|
+
) -> dict[str, Any]:
|
|
67
|
+
"""Build the keyword arguments for ``post()`` (JSON for URLs, multipart for files)."""
|
|
68
|
+
_check_source(source_url, source_file)
|
|
69
|
+
fields = _transcription_fields(
|
|
70
|
+
model=model, include_ts=include_ts, ts_level=ts_level, diarize=diarize,
|
|
71
|
+
lang=lang, include_metadata=include_metadata,
|
|
72
|
+
)
|
|
73
|
+
fields.update(drop_none({"return_result_in_response": return_result_in_response}))
|
|
74
|
+
fields.update(webhook_fields(webhook_url, webhook_secret))
|
|
75
|
+
if source_file is not None:
|
|
76
|
+
return {"data": _form(fields), "files": [("source_file", normalize_file(source_file, "source_file"))]}
|
|
77
|
+
return {"json": {"source_url": source_url, **fields}}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _build_price(
|
|
81
|
+
*,
|
|
82
|
+
source_url: str | None,
|
|
83
|
+
source_file: FileInput | None,
|
|
84
|
+
model: str,
|
|
85
|
+
include_ts: bool | None,
|
|
86
|
+
ts_level: str | None,
|
|
87
|
+
diarize: bool | None,
|
|
88
|
+
lang: str | None,
|
|
89
|
+
include_metadata: bool | None,
|
|
90
|
+
platform: str | None,
|
|
91
|
+
duration_seconds: float | None,
|
|
92
|
+
) -> dict[str, Any]:
|
|
93
|
+
fields = _transcription_fields(
|
|
94
|
+
model=model, include_ts=include_ts, ts_level=ts_level, diarize=diarize,
|
|
95
|
+
lang=lang, include_metadata=include_metadata,
|
|
96
|
+
)
|
|
97
|
+
fields.update(drop_none({"platform": platform, "duration_seconds": duration_seconds}))
|
|
98
|
+
if source_url is not None and source_file is not None:
|
|
99
|
+
raise ValueError("Provide either 'source_url' or 'source_file', not both.")
|
|
100
|
+
if source_file is not None:
|
|
101
|
+
return {"data": _form(fields), "files": [("source_file", normalize_file(source_file, "source_file"))]}
|
|
102
|
+
if source_url is not None:
|
|
103
|
+
fields["source_url"] = source_url
|
|
104
|
+
return {"json": fields}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _pick_result_source(result: JobResult, alt_format: str | None) -> tuple[str | None, str | None]:
|
|
108
|
+
"""Return ``(inline_text, url_to_download)`` for ``get_transcript``."""
|
|
109
|
+
if alt_format is not None:
|
|
110
|
+
alts = result.results_alt_formats or {}
|
|
111
|
+
if alt_format not in alts:
|
|
112
|
+
available = ", ".join(sorted(alts)) or "none"
|
|
113
|
+
raise ValueError(f"No '{alt_format}' rendition on this job (available: {available}).")
|
|
114
|
+
return None, alts[alt_format]
|
|
115
|
+
if result.result:
|
|
116
|
+
return result.result, None
|
|
117
|
+
if result.result_url:
|
|
118
|
+
return None, result.result_url
|
|
119
|
+
raise ValueError(
|
|
120
|
+
"The job result has neither an inline 'result' nor a 'result_url'. "
|
|
121
|
+
"Submit with return_result_in_response=True or wait until the job is done."
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _format_hint(output_format: str | None, alt_format: str | None) -> str | None:
|
|
126
|
+
# A txt rendition is plain text whatever the model's primary format is.
|
|
127
|
+
if alt_format is not None and alt_format.lower() in ("txt", "text"):
|
|
128
|
+
return "text"
|
|
129
|
+
return output_format
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
class Transcription:
|
|
133
|
+
"""Sync transcription resource: one endpoint for audio and video, URL or file.
|
|
134
|
+
|
|
135
|
+
The result of a finished job is either a JSON document or plain text,
|
|
136
|
+
depending on the model; ``get_transcript()`` returns both as a ``Transcript``.
|
|
137
|
+
"""
|
|
138
|
+
|
|
139
|
+
def __init__(self, client: SyncHTTPClient) -> None:
|
|
140
|
+
self._client = client
|
|
141
|
+
|
|
142
|
+
def create(
|
|
143
|
+
self,
|
|
144
|
+
*,
|
|
145
|
+
model: str,
|
|
146
|
+
include_ts: bool | None = None,
|
|
147
|
+
ts_level: str | None = None,
|
|
148
|
+
diarize: bool | None = None,
|
|
149
|
+
lang: str | None = None,
|
|
150
|
+
include_metadata: bool | None = None,
|
|
151
|
+
source_url: str | None = None,
|
|
152
|
+
source_file: FileInput | None = None,
|
|
153
|
+
return_result_in_response: bool | None = None,
|
|
154
|
+
webhook_url: str | None = None,
|
|
155
|
+
webhook_secret: str | None = None,
|
|
156
|
+
) -> Job:
|
|
157
|
+
"""Submit a transcription job via the unified endpoint.
|
|
158
|
+
|
|
159
|
+
Provide either ``source_url`` (video/audio URL) or ``source_file``
|
|
160
|
+
(audio/video file upload), not both.
|
|
161
|
+
|
|
162
|
+
Args:
|
|
163
|
+
model: Model slug, e.g. ``WhisperLargeV3Ct2``.
|
|
164
|
+
include_ts: Return timestamps. Implied when ``ts_level`` or ``diarize`` is set.
|
|
165
|
+
ts_level: ``segment``, ``word`` or ``char``; only levels the model lists
|
|
166
|
+
under ``info.limits.timestamp_levels`` are accepted.
|
|
167
|
+
diarize: Label speakers (models with ``supports_diarization``); implies timestamps.
|
|
168
|
+
lang: ISO language code; unset or ``auto`` = detect.
|
|
169
|
+
include_metadata: Return source info as ``metadata`` on the job status. Only URL sources have
|
|
170
|
+
any (a file upload returns null and is never charged for the flag).
|
|
171
|
+
webhook_secret: 32-255 char key to sign webhooks with; requires ``webhook_url``.
|
|
172
|
+
"""
|
|
173
|
+
kwargs = _build_create(
|
|
174
|
+
source_url=source_url, source_file=source_file, model=model, include_ts=include_ts,
|
|
175
|
+
ts_level=ts_level, diarize=diarize, lang=lang, include_metadata=include_metadata,
|
|
176
|
+
return_result_in_response=return_result_in_response,
|
|
177
|
+
webhook_url=webhook_url, webhook_secret=webhook_secret,
|
|
178
|
+
)
|
|
179
|
+
resp = self._client.post(self._client._resolve_endpoint("transcribe"), **kwargs)
|
|
180
|
+
request_id = resp["data"]["request_id"]
|
|
181
|
+
status_url = self._client._resolve_endpoint("request_status")
|
|
182
|
+
return Job(request_id, self._client, status_url)
|
|
183
|
+
|
|
184
|
+
def create_price(
|
|
185
|
+
self,
|
|
186
|
+
*,
|
|
187
|
+
model: str,
|
|
188
|
+
include_ts: bool | None = None,
|
|
189
|
+
ts_level: str | None = None,
|
|
190
|
+
diarize: bool | None = None,
|
|
191
|
+
lang: str | None = None,
|
|
192
|
+
include_metadata: bool | None = None,
|
|
193
|
+
platform: str | None = None,
|
|
194
|
+
source_url: str | None = None,
|
|
195
|
+
source_file: FileInput | None = None,
|
|
196
|
+
duration_seconds: float | None = None,
|
|
197
|
+
) -> PriceResult:
|
|
198
|
+
"""Calculate the price of a transcription.
|
|
199
|
+
|
|
200
|
+
Pass the same ``ts_level`` / ``diarize`` / ``lang`` / ``include_metadata`` you will pass
|
|
201
|
+
to ``create()``: a quote that omits them comes in under the real charge.
|
|
202
|
+
``platform`` (e.g. ``tiktok``) matters only when quoting from ``duration_seconds``.
|
|
203
|
+
"""
|
|
204
|
+
kwargs = _build_price(
|
|
205
|
+
source_url=source_url, source_file=source_file, model=model, include_ts=include_ts,
|
|
206
|
+
ts_level=ts_level, diarize=diarize, lang=lang, include_metadata=include_metadata,
|
|
207
|
+
platform=platform, duration_seconds=duration_seconds,
|
|
208
|
+
)
|
|
209
|
+
resp = self._client.post(self._client._resolve_endpoint("transcribe_price"), **kwargs)
|
|
210
|
+
return PriceResult.model_validate(resp.get("data", resp))
|
|
211
|
+
|
|
212
|
+
def get_transcript(
|
|
213
|
+
self,
|
|
214
|
+
result: JobResult,
|
|
215
|
+
*,
|
|
216
|
+
output_format: str | None = None,
|
|
217
|
+
alt_format: str | None = None,
|
|
218
|
+
) -> Transcript:
|
|
219
|
+
"""Turn a finished job's result into a ``Transcript``.
|
|
220
|
+
|
|
221
|
+
Uses the inline ``result`` when present, otherwise downloads ``result_url``.
|
|
222
|
+
The download is a plain GET that carries **no** Authorization header (result
|
|
223
|
+
URLs are storage URLs; the API key must not leak to them).
|
|
224
|
+
|
|
225
|
+
Args:
|
|
226
|
+
result: ``job.wait()`` / ``job.status()`` result.
|
|
227
|
+
output_format: The model card's ``info.limits.output_format`` (``"json"``);
|
|
228
|
+
``"text"`` forces plain text. Auto-detected when omitted.
|
|
229
|
+
alt_format: Pick a rendition from ``results_alt_formats`` (e.g. ``"txt"``)
|
|
230
|
+
instead of the primary result.
|
|
231
|
+
"""
|
|
232
|
+
inline, url = _pick_result_source(result, alt_format)
|
|
233
|
+
if inline is None:
|
|
234
|
+
inline = download_text(url, self._client._config.timeout) # type: ignore[arg-type]
|
|
235
|
+
return parse_transcript(inline, output_format=_format_hint(output_format, alt_format))
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
class AsyncTranscription:
|
|
239
|
+
"""Async transcription resource."""
|
|
240
|
+
|
|
241
|
+
def __init__(self, client: AsyncHTTPClient) -> None:
|
|
242
|
+
self._client = client
|
|
243
|
+
|
|
244
|
+
async def create(
|
|
245
|
+
self,
|
|
246
|
+
*,
|
|
247
|
+
model: str,
|
|
248
|
+
include_ts: bool | None = None,
|
|
249
|
+
ts_level: str | None = None,
|
|
250
|
+
diarize: bool | None = None,
|
|
251
|
+
lang: str | None = None,
|
|
252
|
+
include_metadata: bool | None = None,
|
|
253
|
+
source_url: str | None = None,
|
|
254
|
+
source_file: FileInput | None = None,
|
|
255
|
+
return_result_in_response: bool | None = None,
|
|
256
|
+
webhook_url: str | None = None,
|
|
257
|
+
webhook_secret: str | None = None,
|
|
258
|
+
) -> AsyncJob:
|
|
259
|
+
"""Submit a transcription job. See ``Transcription.create`` for the parameters."""
|
|
260
|
+
kwargs = _build_create(
|
|
261
|
+
source_url=source_url, source_file=source_file, model=model, include_ts=include_ts,
|
|
262
|
+
ts_level=ts_level, diarize=diarize, lang=lang, include_metadata=include_metadata,
|
|
263
|
+
return_result_in_response=return_result_in_response,
|
|
264
|
+
webhook_url=webhook_url, webhook_secret=webhook_secret,
|
|
265
|
+
)
|
|
266
|
+
resp = await self._client.post(self._client._resolve_endpoint("transcribe"), **kwargs)
|
|
267
|
+
request_id = resp["data"]["request_id"]
|
|
268
|
+
status_url = self._client._resolve_endpoint("request_status")
|
|
269
|
+
return AsyncJob(request_id, self._client, status_url)
|
|
270
|
+
|
|
271
|
+
async def create_price(
|
|
272
|
+
self,
|
|
273
|
+
*,
|
|
274
|
+
model: str,
|
|
275
|
+
include_ts: bool | None = None,
|
|
276
|
+
ts_level: str | None = None,
|
|
277
|
+
diarize: bool | None = None,
|
|
278
|
+
lang: str | None = None,
|
|
279
|
+
include_metadata: bool | None = None,
|
|
280
|
+
platform: str | None = None,
|
|
281
|
+
source_url: str | None = None,
|
|
282
|
+
source_file: FileInput | None = None,
|
|
283
|
+
duration_seconds: float | None = None,
|
|
284
|
+
) -> PriceResult:
|
|
285
|
+
"""Calculate the price of a transcription. See ``Transcription.create_price``."""
|
|
286
|
+
kwargs = _build_price(
|
|
287
|
+
source_url=source_url, source_file=source_file, model=model, include_ts=include_ts,
|
|
288
|
+
ts_level=ts_level, diarize=diarize, lang=lang, include_metadata=include_metadata,
|
|
289
|
+
platform=platform, duration_seconds=duration_seconds,
|
|
290
|
+
)
|
|
291
|
+
resp = await self._client.post(self._client._resolve_endpoint("transcribe_price"), **kwargs)
|
|
292
|
+
return PriceResult.model_validate(resp.get("data", resp))
|
|
293
|
+
|
|
294
|
+
async def get_transcript(
|
|
295
|
+
self,
|
|
296
|
+
result: JobResult,
|
|
297
|
+
*,
|
|
298
|
+
output_format: str | None = None,
|
|
299
|
+
alt_format: str | None = None,
|
|
300
|
+
) -> Transcript:
|
|
301
|
+
"""Turn a finished job's result into a ``Transcript``.
|
|
302
|
+
|
|
303
|
+
See ``Transcription.get_transcript``; the download sends no Authorization header.
|
|
304
|
+
"""
|
|
305
|
+
inline, url = _pick_result_source(result, alt_format)
|
|
306
|
+
if inline is None:
|
|
307
|
+
inline = await adownload_text(url, self._client._config.timeout) # type: ignore[arg-type]
|
|
308
|
+
return parse_transcript(inline, output_format=_format_hint(output_format, alt_format))
|