genblaze-atlascloudai 0.1.0__tar.gz
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.
- genblaze_atlascloudai-0.1.0/.gitignore +85 -0
- genblaze_atlascloudai-0.1.0/PKG-INFO +75 -0
- genblaze_atlascloudai-0.1.0/README.md +50 -0
- genblaze_atlascloudai-0.1.0/genblaze_atlascloud/__init__.py +6 -0
- genblaze_atlascloudai-0.1.0/genblaze_atlascloud/_errors.py +24 -0
- genblaze_atlascloudai-0.1.0/genblaze_atlascloud/_version.py +8 -0
- genblaze_atlascloudai-0.1.0/genblaze_atlascloud/provider.py +240 -0
- genblaze_atlascloudai-0.1.0/genblaze_atlascloud/py.typed +1 -0
- genblaze_atlascloudai-0.1.0/pyproject.toml +47 -0
- genblaze_atlascloudai-0.1.0/tests/__init__.py +1 -0
- genblaze_atlascloudai-0.1.0/tests/test_atlascloud_provider.py +151 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
|
|
7
|
+
# Distribution / packaging
|
|
8
|
+
dist/
|
|
9
|
+
build/
|
|
10
|
+
*.egg-info/
|
|
11
|
+
*.egg
|
|
12
|
+
wheels/
|
|
13
|
+
/MANIFEST
|
|
14
|
+
|
|
15
|
+
# Virtual environments
|
|
16
|
+
.venv/
|
|
17
|
+
venv/
|
|
18
|
+
env/
|
|
19
|
+
ENV/
|
|
20
|
+
|
|
21
|
+
# IDE / editors
|
|
22
|
+
.vscode/
|
|
23
|
+
.idea/
|
|
24
|
+
*.swp
|
|
25
|
+
*.swo
|
|
26
|
+
*~
|
|
27
|
+
.project
|
|
28
|
+
.settings/
|
|
29
|
+
|
|
30
|
+
# Testing / coverage
|
|
31
|
+
.pytest_cache/
|
|
32
|
+
.coverage
|
|
33
|
+
.coverage.*
|
|
34
|
+
htmlcov/
|
|
35
|
+
coverage.xml
|
|
36
|
+
*.cover
|
|
37
|
+
|
|
38
|
+
# Type checking
|
|
39
|
+
.mypy_cache/
|
|
40
|
+
.pytype/
|
|
41
|
+
.pyre/
|
|
42
|
+
|
|
43
|
+
# Linting
|
|
44
|
+
.ruff_cache/
|
|
45
|
+
|
|
46
|
+
# OS files
|
|
47
|
+
.DS_Store
|
|
48
|
+
Thumbs.db
|
|
49
|
+
ehthumbs.db
|
|
50
|
+
|
|
51
|
+
# Environment / secrets
|
|
52
|
+
.env
|
|
53
|
+
.env.*
|
|
54
|
+
!.env.example
|
|
55
|
+
*.pem
|
|
56
|
+
*.key
|
|
57
|
+
credentials*
|
|
58
|
+
*.credentials
|
|
59
|
+
*_rsa
|
|
60
|
+
*.p12
|
|
61
|
+
*.pfx
|
|
62
|
+
*.keystore
|
|
63
|
+
|
|
64
|
+
# Jupyter
|
|
65
|
+
.ipynb_checkpoints/
|
|
66
|
+
|
|
67
|
+
# MkDocs build output
|
|
68
|
+
site/
|
|
69
|
+
|
|
70
|
+
# Claude Code — local/ephemeral
|
|
71
|
+
.claude/settings.local.json
|
|
72
|
+
.claude/worktrees/
|
|
73
|
+
CLAUDE.local.md
|
|
74
|
+
|
|
75
|
+
# Hypothesis test cache
|
|
76
|
+
.hypothesis/
|
|
77
|
+
|
|
78
|
+
# Temp files
|
|
79
|
+
*.tmp
|
|
80
|
+
*.bak
|
|
81
|
+
*.log
|
|
82
|
+
.pre-pr-check/
|
|
83
|
+
pre-pr-check-findings-batch-*.md
|
|
84
|
+
# Node (libs/spec type-generation toolchain)
|
|
85
|
+
node_modules/
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: genblaze-atlascloudai
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Atlas Cloud image and video provider adapter for genblaze
|
|
5
|
+
Project-URL: Homepage, https://github.com/backblaze-labs/genblaze
|
|
6
|
+
Project-URL: Documentation, https://github.com/backblaze-labs/genblaze
|
|
7
|
+
Project-URL: Repository, https://github.com/backblaze-labs/genblaze
|
|
8
|
+
Project-URL: Issues, https://github.com/backblaze-labs/genblaze/issues
|
|
9
|
+
Author: genblaze contributors
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
Keywords: atlascloud,genblaze,image,media,provenance,video
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Topic :: Multimedia
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Requires-Dist: genblaze-core<0.4,>=0.3.8
|
|
21
|
+
Requires-Dist: httpx<1,>=0.24
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# genblaze-atlascloudai
|
|
27
|
+
|
|
28
|
+
Atlas Cloud image and video generation adapter for
|
|
29
|
+
[genblaze](https://github.com/backblaze-labs/genblaze). The connector uses the
|
|
30
|
+
Atlas Cloud asynchronous prediction API and keeps Atlas Cloud fully opt-in.
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install genblaze-atlascloudai
|
|
36
|
+
export ATLASCLOUD_API_KEY="..."
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from genblaze_atlascloud import AtlasCloudProvider
|
|
43
|
+
from genblaze_core import Modality, Pipeline
|
|
44
|
+
|
|
45
|
+
run, manifest = (
|
|
46
|
+
Pipeline("atlascloud-image")
|
|
47
|
+
.step(
|
|
48
|
+
AtlasCloudProvider(),
|
|
49
|
+
model="bytedance/seedream-v5.0-lite",
|
|
50
|
+
prompt="A product photograph on a clean studio background",
|
|
51
|
+
modality=Modality.IMAGE,
|
|
52
|
+
size="2048*2048",
|
|
53
|
+
output_format="png",
|
|
54
|
+
)
|
|
55
|
+
.run(timeout=300)
|
|
56
|
+
)
|
|
57
|
+
print(run.steps[0].assets[0].url, manifest.canonical_hash)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Use `Modality.VIDEO` with a video model such as
|
|
61
|
+
`bytedance/seedance-2.0/text-to-video`. Model-specific parameters are passed
|
|
62
|
+
through unchanged after URL-bearing inputs are validated.
|
|
63
|
+
|
|
64
|
+
## Reliability
|
|
65
|
+
|
|
66
|
+
Submission is never retried automatically because a failed response can still
|
|
67
|
+
represent a billable generation. Prediction GET requests use a small bounded
|
|
68
|
+
retry with backoff for transient transport failures.
|
|
69
|
+
|
|
70
|
+
Current model IDs and schemas are available from the
|
|
71
|
+
[Atlas Cloud model catalog](https://www.atlascloud.ai/models).
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# genblaze-atlascloudai
|
|
2
|
+
|
|
3
|
+
Atlas Cloud image and video generation adapter for
|
|
4
|
+
[genblaze](https://github.com/backblaze-labs/genblaze). The connector uses the
|
|
5
|
+
Atlas Cloud asynchronous prediction API and keeps Atlas Cloud fully opt-in.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install genblaze-atlascloudai
|
|
11
|
+
export ATLASCLOUD_API_KEY="..."
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
from genblaze_atlascloud import AtlasCloudProvider
|
|
18
|
+
from genblaze_core import Modality, Pipeline
|
|
19
|
+
|
|
20
|
+
run, manifest = (
|
|
21
|
+
Pipeline("atlascloud-image")
|
|
22
|
+
.step(
|
|
23
|
+
AtlasCloudProvider(),
|
|
24
|
+
model="bytedance/seedream-v5.0-lite",
|
|
25
|
+
prompt="A product photograph on a clean studio background",
|
|
26
|
+
modality=Modality.IMAGE,
|
|
27
|
+
size="2048*2048",
|
|
28
|
+
output_format="png",
|
|
29
|
+
)
|
|
30
|
+
.run(timeout=300)
|
|
31
|
+
)
|
|
32
|
+
print(run.steps[0].assets[0].url, manifest.canonical_hash)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Use `Modality.VIDEO` with a video model such as
|
|
36
|
+
`bytedance/seedance-2.0/text-to-video`. Model-specific parameters are passed
|
|
37
|
+
through unchanged after URL-bearing inputs are validated.
|
|
38
|
+
|
|
39
|
+
## Reliability
|
|
40
|
+
|
|
41
|
+
Submission is never retried automatically because a failed response can still
|
|
42
|
+
represent a billable generation. Prediction GET requests use a small bounded
|
|
43
|
+
retry with backoff for transient transport failures.
|
|
44
|
+
|
|
45
|
+
Current model IDs and schemas are available from the
|
|
46
|
+
[Atlas Cloud model catalog](https://www.atlascloud.ai/models).
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
MIT
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Error mapping for the Atlas Cloud connector."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
from genblaze_core.models.enums import ProviderErrorCode
|
|
7
|
+
from genblaze_core.providers.base import classify_api_error
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def map_atlascloud_error(exc: Exception) -> ProviderErrorCode:
|
|
11
|
+
"""Map Atlas Cloud and transport failures to genblaze error codes."""
|
|
12
|
+
if isinstance(exc, httpx.TimeoutException):
|
|
13
|
+
return ProviderErrorCode.TIMEOUT
|
|
14
|
+
if isinstance(exc, httpx.HTTPStatusError):
|
|
15
|
+
status = exc.response.status_code
|
|
16
|
+
if status in (401, 403):
|
|
17
|
+
return ProviderErrorCode.AUTH_FAILURE
|
|
18
|
+
if status == 429:
|
|
19
|
+
return ProviderErrorCode.RATE_LIMIT
|
|
20
|
+
if status in (400, 422):
|
|
21
|
+
return ProviderErrorCode.INVALID_INPUT
|
|
22
|
+
if status >= 500:
|
|
23
|
+
return ProviderErrorCode.SERVER_ERROR
|
|
24
|
+
return classify_api_error(exc)
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"""Atlas Cloud image and video generation provider.
|
|
2
|
+
|
|
3
|
+
Atlas Cloud exposes one asynchronous prediction contract across its media
|
|
4
|
+
catalog: submit an image or video request, then poll the returned prediction.
|
|
5
|
+
The connector deliberately never retries submission. A transport failure after
|
|
6
|
+
a POST is ambiguous, and automatically submitting again could create a second
|
|
7
|
+
billable generation.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
import time
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
import httpx
|
|
17
|
+
from genblaze_core.exceptions import ProviderError
|
|
18
|
+
from genblaze_core.models.asset import Asset
|
|
19
|
+
from genblaze_core.models.enums import Modality, ProviderErrorCode
|
|
20
|
+
from genblaze_core.models.step import Step
|
|
21
|
+
from genblaze_core.providers import (
|
|
22
|
+
BaseProvider,
|
|
23
|
+
DiscoverySupport,
|
|
24
|
+
ModelRegistry,
|
|
25
|
+
ProviderCapabilities,
|
|
26
|
+
RetryPolicy,
|
|
27
|
+
validate_asset_url,
|
|
28
|
+
validate_chain_input_url,
|
|
29
|
+
)
|
|
30
|
+
from genblaze_core.providers.retry import retry_after_from_response
|
|
31
|
+
from genblaze_core.runnable.config import RunnableConfig
|
|
32
|
+
|
|
33
|
+
from ._errors import map_atlascloud_error
|
|
34
|
+
|
|
35
|
+
_DEFAULT_BASE_URL = "https://api.atlascloud.ai"
|
|
36
|
+
_TERMINAL_STATUSES = frozenset({"completed", "succeeded", "failed", "timeout", "canceled"})
|
|
37
|
+
_FAILED_STATUSES = frozenset({"failed", "timeout", "canceled"})
|
|
38
|
+
_URL_PARAM_KEYS = frozenset(
|
|
39
|
+
{"image", "image_url", "images", "video", "video_url", "audio", "audio_url"}
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _unwrap_response(response: httpx.Response) -> dict[str, Any]:
|
|
44
|
+
response.raise_for_status()
|
|
45
|
+
payload = response.json()
|
|
46
|
+
if not isinstance(payload, dict):
|
|
47
|
+
raise ValueError("Atlas Cloud returned a non-object response")
|
|
48
|
+
if payload.get("code") not in (None, 0, 200):
|
|
49
|
+
message = payload.get("message") or payload.get("msg") or "unknown API error"
|
|
50
|
+
raise ValueError(f"Atlas Cloud API error: {message}")
|
|
51
|
+
data = payload.get("data", payload)
|
|
52
|
+
if not isinstance(data, dict):
|
|
53
|
+
raise ValueError("Atlas Cloud response data is not an object")
|
|
54
|
+
return data
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _validate_url_params(params: dict[str, Any]) -> None:
|
|
58
|
+
for key in _URL_PARAM_KEYS:
|
|
59
|
+
value = params.get(key)
|
|
60
|
+
values = value if isinstance(value, list) else [value]
|
|
61
|
+
for item in values:
|
|
62
|
+
if isinstance(item, str) and item:
|
|
63
|
+
validate_chain_input_url(item)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class AtlasCloudProvider(BaseProvider):
|
|
67
|
+
"""Opt-in Atlas Cloud adapter for image and video generation.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
api_key: Atlas Cloud API key. Defaults to ``ATLASCLOUD_API_KEY``.
|
|
71
|
+
base_url: API origin. Defaults to ``https://api.atlascloud.ai``.
|
|
72
|
+
poll_interval: Initial seconds between prediction polls.
|
|
73
|
+
poll_get_retries: Bounded retries for transient prediction GET failures.
|
|
74
|
+
http_timeout: Per-request HTTP timeout in seconds.
|
|
75
|
+
http_client: Optional injected client, primarily for tests.
|
|
76
|
+
models: Optional custom model registry.
|
|
77
|
+
retry_policy: Optional core retry policy. The default has one attempt so
|
|
78
|
+
the core never repeats a potentially billable POST.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
name = "atlascloud"
|
|
82
|
+
discovery_support = DiscoverySupport.NONE
|
|
83
|
+
|
|
84
|
+
def __init__(
|
|
85
|
+
self,
|
|
86
|
+
api_key: str | None = None,
|
|
87
|
+
*,
|
|
88
|
+
base_url: str = _DEFAULT_BASE_URL,
|
|
89
|
+
poll_interval: float = 3.0,
|
|
90
|
+
poll_get_retries: int = 2,
|
|
91
|
+
http_timeout: float = 120.0,
|
|
92
|
+
http_client: httpx.Client | None = None,
|
|
93
|
+
models: ModelRegistry | None = None,
|
|
94
|
+
retry_policy: RetryPolicy | None = None,
|
|
95
|
+
probe_cache_ttl: float | None = None,
|
|
96
|
+
probe_cache_max_entries: int | None = None,
|
|
97
|
+
) -> None:
|
|
98
|
+
if poll_get_retries < 0:
|
|
99
|
+
raise ValueError("poll_get_retries must be >= 0")
|
|
100
|
+
super().__init__(
|
|
101
|
+
models=models,
|
|
102
|
+
retry_policy=retry_policy or RetryPolicy(max_attempts=1),
|
|
103
|
+
probe_cache_ttl=probe_cache_ttl,
|
|
104
|
+
probe_cache_max_entries=probe_cache_max_entries,
|
|
105
|
+
)
|
|
106
|
+
self.poll_interval = poll_interval
|
|
107
|
+
self.poll_get_retries = poll_get_retries
|
|
108
|
+
self._api_key = api_key or os.getenv("ATLASCLOUD_API_KEY")
|
|
109
|
+
self._base_url = base_url.rstrip("/")
|
|
110
|
+
self._client = http_client or httpx.Client(timeout=http_timeout)
|
|
111
|
+
|
|
112
|
+
def get_capabilities(self) -> ProviderCapabilities:
|
|
113
|
+
return ProviderCapabilities(
|
|
114
|
+
supported_modalities=[Modality.IMAGE, Modality.VIDEO],
|
|
115
|
+
supported_inputs=["text", "image", "video", "audio"],
|
|
116
|
+
accepts_chain_input=False,
|
|
117
|
+
models=self._models.known(),
|
|
118
|
+
output_formats=["image/jpeg", "image/png", "video/mp4"],
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
def _headers(self) -> dict[str, str]:
|
|
122
|
+
if not self._api_key:
|
|
123
|
+
raise ProviderError(
|
|
124
|
+
"Atlas Cloud API key is required. Set ATLASCLOUD_API_KEY or pass api_key.",
|
|
125
|
+
error_code=ProviderErrorCode.AUTH_FAILURE,
|
|
126
|
+
)
|
|
127
|
+
return {
|
|
128
|
+
"Authorization": f"Bearer {self._api_key}",
|
|
129
|
+
"Content-Type": "application/json",
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
def _endpoint_for(self, step: Step) -> str:
|
|
133
|
+
if step.modality == Modality.IMAGE:
|
|
134
|
+
return "/api/v1/model/generateImage"
|
|
135
|
+
if step.modality == Modality.VIDEO:
|
|
136
|
+
return "/api/v1/model/generateVideo"
|
|
137
|
+
raise ProviderError(
|
|
138
|
+
"Atlas Cloud generation requires modality=Modality.IMAGE or Modality.VIDEO",
|
|
139
|
+
error_code=ProviderErrorCode.INVALID_INPUT,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
def submit(self, step: Step, config: RunnableConfig | None = None) -> Any:
|
|
143
|
+
"""Submit exactly one generation request; this method never retries."""
|
|
144
|
+
params = dict(step.params)
|
|
145
|
+
_validate_url_params(params)
|
|
146
|
+
payload = {**params, "model": step.model, "prompt": step.prompt or ""}
|
|
147
|
+
try:
|
|
148
|
+
response = self._client.post(
|
|
149
|
+
f"{self._base_url}{self._endpoint_for(step)}",
|
|
150
|
+
headers=self._headers(),
|
|
151
|
+
json=payload,
|
|
152
|
+
)
|
|
153
|
+
data = _unwrap_response(response)
|
|
154
|
+
prediction_id = data.get("id") or data.get("request_id")
|
|
155
|
+
if not prediction_id:
|
|
156
|
+
raise ValueError("Atlas Cloud submit response did not include a prediction id")
|
|
157
|
+
return str(prediction_id)
|
|
158
|
+
except ProviderError:
|
|
159
|
+
raise
|
|
160
|
+
except Exception as exc:
|
|
161
|
+
raise ProviderError(
|
|
162
|
+
f"Atlas Cloud submit failed: {exc}",
|
|
163
|
+
error_code=map_atlascloud_error(exc),
|
|
164
|
+
retry_after=retry_after_from_response(exc),
|
|
165
|
+
) from exc
|
|
166
|
+
|
|
167
|
+
def _get_prediction(self, prediction_id: Any) -> dict[str, Any]:
|
|
168
|
+
last_error: Exception | None = None
|
|
169
|
+
for attempt in range(self.poll_get_retries + 1):
|
|
170
|
+
try:
|
|
171
|
+
response = self._client.get(
|
|
172
|
+
f"{self._base_url}/api/v1/model/prediction/{prediction_id}",
|
|
173
|
+
headers=self._headers(),
|
|
174
|
+
)
|
|
175
|
+
return _unwrap_response(response)
|
|
176
|
+
except (httpx.TimeoutException, httpx.NetworkError, httpx.RemoteProtocolError) as exc:
|
|
177
|
+
last_error = exc
|
|
178
|
+
if attempt == self.poll_get_retries:
|
|
179
|
+
break
|
|
180
|
+
time.sleep(min(0.25 * (2**attempt), 1.0))
|
|
181
|
+
assert last_error is not None
|
|
182
|
+
raise last_error
|
|
183
|
+
|
|
184
|
+
def poll(self, prediction_id: Any, config: RunnableConfig | None = None) -> bool:
|
|
185
|
+
try:
|
|
186
|
+
data = self._get_prediction(prediction_id)
|
|
187
|
+
status = str(data.get("status", "")).lower()
|
|
188
|
+
if status in _TERMINAL_STATUSES:
|
|
189
|
+
self._cache_poll_result(prediction_id, data)
|
|
190
|
+
return True
|
|
191
|
+
return False
|
|
192
|
+
except ProviderError:
|
|
193
|
+
raise
|
|
194
|
+
except Exception as exc:
|
|
195
|
+
raise ProviderError(
|
|
196
|
+
f"Atlas Cloud poll failed: {exc}",
|
|
197
|
+
error_code=map_atlascloud_error(exc),
|
|
198
|
+
retry_after=retry_after_from_response(exc),
|
|
199
|
+
) from exc
|
|
200
|
+
|
|
201
|
+
def fetch_output(self, prediction_id: Any, step: Step) -> Step:
|
|
202
|
+
try:
|
|
203
|
+
data = self._get_cached_poll_result(prediction_id)
|
|
204
|
+
if data is None:
|
|
205
|
+
data = self._get_prediction(prediction_id)
|
|
206
|
+
status = str(data.get("status", "")).lower()
|
|
207
|
+
if status in _FAILED_STATUSES:
|
|
208
|
+
message = data.get("error") or data.get("message") or status
|
|
209
|
+
raise ProviderError(
|
|
210
|
+
f"Atlas Cloud generation failed: {message}",
|
|
211
|
+
error_code=ProviderErrorCode.MODEL_ERROR,
|
|
212
|
+
)
|
|
213
|
+
outputs = data.get("outputs") or data.get("output") or []
|
|
214
|
+
if isinstance(outputs, str):
|
|
215
|
+
outputs = [outputs]
|
|
216
|
+
if not isinstance(outputs, list) or not outputs:
|
|
217
|
+
raise ProviderError(
|
|
218
|
+
"Atlas Cloud completed without output URLs",
|
|
219
|
+
error_code=ProviderErrorCode.MODEL_ERROR,
|
|
220
|
+
)
|
|
221
|
+
media_type = "video/mp4" if step.modality == Modality.VIDEO else "image/jpeg"
|
|
222
|
+
for url in outputs:
|
|
223
|
+
if not isinstance(url, str):
|
|
224
|
+
continue
|
|
225
|
+
validate_asset_url(url)
|
|
226
|
+
step.assets.append(Asset(url=url, media_type=media_type))
|
|
227
|
+
step.provider_payload = {
|
|
228
|
+
"atlascloud": {
|
|
229
|
+
"prediction_id": str(prediction_id),
|
|
230
|
+
"status": status,
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return step
|
|
234
|
+
except ProviderError:
|
|
235
|
+
raise
|
|
236
|
+
except Exception as exc:
|
|
237
|
+
raise ProviderError(
|
|
238
|
+
f"Atlas Cloud output fetch failed: {exc}",
|
|
239
|
+
error_code=map_atlascloud_error(exc),
|
|
240
|
+
) from exc
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "genblaze-atlascloudai"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Atlas Cloud image and video provider adapter for genblaze"
|
|
9
|
+
authors = [{name = "genblaze contributors"}]
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
|
+
license = "MIT"
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
"Typing :: Typed",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Topic :: Multimedia",
|
|
20
|
+
"Topic :: Software Development :: Libraries",
|
|
21
|
+
]
|
|
22
|
+
keywords = ["genblaze", "atlascloud", "image", "video", "media", "provenance"]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"genblaze-core>=0.3.8,<0.4",
|
|
25
|
+
"httpx>=0.24,<1",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/backblaze-labs/genblaze"
|
|
30
|
+
Documentation = "https://github.com/backblaze-labs/genblaze"
|
|
31
|
+
Repository = "https://github.com/backblaze-labs/genblaze"
|
|
32
|
+
Issues = "https://github.com/backblaze-labs/genblaze/issues"
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
dev = ["pytest>=7.0"]
|
|
36
|
+
|
|
37
|
+
[project.entry-points."genblaze.providers"]
|
|
38
|
+
atlascloud = "genblaze_atlascloud:AtlasCloudProvider"
|
|
39
|
+
|
|
40
|
+
[tool.hatch.build.targets.wheel]
|
|
41
|
+
packages = ["genblaze_atlascloud"]
|
|
42
|
+
|
|
43
|
+
[tool.pytest.ini_options]
|
|
44
|
+
testpaths = ["tests"]
|
|
45
|
+
|
|
46
|
+
[tool.deptry]
|
|
47
|
+
optional_dependencies_dev_groups = ["dev"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"""Tests for AtlasCloudProvider (mocked; no billable requests)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
import pytest
|
|
7
|
+
from genblaze_atlascloud import AtlasCloudProvider
|
|
8
|
+
from genblaze_core.exceptions import ProviderError
|
|
9
|
+
from genblaze_core.models.enums import Modality, ProviderErrorCode, StepStatus
|
|
10
|
+
from genblaze_core.models.step import Step
|
|
11
|
+
from genblaze_core.testing import ProviderComplianceTests
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _client(handler):
|
|
15
|
+
return httpx.Client(transport=httpx.MockTransport(handler))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _provider(handler, **kwargs):
|
|
19
|
+
return AtlasCloudProvider(api_key="test-key", http_client=_client(handler), **kwargs)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_image_submit_uses_image_endpoint_and_does_not_leak_key():
|
|
23
|
+
seen = {}
|
|
24
|
+
|
|
25
|
+
def handler(request):
|
|
26
|
+
seen["request"] = request
|
|
27
|
+
return httpx.Response(200, json={"code": 200, "data": {"id": "pred-1"}})
|
|
28
|
+
|
|
29
|
+
provider = _provider(handler)
|
|
30
|
+
step = Step(
|
|
31
|
+
provider="atlascloud",
|
|
32
|
+
model="bytedance/seedream-v5.0-lite",
|
|
33
|
+
modality=Modality.IMAGE,
|
|
34
|
+
prompt="studio photo",
|
|
35
|
+
params={"size": "2048*2048"},
|
|
36
|
+
)
|
|
37
|
+
assert provider.submit(step) == "pred-1"
|
|
38
|
+
request = seen["request"]
|
|
39
|
+
assert request.url.path.endswith("/generateImage")
|
|
40
|
+
assert request.headers["authorization"] == "Bearer test-key"
|
|
41
|
+
assert b"test-key" not in request.content
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_video_submit_uses_video_endpoint():
|
|
45
|
+
def handler(request):
|
|
46
|
+
assert request.url.path.endswith("/generateVideo")
|
|
47
|
+
return httpx.Response(200, json={"data": {"id": "pred-2"}})
|
|
48
|
+
|
|
49
|
+
step = Step(
|
|
50
|
+
provider="atlascloud",
|
|
51
|
+
model="bytedance/seedance-2.0/text-to-video",
|
|
52
|
+
modality=Modality.VIDEO,
|
|
53
|
+
prompt="ocean waves",
|
|
54
|
+
)
|
|
55
|
+
assert _provider(handler).submit(step) == "pred-2"
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_submit_is_single_attempt_on_transport_failure():
|
|
59
|
+
attempts = 0
|
|
60
|
+
|
|
61
|
+
def handler(request):
|
|
62
|
+
nonlocal attempts
|
|
63
|
+
attempts += 1
|
|
64
|
+
raise httpx.ReadTimeout("ambiguous POST timeout", request=request)
|
|
65
|
+
|
|
66
|
+
provider = _provider(handler)
|
|
67
|
+
step = Step(provider="atlascloud", model="image-model", modality=Modality.IMAGE)
|
|
68
|
+
result = provider.invoke(step)
|
|
69
|
+
assert result.status == StepStatus.FAILED
|
|
70
|
+
assert result.error_code == ProviderErrorCode.TIMEOUT
|
|
71
|
+
assert attempts == 1
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_poll_and_fetch_output_share_terminal_response():
|
|
75
|
+
requests = 0
|
|
76
|
+
|
|
77
|
+
def handler(request):
|
|
78
|
+
nonlocal requests
|
|
79
|
+
requests += 1
|
|
80
|
+
return httpx.Response(
|
|
81
|
+
200,
|
|
82
|
+
json={
|
|
83
|
+
"code": 200,
|
|
84
|
+
"data": {
|
|
85
|
+
"id": "pred-3",
|
|
86
|
+
"status": "completed",
|
|
87
|
+
"outputs": ["https://cdn.atlascloud.ai/result.png"],
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
provider = _provider(handler)
|
|
93
|
+
assert provider.poll("pred-3") is True
|
|
94
|
+
step = Step(provider="atlascloud", model="image-model", modality=Modality.IMAGE)
|
|
95
|
+
result = provider.fetch_output("pred-3", step)
|
|
96
|
+
assert requests == 1
|
|
97
|
+
assert result.assets[0].url == "https://cdn.atlascloud.ai/result.png"
|
|
98
|
+
assert result.assets[0].media_type == "image/jpeg"
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def test_rejects_non_https_input_url_before_submit():
|
|
102
|
+
provider = _provider(lambda request: pytest.fail("request should not be sent"))
|
|
103
|
+
step = Step(
|
|
104
|
+
provider="atlascloud",
|
|
105
|
+
model="edit-model",
|
|
106
|
+
modality=Modality.IMAGE,
|
|
107
|
+
params={"image_url": "http://127.0.0.1/private.png"},
|
|
108
|
+
)
|
|
109
|
+
with pytest.raises(ProviderError):
|
|
110
|
+
provider.submit(step)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def test_missing_key_fails_before_request():
|
|
114
|
+
provider = AtlasCloudProvider(api_key="", http_client=_client(lambda request: None))
|
|
115
|
+
provider._api_key = None
|
|
116
|
+
step = Step(provider="atlascloud", model="image-model", modality=Modality.IMAGE)
|
|
117
|
+
with pytest.raises(ProviderError, match="ATLASCLOUD_API_KEY"):
|
|
118
|
+
provider.submit(step)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class TestAtlasCloudCompliance(ProviderComplianceTests):
|
|
122
|
+
expects_cost = False
|
|
123
|
+
|
|
124
|
+
def make_provider(self):
|
|
125
|
+
def handler(request):
|
|
126
|
+
if request.method == "POST":
|
|
127
|
+
return httpx.Response(200, json={"data": {"id": "pred-ok"}})
|
|
128
|
+
return httpx.Response(
|
|
129
|
+
200,
|
|
130
|
+
json={
|
|
131
|
+
"data": {
|
|
132
|
+
"id": "pred-ok",
|
|
133
|
+
"status": "completed",
|
|
134
|
+
"outputs": ["https://cdn.atlascloud.ai/result.png"],
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
return _provider(handler, poll_interval=0)
|
|
140
|
+
|
|
141
|
+
def make_step(self):
|
|
142
|
+
return Step(
|
|
143
|
+
provider="atlascloud",
|
|
144
|
+
model="bytedance/seedream-v5.0-lite",
|
|
145
|
+
modality=Modality.IMAGE,
|
|
146
|
+
prompt="test prompt",
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
def test_full_lifecycle(self):
|
|
150
|
+
result = self.make_provider().invoke(self.make_step())
|
|
151
|
+
assert result.status == StepStatus.SUCCEEDED
|