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
deapi_sdk/transcript.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"""Transcript result parsing for v2 transcription jobs.
|
|
2
|
+
|
|
3
|
+
A transcription job's result comes in one of two shapes, decided by the model
|
|
4
|
+
card in ``GET /models`` (``info.limits.output_format``):
|
|
5
|
+
|
|
6
|
+
* ``"json"`` (e.g. ``WhisperLargeV3Ct2``): the transcript is always a JSON
|
|
7
|
+
document ``{"text", "language", "ts_level", "diarization_available",
|
|
8
|
+
"segments": [...]}`` -- even with timestamps off.
|
|
9
|
+
* ``null`` (e.g. ``WhisperLargeV3``): plain text, with timestamps written into
|
|
10
|
+
the text itself (``[0:50 - 1:49] ...``) when requested.
|
|
11
|
+
|
|
12
|
+
``parse_transcript`` turns either into one ``Transcript`` object.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import json
|
|
18
|
+
from typing import Any, Literal
|
|
19
|
+
|
|
20
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class TranscriptWord(BaseModel):
|
|
24
|
+
"""One word with timing. Extra fields (e.g. ``chars``) are kept."""
|
|
25
|
+
|
|
26
|
+
model_config = ConfigDict(extra="allow")
|
|
27
|
+
|
|
28
|
+
word: str = ""
|
|
29
|
+
start: float | None = None
|
|
30
|
+
end: float | None = None
|
|
31
|
+
speaker: str | None = None
|
|
32
|
+
score: float | None = None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class TranscriptSegment(BaseModel):
|
|
36
|
+
"""One timed segment. ``speaker`` is set when diarization ran, ``words`` at word level."""
|
|
37
|
+
|
|
38
|
+
model_config = ConfigDict(extra="allow")
|
|
39
|
+
|
|
40
|
+
start: float | None = None
|
|
41
|
+
end: float | None = None
|
|
42
|
+
text: str = ""
|
|
43
|
+
speaker: str | None = None
|
|
44
|
+
words: list[TranscriptWord] | None = None
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class Transcript(BaseModel):
|
|
48
|
+
"""A parsed transcription result.
|
|
49
|
+
|
|
50
|
+
``format`` is ``"json"`` for a structured document and ``"text"`` for plain
|
|
51
|
+
text (``segments`` is then empty and ``language`` / ``ts_level`` are None).
|
|
52
|
+
``raw`` is always the untouched result string.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
model_config = ConfigDict(extra="allow")
|
|
56
|
+
|
|
57
|
+
text: str
|
|
58
|
+
format: Literal["json", "text"]
|
|
59
|
+
language: str | None = None
|
|
60
|
+
ts_level: str | None = None
|
|
61
|
+
diarization_available: bool | None = None
|
|
62
|
+
segments: list[TranscriptSegment] = Field(default_factory=list)
|
|
63
|
+
raw: str = ""
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def transcript_output_format(model_card: Any) -> str | None:
|
|
67
|
+
"""Read ``info.limits.output_format`` from a model card (dict or pydantic model).
|
|
68
|
+
|
|
69
|
+
Returns ``"json"`` or None (None means the model returns plain text).
|
|
70
|
+
"""
|
|
71
|
+
if hasattr(model_card, "model_dump"):
|
|
72
|
+
model_card = model_card.model_dump()
|
|
73
|
+
if not isinstance(model_card, dict):
|
|
74
|
+
return None
|
|
75
|
+
info = model_card.get("info")
|
|
76
|
+
limits = info.get("limits") if isinstance(info, dict) else None
|
|
77
|
+
value = limits.get("output_format") if isinstance(limits, dict) else None
|
|
78
|
+
return value if isinstance(value, str) and value else None
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _decode_object(raw: str | dict[str, Any]) -> dict[str, Any] | None:
|
|
82
|
+
"""Return the transcript JSON object, or None if ``raw`` is not one."""
|
|
83
|
+
if isinstance(raw, dict):
|
|
84
|
+
doc: Any = raw
|
|
85
|
+
else:
|
|
86
|
+
if not raw.lstrip().startswith("{"):
|
|
87
|
+
return None
|
|
88
|
+
try:
|
|
89
|
+
doc = json.loads(raw)
|
|
90
|
+
except ValueError:
|
|
91
|
+
return None
|
|
92
|
+
if not isinstance(doc, dict) or not isinstance(doc.get("text"), str):
|
|
93
|
+
return None
|
|
94
|
+
return doc
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def parse_transcript(
|
|
98
|
+
raw: str | dict[str, Any] | None,
|
|
99
|
+
*,
|
|
100
|
+
output_format: str | None = None,
|
|
101
|
+
) -> Transcript:
|
|
102
|
+
"""Parse a transcription result (``JobResult.result`` or a downloaded file).
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
raw: The result string, or an already-decoded JSON object.
|
|
106
|
+
output_format: The model card's ``info.limits.output_format``.
|
|
107
|
+
``"json"`` or None (auto): a JSON object with a ``text`` field is
|
|
108
|
+
parsed as a structured transcript. ``"text"``: never decode, the
|
|
109
|
+
string is returned as is.
|
|
110
|
+
|
|
111
|
+
Never raises on malformed or unexpected input -- anything that is not a
|
|
112
|
+
structured transcript comes back as ``format="text"``.
|
|
113
|
+
"""
|
|
114
|
+
if raw is None:
|
|
115
|
+
return Transcript(text="", format="text", raw="")
|
|
116
|
+
raw_str = raw if isinstance(raw, str) else json.dumps(raw)
|
|
117
|
+
|
|
118
|
+
doc = None if output_format == "text" else _decode_object(raw)
|
|
119
|
+
if doc is None:
|
|
120
|
+
return Transcript(text=raw_str, format="text", raw=raw_str)
|
|
121
|
+
|
|
122
|
+
segments: list[TranscriptSegment] = []
|
|
123
|
+
raw_segments = doc.get("segments")
|
|
124
|
+
if isinstance(raw_segments, list):
|
|
125
|
+
for seg in raw_segments:
|
|
126
|
+
try:
|
|
127
|
+
segments.append(TranscriptSegment.model_validate(seg))
|
|
128
|
+
except Exception:
|
|
129
|
+
continue
|
|
130
|
+
|
|
131
|
+
diarization = doc.get("diarization_available")
|
|
132
|
+
language = doc.get("language")
|
|
133
|
+
ts_level = doc.get("ts_level")
|
|
134
|
+
return Transcript(
|
|
135
|
+
text=doc["text"],
|
|
136
|
+
format="json",
|
|
137
|
+
language=language if isinstance(language, str) else None,
|
|
138
|
+
ts_level=ts_level if isinstance(ts_level, str) else None,
|
|
139
|
+
diarization_available=diarization if isinstance(diarization, bool) else None,
|
|
140
|
+
segments=segments,
|
|
141
|
+
raw=raw_str,
|
|
142
|
+
)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from deapi_sdk.types.account import Account, Payment, PaymentsPage, UsageReport
|
|
4
|
+
from deapi_sdk.types.audio import Text2AudioParams, Text2MusicParams
|
|
5
|
+
from deapi_sdk.types.common import (
|
|
6
|
+
Balance,
|
|
7
|
+
JobResult,
|
|
8
|
+
JobStatusEvent,
|
|
9
|
+
JobSubmission,
|
|
10
|
+
ModelInfo,
|
|
11
|
+
ModelsResponse,
|
|
12
|
+
PaginationLinks,
|
|
13
|
+
PaginationMeta,
|
|
14
|
+
PriceResult,
|
|
15
|
+
PromptBoost,
|
|
16
|
+
)
|
|
17
|
+
from deapi_sdk.types.embeddings import Text2EmbeddingParams
|
|
18
|
+
from deapi_sdk.types.images import Img2ImgParams, LoraWeight, Text2ImageParams
|
|
19
|
+
from deapi_sdk.types.keys import ApiKey, ApiKeyCreated, ApiKeysPage
|
|
20
|
+
from deapi_sdk.types.ocr import Img2TextParams
|
|
21
|
+
from deapi_sdk.types.prompts import EnhancePromptResult
|
|
22
|
+
from deapi_sdk.types.transcription import TranscribeParams
|
|
23
|
+
from deapi_sdk.types.video import (
|
|
24
|
+
Aud2VideoParams,
|
|
25
|
+
Img2VideoParams,
|
|
26
|
+
Text2VideoParams,
|
|
27
|
+
VideoDescription,
|
|
28
|
+
VideoEvent,
|
|
29
|
+
parse_video_description,
|
|
30
|
+
)
|
|
31
|
+
from deapi_sdk.types.websocket import WebSocketConfig, WebSocketConnection
|
|
32
|
+
|
|
33
|
+
__all__ = [
|
|
34
|
+
"Account",
|
|
35
|
+
"ApiKey",
|
|
36
|
+
"ApiKeyCreated",
|
|
37
|
+
"ApiKeysPage",
|
|
38
|
+
"Aud2VideoParams",
|
|
39
|
+
"Balance",
|
|
40
|
+
"EnhancePromptResult",
|
|
41
|
+
"Img2ImgParams",
|
|
42
|
+
"Img2TextParams",
|
|
43
|
+
"Img2VideoParams",
|
|
44
|
+
"JobResult",
|
|
45
|
+
"JobStatusEvent",
|
|
46
|
+
"JobSubmission",
|
|
47
|
+
"LoraWeight",
|
|
48
|
+
"ModelInfo",
|
|
49
|
+
"ModelsResponse",
|
|
50
|
+
"PaginationLinks",
|
|
51
|
+
"PaginationMeta",
|
|
52
|
+
"Payment",
|
|
53
|
+
"PaymentsPage",
|
|
54
|
+
"PriceResult",
|
|
55
|
+
"PromptBoost",
|
|
56
|
+
"Text2AudioParams",
|
|
57
|
+
"Text2EmbeddingParams",
|
|
58
|
+
"Text2ImageParams",
|
|
59
|
+
"Text2MusicParams",
|
|
60
|
+
"Text2VideoParams",
|
|
61
|
+
"TranscribeParams",
|
|
62
|
+
"UsageReport",
|
|
63
|
+
"VideoDescription",
|
|
64
|
+
"VideoEvent",
|
|
65
|
+
"WebSocketConfig",
|
|
66
|
+
"WebSocketConnection",
|
|
67
|
+
"parse_video_description",
|
|
68
|
+
]
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, Field, field_validator
|
|
6
|
+
|
|
7
|
+
from deapi_sdk.types.common import PaginationLinks, PaginationMeta
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AutoTopUp(BaseModel):
|
|
11
|
+
"""Automatic top-up settings: top up ``amount`` when the balance falls to ``threshold``."""
|
|
12
|
+
|
|
13
|
+
enabled: bool | None = None
|
|
14
|
+
threshold: float | None = None
|
|
15
|
+
amount: float | None = None # null when no amount is configured
|
|
16
|
+
|
|
17
|
+
model_config = {"extra": "allow"}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Account(BaseModel):
|
|
21
|
+
"""Account billing (``GET /account``): balance, currency and the ``auto_top_up`` block."""
|
|
22
|
+
|
|
23
|
+
balance: float | None = None
|
|
24
|
+
currency: str | None = None
|
|
25
|
+
auto_top_up: AutoTopUp | None = None
|
|
26
|
+
|
|
27
|
+
model_config = {"extra": "allow"}
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def auto_topup_enabled(self) -> bool | None:
|
|
31
|
+
return self.auto_top_up.enabled if self.auto_top_up else None
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def auto_topup_threshold(self) -> float | None:
|
|
35
|
+
return self.auto_top_up.threshold if self.auto_top_up else None
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def auto_topup_amount(self) -> float | None:
|
|
39
|
+
return self.auto_top_up.amount if self.auto_top_up else None
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class Payment(BaseModel):
|
|
43
|
+
"""One balance top-up (any status)."""
|
|
44
|
+
|
|
45
|
+
id: Any = None
|
|
46
|
+
amount: float | None = None
|
|
47
|
+
currency: str | None = None
|
|
48
|
+
status: str | None = None # pending | paid | disputed | cancelled | failed | expired
|
|
49
|
+
provider: str | None = None
|
|
50
|
+
created_at: str | None = None
|
|
51
|
+
|
|
52
|
+
model_config = {"extra": "allow"}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class PaymentsPage(BaseModel):
|
|
56
|
+
data: list[Payment] = []
|
|
57
|
+
links: PaginationLinks | None = None
|
|
58
|
+
meta: PaginationMeta | None = None
|
|
59
|
+
|
|
60
|
+
model_config = {"extra": "allow"}
|
|
61
|
+
|
|
62
|
+
@field_validator("links", "meta", mode="before")
|
|
63
|
+
@classmethod
|
|
64
|
+
def _lenient(cls, v: Any) -> Any:
|
|
65
|
+
return v if isinstance(v, dict) else None
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class UsageTotals(BaseModel):
|
|
69
|
+
cost: float | None = None
|
|
70
|
+
requests: int | None = None
|
|
71
|
+
errors: int | None = None
|
|
72
|
+
|
|
73
|
+
model_config = {"extra": "allow"}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class UsageGroup(BaseModel):
|
|
77
|
+
"""One bucket of a usage report. ``key`` is a date, type, model slug or key id depending on ``group_by``."""
|
|
78
|
+
|
|
79
|
+
key: str | int | None = None
|
|
80
|
+
name: str | None = None
|
|
81
|
+
cost: float | None = None
|
|
82
|
+
requests: int | None = None
|
|
83
|
+
errors: int | None = None
|
|
84
|
+
|
|
85
|
+
model_config = {"extra": "allow"}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class UsageReport(BaseModel):
|
|
89
|
+
"""Cost, requests and errors over a time window (account-wide or per key).
|
|
90
|
+
|
|
91
|
+
``totals`` holds the grand total and ``groups`` one entry per ``group_by`` bucket. ``cost``,
|
|
92
|
+
``requests`` and ``errors`` are shortcuts to ``totals``. The window is exposed as ``from_`` (the
|
|
93
|
+
JSON field is ``from``) and ``to``.
|
|
94
|
+
"""
|
|
95
|
+
|
|
96
|
+
from_: str | None = Field(default=None, alias="from")
|
|
97
|
+
to: str | None = None
|
|
98
|
+
group_by: str | None = None
|
|
99
|
+
currency: str | None = None
|
|
100
|
+
totals: UsageTotals | None = None
|
|
101
|
+
groups: list[UsageGroup] | None = None
|
|
102
|
+
|
|
103
|
+
model_config = {"extra": "allow", "populate_by_name": True}
|
|
104
|
+
|
|
105
|
+
@property
|
|
106
|
+
def cost(self) -> float | None:
|
|
107
|
+
return self.totals.cost if self.totals else None
|
|
108
|
+
|
|
109
|
+
@property
|
|
110
|
+
def requests(self) -> int | None:
|
|
111
|
+
return self.totals.requests if self.totals else None
|
|
112
|
+
|
|
113
|
+
@property
|
|
114
|
+
def errors(self) -> int | None:
|
|
115
|
+
return self.totals.errors if self.totals else None
|
deapi_sdk/types/audio.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Text2AudioParams(BaseModel):
|
|
7
|
+
text: str
|
|
8
|
+
model: str
|
|
9
|
+
lang: str | None = None
|
|
10
|
+
format: str | None = None
|
|
11
|
+
speed: float | None = None
|
|
12
|
+
sample_rate: float | None = None
|
|
13
|
+
mode: str | None = None
|
|
14
|
+
voice: str | None = None
|
|
15
|
+
ref_text: str | None = None
|
|
16
|
+
instruct: str | None = None
|
|
17
|
+
webhook_url: str | None = None
|
|
18
|
+
webhook_secret: str | None = None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Text2MusicParams(BaseModel):
|
|
22
|
+
caption: str
|
|
23
|
+
model: str
|
|
24
|
+
duration: float
|
|
25
|
+
inference_steps: int | None = None
|
|
26
|
+
guidance_scale: float | None = None
|
|
27
|
+
seed: int | None = None
|
|
28
|
+
format: str | None = None
|
|
29
|
+
lyrics: str | None = None
|
|
30
|
+
bpm: int | None = None
|
|
31
|
+
keyscale: str | None = None
|
|
32
|
+
timesignature: int | None = None
|
|
33
|
+
vocal_language: str | None = None
|
|
34
|
+
webhook_url: str | None = None
|
|
35
|
+
webhook_secret: str | None = None
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, Field, field_validator
|
|
6
|
+
|
|
7
|
+
from deapi_sdk._types import JobStatus
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class JobSubmission(BaseModel):
|
|
11
|
+
request_id: str
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class PromptBoost(BaseModel):
|
|
15
|
+
"""What the inline prompt booster did to the prompt (present only once the boost ran)."""
|
|
16
|
+
|
|
17
|
+
prompt: str | None = None
|
|
18
|
+
prompt_original: str | None = None
|
|
19
|
+
negative_prompt: str | None = None
|
|
20
|
+
negative_prompt_original: str | None = None
|
|
21
|
+
|
|
22
|
+
model_config = {"extra": "allow"}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class JobResult(BaseModel):
|
|
26
|
+
status: JobStatus
|
|
27
|
+
preview: str | None = None
|
|
28
|
+
result_url: str | None = None
|
|
29
|
+
results_alt_formats: dict[str, Any] | None = None
|
|
30
|
+
result: str | None = None
|
|
31
|
+
progress: float | None = 0.0
|
|
32
|
+
# Failure surface (all null unless the job failed)
|
|
33
|
+
error_code: str | None = None # WORKER_TIMEOUT | WORKER_ERROR | PROCESSING_ERROR
|
|
34
|
+
error_reason: str | None = None
|
|
35
|
+
retryable: bool | None = None
|
|
36
|
+
refunded: bool | None = None
|
|
37
|
+
failed_at: str | None = None
|
|
38
|
+
# Actual cost, e.g. {"amount": 0.01, "is_estimated": False}
|
|
39
|
+
price: dict[str, Any] | float | None = None
|
|
40
|
+
metadata: dict[str, Any] | None = None
|
|
41
|
+
prompt_boosted: bool | None = None
|
|
42
|
+
prompt_boost: PromptBoost | None = None
|
|
43
|
+
reference_labels: Any = None # not in the v2 spec (current responses omit it); kept for compatibility
|
|
44
|
+
|
|
45
|
+
model_config = {"extra": "allow"}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class JobStatusEvent(BaseModel):
|
|
49
|
+
"""A real-time job status update delivered over WebSocket (``request.status.updated``).
|
|
50
|
+
|
|
51
|
+
``status`` is ``processing`` (repeated while ``progress`` grows) or ``done``;
|
|
52
|
+
failed jobs are usually not announced over WebSocket. Unknown future statuses are kept
|
|
53
|
+
as plain strings. ``progress`` is a percentage (0-100); the wire format sends
|
|
54
|
+
it as a decimal string, which is converted to ``float``.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
request_id: str
|
|
58
|
+
# left_to_right: known values become JobStatus members instead of plain str
|
|
59
|
+
status: JobStatus | str = Field(union_mode="left_to_right")
|
|
60
|
+
progress: float | None = None
|
|
61
|
+
preview: str | None = None
|
|
62
|
+
result_url: str | None = None
|
|
63
|
+
|
|
64
|
+
model_config = {"extra": "allow"}
|
|
65
|
+
|
|
66
|
+
@field_validator("progress", mode="before")
|
|
67
|
+
@classmethod
|
|
68
|
+
def _parse_progress(cls, value: Any) -> Any:
|
|
69
|
+
if isinstance(value, str):
|
|
70
|
+
value = value.strip()
|
|
71
|
+
if not value:
|
|
72
|
+
return None
|
|
73
|
+
try:
|
|
74
|
+
return float(value)
|
|
75
|
+
except ValueError:
|
|
76
|
+
return None
|
|
77
|
+
return value
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class PriceResult(BaseModel):
|
|
81
|
+
# The spec marks nothing required; ``price`` may be absent when ``estimate_basis`` is "unavailable".
|
|
82
|
+
price: float | None = None
|
|
83
|
+
is_estimated: bool | None = None
|
|
84
|
+
# request_params | model_history | model_default | unavailable (only on estimated quotes)
|
|
85
|
+
estimate_basis: str | None = None
|
|
86
|
+
|
|
87
|
+
model_config = {"extra": "allow"}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class Balance(BaseModel):
|
|
91
|
+
balance: float
|
|
92
|
+
|
|
93
|
+
model_config = {"extra": "allow"}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class PaginationLinks(BaseModel):
|
|
97
|
+
first: str | None = None
|
|
98
|
+
last: str | None = None
|
|
99
|
+
prev: str | None = None
|
|
100
|
+
next: str | None = None
|
|
101
|
+
|
|
102
|
+
model_config = {"extra": "allow"}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class PaginationMeta(BaseModel):
|
|
106
|
+
current_page: int | None = None
|
|
107
|
+
from_: int | None = Field(default=None, alias="from")
|
|
108
|
+
last_page: int | None = None
|
|
109
|
+
per_page: int | None = None
|
|
110
|
+
to: int | None = None
|
|
111
|
+
total: int | None = None
|
|
112
|
+
path: str | None = None
|
|
113
|
+
links: list[dict[str, Any]] | None = None
|
|
114
|
+
|
|
115
|
+
model_config = {"extra": "allow", "populate_by_name": True}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
class ModelInfo(BaseModel):
|
|
119
|
+
name: str
|
|
120
|
+
slug: str
|
|
121
|
+
inference_types: list[str]
|
|
122
|
+
status: str | None = None # standard_model | test_model
|
|
123
|
+
tags: list[str] = []
|
|
124
|
+
info: dict[str, Any] | None = None
|
|
125
|
+
loras: list[dict[str, Any]] | None = None
|
|
126
|
+
languages: list[dict[str, Any]] | None = None
|
|
127
|
+
|
|
128
|
+
model_config = {"extra": "allow"}
|
|
129
|
+
|
|
130
|
+
@field_validator("tags", mode="before")
|
|
131
|
+
@classmethod
|
|
132
|
+
def _normalize_tags(cls, v: Any) -> Any:
|
|
133
|
+
return [] if v is None else v
|
|
134
|
+
|
|
135
|
+
def _info_section(self, key: str) -> dict[str, Any]:
|
|
136
|
+
section = (self.info or {}).get(key)
|
|
137
|
+
return section if isinstance(section, dict) else {}
|
|
138
|
+
|
|
139
|
+
@property
|
|
140
|
+
def limits(self) -> dict[str, Any]:
|
|
141
|
+
"""``info.limits`` (resolution, duration, steps, ...) or ``{}``."""
|
|
142
|
+
return self._info_section("limits")
|
|
143
|
+
|
|
144
|
+
@property
|
|
145
|
+
def features(self) -> dict[str, Any]:
|
|
146
|
+
"""``info.features`` (feature flags such as ``supports_steps``) or ``{}``."""
|
|
147
|
+
return self._info_section("features")
|
|
148
|
+
|
|
149
|
+
@property
|
|
150
|
+
def defaults(self) -> dict[str, Any]:
|
|
151
|
+
"""``info.defaults`` (default parameter values) or ``{}``."""
|
|
152
|
+
return self._info_section("defaults")
|
|
153
|
+
|
|
154
|
+
@field_validator("info", mode="before")
|
|
155
|
+
@classmethod
|
|
156
|
+
def _normalize_info(cls, v: Any) -> Any:
|
|
157
|
+
# PHP/Laravel returns empty arrays as [] instead of {}
|
|
158
|
+
if isinstance(v, list):
|
|
159
|
+
return {} if len(v) == 0 else None
|
|
160
|
+
return v
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
class ModelsResponse(BaseModel):
|
|
164
|
+
data: list[ModelInfo]
|
|
165
|
+
links: PaginationLinks | None = None
|
|
166
|
+
meta: PaginationMeta | None = None
|
|
167
|
+
|
|
168
|
+
model_config = {"extra": "allow"}
|
|
169
|
+
|
|
170
|
+
@field_validator("links", "meta", mode="before")
|
|
171
|
+
@classmethod
|
|
172
|
+
def _lenient_pagination(cls, v: Any) -> Any:
|
|
173
|
+
# PHP may send [] for empty objects; anything non-dict is dropped.
|
|
174
|
+
return v if isinstance(v, dict) else None
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Text2EmbeddingParams(BaseModel):
|
|
7
|
+
input: str | list[str]
|
|
8
|
+
model: str
|
|
9
|
+
return_result_in_response: bool | None = None
|
|
10
|
+
webhook_url: str | None = None
|
|
11
|
+
webhook_secret: str | None = None
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class LoraWeight(BaseModel):
|
|
7
|
+
name: str
|
|
8
|
+
weight: float
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Text2ImageParams(BaseModel):
|
|
12
|
+
prompt: str
|
|
13
|
+
model: str
|
|
14
|
+
width: int | None = None
|
|
15
|
+
height: int | None = None
|
|
16
|
+
seed: int | None = None
|
|
17
|
+
negative_prompt: str | None = None
|
|
18
|
+
loras: list[LoraWeight] | None = None
|
|
19
|
+
guidance: float | None = None
|
|
20
|
+
steps: int | None = None
|
|
21
|
+
quality: str | None = None
|
|
22
|
+
enhance_prompt: bool | None = None
|
|
23
|
+
webhook_url: str | None = None
|
|
24
|
+
webhook_secret: str | None = None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Img2ImgParams(BaseModel):
|
|
28
|
+
prompt: str
|
|
29
|
+
model: str
|
|
30
|
+
steps: int | None = None
|
|
31
|
+
seed: int | None = None
|
|
32
|
+
negative_prompt: str | None = None
|
|
33
|
+
loras: list[LoraWeight] | None = None
|
|
34
|
+
width: int | None = None
|
|
35
|
+
height: int | None = None
|
|
36
|
+
guidance: float | None = None
|
|
37
|
+
quality: str | None = None
|
|
38
|
+
enhance_prompt: bool | None = None
|
|
39
|
+
webhook_url: str | None = None
|
|
40
|
+
webhook_secret: str | None = None
|
deapi_sdk/types/keys.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, field_validator
|
|
6
|
+
|
|
7
|
+
from deapi_sdk.types.common import PaginationLinks, PaginationMeta
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ApiKey(BaseModel):
|
|
11
|
+
"""An API key as returned by ``GET /key``, ``GET /keys`` and ``GET /keys/{id}``. Never contains the secret."""
|
|
12
|
+
|
|
13
|
+
id: int
|
|
14
|
+
name: str | None = None
|
|
15
|
+
preview: str | None = None
|
|
16
|
+
role: str | None = None # admin | api
|
|
17
|
+
status: str | None = None # active | revoked (disabled) | expired
|
|
18
|
+
created_at: str | None = None
|
|
19
|
+
expires_at: str | None = None
|
|
20
|
+
last_used_at: str | None = None
|
|
21
|
+
ip_whitelist: list[str] = []
|
|
22
|
+
ip_whitelist_count: int | None = None
|
|
23
|
+
limit: float | None = None
|
|
24
|
+
reset_interval: str | None = None
|
|
25
|
+
limit_used: float | None = None
|
|
26
|
+
limit_remaining: float | None = None
|
|
27
|
+
limit_resets_at: str | None = None
|
|
28
|
+
|
|
29
|
+
model_config = {"extra": "allow"}
|
|
30
|
+
|
|
31
|
+
@field_validator("ip_whitelist", mode="before")
|
|
32
|
+
@classmethod
|
|
33
|
+
def _norm_ip(cls, v: Any) -> Any:
|
|
34
|
+
return [] if v is None else v
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ApiKeyCreated(ApiKey):
|
|
38
|
+
"""Response of ``POST /keys``. ``secret`` is shown ONCE; store it immediately."""
|
|
39
|
+
|
|
40
|
+
secret: str | None = None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class ApiKeysPage(BaseModel):
|
|
44
|
+
data: list[ApiKey] = []
|
|
45
|
+
links: PaginationLinks | None = None
|
|
46
|
+
meta: PaginationMeta | None = None
|
|
47
|
+
|
|
48
|
+
model_config = {"extra": "allow"}
|
|
49
|
+
|
|
50
|
+
@field_validator("links", "meta", mode="before")
|
|
51
|
+
@classmethod
|
|
52
|
+
def _lenient(cls, v: Any) -> Any:
|
|
53
|
+
return v if isinstance(v, dict) else None
|
deapi_sdk/types/ocr.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Img2TextParams(BaseModel):
|
|
7
|
+
"""Parameters for image-to-text (OCR) requests."""
|
|
8
|
+
|
|
9
|
+
model: str
|
|
10
|
+
language: str | None = None
|
|
11
|
+
format: str | None = None
|
|
12
|
+
return_result_in_response: bool | None = None
|
|
13
|
+
webhook_url: str | None = None
|
|
14
|
+
webhook_secret: str | None = None
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
# Inference types the prompt booster accepts (dot notation). Upscaling, background
|
|
8
|
+
# removal, OCR, transcription and embeddings have no booster and are rejected with 422.
|
|
9
|
+
PromptBoosterType = Literal[
|
|
10
|
+
"images.generations",
|
|
11
|
+
"images.edits",
|
|
12
|
+
"videos.generations",
|
|
13
|
+
"videos.animations",
|
|
14
|
+
"audio.speech",
|
|
15
|
+
"audio.music",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
# Types that need a reference ``image`` alongside the prompt.
|
|
19
|
+
PROMPT_BOOSTER_TYPES_REQUIRING_IMAGE = ("images.edits", "videos.animations")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class EnhancePromptResult(BaseModel):
|
|
23
|
+
"""Result of the prompt enhancement endpoint."""
|
|
24
|
+
prompt: str
|
|
25
|
+
negative_prompt: str | None = None
|
|
26
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TranscribeParams(BaseModel):
|
|
7
|
+
"""Params for the unified transcribe endpoint."""
|
|
8
|
+
include_ts: bool
|
|
9
|
+
model: str
|
|
10
|
+
source_url: str | None = None
|
|
11
|
+
source_file: str | None = None
|
|
12
|
+
return_result_in_response: bool | None = None
|
|
13
|
+
webhook_url: str | None = None
|
|
14
|
+
|