Skip to content

Commit 8c30f19

Browse files
authored
Add support for image URL (#198)
* Add support for image URL * bump version to 1.3.1 * fix cli
1 parent a83acd4 commit 8c30f19

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ build-backend = "poetry.masonry.api"
1212

1313
[tool.poetry]
1414
name = "together"
15-
version = "1.3.0"
15+
version = "1.3.1"
1616
authors = [
1717
"Together AI <[email protected]>"
1818
]

src/together/cli/api/images.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import base64
22
import pathlib
3+
import requests
34

45
import click
56
from PIL import Image
@@ -70,8 +71,18 @@ def generate(
7071
for i, choice in enumerate(response.data):
7172
assert isinstance(choice, ImageChoicesData)
7273

74+
data = None
75+
if choice.b64_json:
76+
data = base64.b64decode(choice.b64_json)
77+
elif choice.url:
78+
data = requests.get(choice.url).content
79+
80+
if not data:
81+
click.echo(f"Image [{i + 1}/{len(response.data)}] is empty")
82+
continue
83+
7384
with open(f"{output}/{prefix}{choice.index}.png", "wb") as f:
74-
f.write(base64.b64decode(choice.b64_json))
85+
f.write(data)
7586

7687
click.echo(
7788
f"Image [{i + 1}/{len(response.data)}] saved to {output}/{prefix}{choice.index}.png"

src/together/types/images.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ class ImageChoicesData(BaseModel):
2828
# response index
2929
index: int
3030
# base64 image response
31-
b64_json: str
31+
b64_json: str | None = None
32+
# URL hosting image
33+
url: str | None = None
3234

3335

3436
class ImageResponse(BaseModel):

0 commit comments

Comments
 (0)