llamagen-python 0.1.5__tar.gz → 0.1.7__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.
- llamagen_python-0.1.7/PKG-INFO +403 -0
- llamagen_python-0.1.7/README.md +378 -0
- llamagen_python-0.1.7/examples/Untitled.ipynb +84 -0
- llamagen_python-0.1.7/examples/quickstart.py +171 -0
- {llamagen_python-0.1.5 → llamagen_python-0.1.7}/pyproject.toml +1 -1
- {llamagen_python-0.1.5 → llamagen_python-0.1.7}/src/llamagen/__init__.py +1 -6
- llamagen_python-0.1.7/src/llamagen/_errors.py +65 -0
- {llamagen_python-0.1.5 → llamagen_python-0.1.7}/src/llamagen/_http.py +1 -1
- {llamagen_python-0.1.5 → llamagen_python-0.1.7}/src/llamagen/_types.py +1 -5
- {llamagen_python-0.1.5 → llamagen_python-0.1.7}/src/llamagen/resources/animations.py +3 -5
- {llamagen_python-0.1.5 → llamagen_python-0.1.7}/src/llamagen/resources/comics.py +4 -67
- {llamagen_python-0.1.5 → llamagen_python-0.1.7}/tests/test_client.py +62 -2
- llamagen_python-0.1.5/PKG-INFO +0 -186
- llamagen_python-0.1.5/README.md +0 -161
- llamagen_python-0.1.5/examples/quickstart.py +0 -40
- llamagen_python-0.1.5/src/llamagen/_errors.py +0 -24
- llamagen_python-0.1.5/src/llamagen/_webhooks.py +0 -138
- llamagen_python-0.1.5/tests/test_webhooks.py +0 -49
- {llamagen_python-0.1.5 → llamagen_python-0.1.7}/.gitignore +0 -0
- {llamagen_python-0.1.5 → llamagen_python-0.1.7}/LICENSE +0 -0
- {llamagen_python-0.1.5 → llamagen_python-0.1.7}/docs/RELEASE.md +0 -0
- {llamagen_python-0.1.5 → llamagen_python-0.1.7}/src/llamagen/_client.py +0 -0
- {llamagen_python-0.1.5 → llamagen_python-0.1.7}/src/llamagen/py.typed +0 -0
- {llamagen_python-0.1.5 → llamagen_python-0.1.7}/src/llamagen/resources/__init__.py +0 -0
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: llamagen-python
|
|
3
|
+
Version: 0.1.7
|
|
4
|
+
Summary: Official Python SDK for LlamaGen Comic API and Animation API
|
|
5
|
+
Project-URL: Homepage, https://llamagen.ai/comic-api
|
|
6
|
+
Project-URL: Documentation, https://llamagen.ai/comic-api/docs
|
|
7
|
+
Project-URL: Source, https://github.com/LlamaGenAI/llamagen-python
|
|
8
|
+
Project-URL: Issues, https://github.com/LlamaGenAI/llamagen-python/issues
|
|
9
|
+
Author-email: "llamagen.ai" <support@llamagen.ai>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: ai,ai comic api,animation,comic,image-to-video,llamagen,sdk,text-to-video
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# llamagen-python
|
|
27
|
+
|
|
28
|
+
Official Python SDK for LlamaGen's Comic API and Animation API.
|
|
29
|
+
|
|
30
|
+
Homepage: <https://llamagen.ai/comic-api>
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install llamagen-python
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Get Your API Key
|
|
39
|
+
|
|
40
|
+
1. Open the [LlamaGen Comic API Dashboard](https://llamagen.ai/comic-api).
|
|
41
|
+
2. Sign in and create an API key.
|
|
42
|
+
3. Use the key with the SDK or an HTTP `Authorization` header:
|
|
43
|
+
|
|
44
|
+
```http
|
|
45
|
+
Authorization: Bearer YOUR_API_KEY
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
For local SDK examples, set the key in your shell or in a local `.env` file:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
LLAMAGEN_API_KEY=YOUR_API_KEY
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Quick Start
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
import os
|
|
58
|
+
|
|
59
|
+
from llamagen import LlamaGenClient
|
|
60
|
+
|
|
61
|
+
WAIT_TIMEOUT_MS = 30 * 60 * 1000
|
|
62
|
+
|
|
63
|
+
client = LlamaGenClient(
|
|
64
|
+
api_key=os.environ["LLAMAGEN_API_KEY"],
|
|
65
|
+
timeout_ms=30000,
|
|
66
|
+
max_retries=5,
|
|
67
|
+
retry_delay_ms=500,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
created = client.comic.create({
|
|
71
|
+
"prompt": "A 4-panel comic about Leo finding a glowing key in a quiet library.",
|
|
72
|
+
"style": "manga",
|
|
73
|
+
"fixPanelNum": 4,
|
|
74
|
+
})
|
|
75
|
+
print("comic.create:", created["id"], created.get("status"))
|
|
76
|
+
|
|
77
|
+
done = client.comic.wait_for_completion(created["id"], timeout_ms=WAIT_TIMEOUT_MS)
|
|
78
|
+
print("comic.wait_for_completion:", done["id"], done.get("status"), done.get("comics"))
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
## Client
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from llamagen import LlamaGenClient
|
|
86
|
+
|
|
87
|
+
client = LlamaGenClient(
|
|
88
|
+
api_key="YOUR_API_KEY",
|
|
89
|
+
base_url="https://api.llamagen.ai/v1",
|
|
90
|
+
timeout_ms=30000,
|
|
91
|
+
max_retries=5,
|
|
92
|
+
retry_delay_ms=500,
|
|
93
|
+
)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The SDK uses Python's standard library HTTP stack and does not require runtime
|
|
97
|
+
dependencies.
|
|
98
|
+
|
|
99
|
+
## Comic API
|
|
100
|
+
|
|
101
|
+
Use `llamagen.comic` to create comics, manga, webtoons, storyboards,
|
|
102
|
+
consistent-character pages, and panel edits.
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
import os
|
|
106
|
+
|
|
107
|
+
from llamagen import LlamaGenClient
|
|
108
|
+
|
|
109
|
+
client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])
|
|
110
|
+
|
|
111
|
+
generation = client.comic.create({
|
|
112
|
+
"prompt": "The Little Prince meets the Fox in a luminous desert.",
|
|
113
|
+
"style": "storybook manga",
|
|
114
|
+
"size": "1024x1024",
|
|
115
|
+
"pagination": {"totalPages": 2, "panelsPerPage": 4},
|
|
116
|
+
"comicRoles": [
|
|
117
|
+
{
|
|
118
|
+
"name": "The Little Prince",
|
|
119
|
+
"image": "https://example.com/prince.png",
|
|
120
|
+
"clothing": "green coat and yellow scarf",
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
"attachments": [{"type": "image", "url": "https://example.com/reference.png"}],
|
|
124
|
+
"language": "en",
|
|
125
|
+
"upscale": "2K",
|
|
126
|
+
})
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Comic methods:
|
|
130
|
+
|
|
131
|
+
- `llamagen.comic.create(params)` calls `POST /v1/comics/generations`.
|
|
132
|
+
- `llamagen.comic.get(id, page=None, panel=None)` calls `GET /v1/comics/generations/{id}`.
|
|
133
|
+
- `llamagen.comic.continue_write(id, params)` extends an existing comic.
|
|
134
|
+
- `llamagen.comic.update_panel(id, params)` regenerates one panel.
|
|
135
|
+
- `llamagen.comic.usage()` calls `GET /v1/comics/usage`.
|
|
136
|
+
- `llamagen.comic.upload(file, filename=None)` calls `POST /v1/comics/upload`.
|
|
137
|
+
- `llamagen.comic.wait_for_completion(id, **options)` polls until a terminal status.
|
|
138
|
+
- `llamagen.comic.create_and_wait(params, **options)` creates and polls.
|
|
139
|
+
|
|
140
|
+
Comic examples:
|
|
141
|
+
|
|
142
|
+
Create a comic generation:
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
import os
|
|
146
|
+
|
|
147
|
+
from llamagen import LlamaGenClient
|
|
148
|
+
|
|
149
|
+
client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])
|
|
150
|
+
|
|
151
|
+
created = client.comic.create({
|
|
152
|
+
"prompt": "A 4-panel comic about Leo finding a glowing key in a quiet library.",
|
|
153
|
+
"style": "manga",
|
|
154
|
+
"fixPanelNum": 4,
|
|
155
|
+
})
|
|
156
|
+
print("comic.create:", created["id"], created.get("status"))
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Fetch a comic generation, page, or panel:
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
import os
|
|
163
|
+
|
|
164
|
+
from llamagen import LlamaGenClient
|
|
165
|
+
|
|
166
|
+
client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])
|
|
167
|
+
comic_id = "YOUR_COMIC_ID"
|
|
168
|
+
|
|
169
|
+
fetched = client.comic.get(comic_id)
|
|
170
|
+
print("comic.get:", fetched["id"], fetched.get("status"))
|
|
171
|
+
|
|
172
|
+
panel = client.comic.get(comic_id, page=0, panel=0)
|
|
173
|
+
print("comic.get panel:", panel.get("id", comic_id), panel.get("status"))
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Wait for completion. The default timeout is 30 minutes:
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
import os
|
|
180
|
+
|
|
181
|
+
from llamagen import LlamaGenClient
|
|
182
|
+
|
|
183
|
+
WAIT_TIMEOUT_MS = 30 * 60 * 1000
|
|
184
|
+
|
|
185
|
+
client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])
|
|
186
|
+
comic_id = "YOUR_COMIC_ID"
|
|
187
|
+
|
|
188
|
+
done = client.comic.wait_for_completion(comic_id, timeout_ms=WAIT_TIMEOUT_MS)
|
|
189
|
+
print("comic.wait_for_completion:", done["id"], done.get("status"), done.get("comics"))
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Create and wait in one call:
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
import os
|
|
196
|
+
|
|
197
|
+
from llamagen import LlamaGenClient
|
|
198
|
+
|
|
199
|
+
WAIT_TIMEOUT_MS = 30 * 60 * 1000
|
|
200
|
+
|
|
201
|
+
client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])
|
|
202
|
+
|
|
203
|
+
finished = client.comic.create_and_wait({
|
|
204
|
+
"prompt": "A cozy 3-panel comic about a robot learning to bake bread.",
|
|
205
|
+
"style": "storybook",
|
|
206
|
+
"fixPanelNum": 3,
|
|
207
|
+
}, timeout_ms=WAIT_TIMEOUT_MS)
|
|
208
|
+
print("comic.create_and_wait:", finished["id"], finished.get("status"))
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Continue an existing comic:
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
import os
|
|
215
|
+
|
|
216
|
+
from llamagen import LlamaGenClient
|
|
217
|
+
|
|
218
|
+
client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])
|
|
219
|
+
comic_id = "YOUR_COMIC_ID"
|
|
220
|
+
|
|
221
|
+
continued = client.comic.continue_write(
|
|
222
|
+
comic_id,
|
|
223
|
+
{
|
|
224
|
+
"prompt": "Continue the story with Leo opening a secret reading room.",
|
|
225
|
+
"pagination": {"totalPages": 1, "panelsPerPage": 4},
|
|
226
|
+
},
|
|
227
|
+
)
|
|
228
|
+
print("comic.continue_write:", continued["id"], continued.get("status"))
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Regenerate one panel:
|
|
232
|
+
|
|
233
|
+
```python
|
|
234
|
+
import os
|
|
235
|
+
|
|
236
|
+
from llamagen import LlamaGenClient
|
|
237
|
+
|
|
238
|
+
client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])
|
|
239
|
+
comic_id = "YOUR_COMIC_ID"
|
|
240
|
+
|
|
241
|
+
updated = client.comic.update_panel(
|
|
242
|
+
comic_id,
|
|
243
|
+
{
|
|
244
|
+
"panelIndex": 0,
|
|
245
|
+
"prompt": "Make the glowing key brighter and add dramatic moonlight.",
|
|
246
|
+
},
|
|
247
|
+
)
|
|
248
|
+
print("comic.update_panel:", updated["id"], updated.get("status"))
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Check usage:
|
|
252
|
+
|
|
253
|
+
```python
|
|
254
|
+
import os
|
|
255
|
+
|
|
256
|
+
from llamagen import LlamaGenClient
|
|
257
|
+
|
|
258
|
+
client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])
|
|
259
|
+
|
|
260
|
+
usage = client.comic.usage()
|
|
261
|
+
print("comic.usage:", usage)
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Upload a local reference image:
|
|
265
|
+
|
|
266
|
+
```python
|
|
267
|
+
import os
|
|
268
|
+
from pathlib import Path
|
|
269
|
+
|
|
270
|
+
from llamagen import LlamaGenClient
|
|
271
|
+
|
|
272
|
+
client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])
|
|
273
|
+
|
|
274
|
+
upload_file = os.environ.get("LLAMAGEN_UPLOAD_FILE")
|
|
275
|
+
if upload_file:
|
|
276
|
+
uploaded = client.comic.upload(Path(upload_file))
|
|
277
|
+
print("comic.upload:", uploaded)
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## Animation API
|
|
281
|
+
|
|
282
|
+
```python
|
|
283
|
+
import os
|
|
284
|
+
|
|
285
|
+
from llamagen import LlamaGenClient
|
|
286
|
+
|
|
287
|
+
client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])
|
|
288
|
+
|
|
289
|
+
video = client.animation.create({
|
|
290
|
+
"prompt": "A heroic fox detective walks through neon rain, cinematic camera move.",
|
|
291
|
+
"videoOptions": {
|
|
292
|
+
"duration": 5,
|
|
293
|
+
"resolution": "720p",
|
|
294
|
+
"aspect_ratio": "16:9",
|
|
295
|
+
},
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
finished = client.animation.wait_for_completion(
|
|
299
|
+
video["id"],
|
|
300
|
+
interval_ms=5000,
|
|
301
|
+
timeout_ms=30 * 60 * 1000,
|
|
302
|
+
)
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
Animation methods:
|
|
306
|
+
|
|
307
|
+
- `llamagen.animation.create(params)` calls `POST /v1/artworks/generations`.
|
|
308
|
+
- `llamagen.animation.get(id)` calls `GET /v1/artworks/generations/{id}`.
|
|
309
|
+
- `llamagen.animation.wait_for_completion(id, **options)` polls video status.
|
|
310
|
+
- `llamagen.animation.create_and_wait(params, **options)` creates and polls.
|
|
311
|
+
|
|
312
|
+
Animation examples:
|
|
313
|
+
|
|
314
|
+
```python
|
|
315
|
+
import os
|
|
316
|
+
|
|
317
|
+
from llamagen import LlamaGenClient
|
|
318
|
+
|
|
319
|
+
client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])
|
|
320
|
+
|
|
321
|
+
video = client.animation.create({
|
|
322
|
+
"prompt": "A heroic fox detective walks through neon rain, cinematic camera move.",
|
|
323
|
+
"videoOptions": {
|
|
324
|
+
"duration": 5,
|
|
325
|
+
"resolution": "720p",
|
|
326
|
+
"aspect_ratio": "16:9",
|
|
327
|
+
},
|
|
328
|
+
})
|
|
329
|
+
print("animation.create:", video["id"], video.get("status"))
|
|
330
|
+
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Fetch and wait for an animation:
|
|
334
|
+
|
|
335
|
+
```python
|
|
336
|
+
import os
|
|
337
|
+
|
|
338
|
+
from llamagen import LlamaGenClient
|
|
339
|
+
|
|
340
|
+
WAIT_TIMEOUT_MS = 30 * 60 * 1000
|
|
341
|
+
|
|
342
|
+
client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])
|
|
343
|
+
animation_id = "YOUR_ANIMATION_ID"
|
|
344
|
+
|
|
345
|
+
fetched = client.animation.get(animation_id)
|
|
346
|
+
print("animation.get:", fetched["id"], fetched.get("status"))
|
|
347
|
+
|
|
348
|
+
finished = client.animation.wait_for_completion(animation_id, timeout_ms=WAIT_TIMEOUT_MS)
|
|
349
|
+
print("animation.wait_for_completion:", finished["id"], finished.get("status"))
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
Create and wait for an animation in one call:
|
|
353
|
+
|
|
354
|
+
```python
|
|
355
|
+
import os
|
|
356
|
+
|
|
357
|
+
from llamagen import LlamaGenClient
|
|
358
|
+
|
|
359
|
+
WAIT_TIMEOUT_MS = 30 * 60 * 1000
|
|
360
|
+
|
|
361
|
+
client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])
|
|
362
|
+
|
|
363
|
+
finished = client.animation.create_and_wait({
|
|
364
|
+
"prompt": "A paper boat sailing across a watercolor city at sunrise.",
|
|
365
|
+
"videoOptions": {
|
|
366
|
+
"duration": 5,
|
|
367
|
+
"resolution": "720p",
|
|
368
|
+
"aspect_ratio": "16:9",
|
|
369
|
+
},
|
|
370
|
+
}, timeout_ms=WAIT_TIMEOUT_MS)
|
|
371
|
+
print("animation.create_and_wait:", finished["id"], finished.get("status"))
|
|
372
|
+
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
## Errors
|
|
376
|
+
|
|
377
|
+
```python
|
|
378
|
+
import os
|
|
379
|
+
|
|
380
|
+
from llamagen import (
|
|
381
|
+
LlamaGenAPIError,
|
|
382
|
+
LlamaGenClient,
|
|
383
|
+
LlamaGenConnectionError,
|
|
384
|
+
LlamaGenTimeoutError,
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])
|
|
388
|
+
|
|
389
|
+
try:
|
|
390
|
+
usage = client.comic.usage()
|
|
391
|
+
except LlamaGenAPIError as error:
|
|
392
|
+
print("API request failed:", error)
|
|
393
|
+
print("HTTP status:", error.status)
|
|
394
|
+
print("Server response:", error.data)
|
|
395
|
+
except LlamaGenConnectionError as error:
|
|
396
|
+
print("Network connection failed:", error)
|
|
397
|
+
except LlamaGenTimeoutError as error:
|
|
398
|
+
print("Request timed out:", error)
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
- `LlamaGenAPIError`: the API returned a non-2xx response, such as `401`, `403`, or `429`.
|
|
402
|
+
- `LlamaGenConnectionError`: the SDK could not connect to the API after retries.
|
|
403
|
+
- `LlamaGenTimeoutError`: the request timed out after retries.
|