Skip to content

Rename DALL·E to Image #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions openai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import Optional

from openai.api_resources import (
DALLE,
Answer,
Classification,
Completion,
Expand All @@ -18,6 +17,7 @@
ErrorObject,
File,
FineTune,
Image,
Model,
Moderation,
Search,
Expand Down Expand Up @@ -51,7 +51,7 @@
"Completion",
"Customer",
"Edit",
"DALLE",
"Image",
"Deployment",
"Embedding",
"Engine",
Expand Down
2 changes: 1 addition & 1 deletion openai/api_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from openai.api_resources.classification import Classification # noqa: F401
from openai.api_resources.completion import Completion # noqa: F401
from openai.api_resources.customer import Customer # noqa: F401
from openai.api_resources.dalle import DALLE # noqa: F401
from openai.api_resources.deployment import Deployment # noqa: F401
from openai.api_resources.edit import Edit # noqa: F401
from openai.api_resources.embedding import Embedding # noqa: F401
from openai.api_resources.engine import Engine # noqa: F401
from openai.api_resources.error_object import ErrorObject # noqa: F401
from openai.api_resources.file import File # noqa: F401
from openai.api_resources.fine_tune import FineTune # noqa: F401
from openai.api_resources.image import Image # noqa: F401
from openai.api_resources.model import Model # noqa: F401
from openai.api_resources.moderation import Moderation # noqa: F401
from openai.api_resources.search import Search # noqa: F401
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
from openai.api_resources.abstract import APIResource


class DALLE(APIResource):
class Image(APIResource):
OBJECT_NAME = "images"

@classmethod
def _get_url(cls, action):
return cls.class_url() + f"/{action}"

@classmethod
def generations(
def create(
cls,
**params,
):
instance = cls()
return instance.request("post", cls._get_url("generations"), params)

@classmethod
def variations(
def create_variation(
cls,
image,
api_key=None,
Expand Down Expand Up @@ -55,7 +55,7 @@ def variations(
)

@classmethod
def edits(
def create_edit(
cls,
image,
mask,
Expand Down
40 changes: 17 additions & 23 deletions openai/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,44 +229,41 @@ def list(cls, args):
print(file)


class DALLE:
class Image:
@classmethod
def generations(cls, args):
resp = openai.DALLE.generations(
def create(cls, args):
resp = openai.Image.create(
prompt=args.prompt,
model=args.model,
size=args.size,
num_images=args.num_images,
n=args.num_images,
response_format=args.response_format,
)
print(resp)

@classmethod
def variations(cls, args):
def create_variation(cls, args):
with open(args.image, "rb") as file_reader:
buffer_reader = BufferReader(file_reader.read(), desc="Upload progress")
resp = openai.DALLE.variations(
resp = openai.Image.create_variation(
image=buffer_reader,
model=args.model,
size=args.size,
num_images=args.num_images,
n=args.num_images,
response_format=args.response_format,
)
print(resp)

@classmethod
def edits(cls, args):
def create_edit(cls, args):
with open(args.image, "rb") as file_reader:
image_reader = BufferReader(file_reader.read(), desc="Upload progress")
with open(args.mask, "rb") as file_reader:
mask_reader = BufferReader(file_reader.read(), desc="Upload progress")
resp = openai.DALLE.edits(
resp = openai.Image.create_edit(
image=image_reader,
mask=mask_reader,
prompt=args.prompt,
model=args.model,
size=args.size,
num_images=args.num_images,
n=args.num_images,
response_format=args.response_format,
)
print(resp)
Expand Down Expand Up @@ -1026,19 +1023,17 @@ def help(args):
sub.add_argument("-i", "--id", required=True, help="The id of the fine-tune job")
sub.set_defaults(func=FineTune.cancel)

# DALLE
sub = subparsers.add_parser("dalle.generations")
sub.add_argument("-m", "--model", type=str, default="image-alpha-001")
# Image
sub = subparsers.add_parser("image.create")
sub.add_argument("-p", "--prompt", type=str, required=True)
sub.add_argument("-n", "--num-images", type=int, default=1)
sub.add_argument(
"-s", "--size", type=str, default="1024x1024", help="Size of the output image"
)
sub.add_argument("--response-format", type=str, default="url")
sub.set_defaults(func=DALLE.generations)
sub.set_defaults(func=Image.create)

sub = subparsers.add_parser("dalle.edits")
sub.add_argument("-m", "--model", type=str, default="image-alpha-001")
sub = subparsers.add_parser("image.create_edit")
sub.add_argument("-p", "--prompt", type=str, required=True)
sub.add_argument("-n", "--num-images", type=int, default=1)
sub.add_argument(
Expand All @@ -1059,10 +1054,9 @@ def help(args):
required=True,
help="Path to a mask image. It should be the same size as the image you're editing and a RGBA PNG image. The Alpha channel acts as the mask.",
)
sub.set_defaults(func=DALLE.edits)
sub.set_defaults(func=Image.create_edit)

sub = subparsers.add_parser("dalle.variations")
sub.add_argument("-m", "--model", type=str, default="image-alpha-001")
sub = subparsers.add_parser("image.create_variation")
sub.add_argument("-n", "--num-images", type=int, default=1)
sub.add_argument(
"-I",
Expand All @@ -1075,7 +1069,7 @@ def help(args):
"-s", "--size", type=str, default="1024x1024", help="Size of the output image"
)
sub.add_argument("--response-format", type=str, default="url")
sub.set_defaults(func=DALLE.variations)
sub.set_defaults(func=Image.create_variation)


def wandb_register(parser):
Expand Down
2 changes: 1 addition & 1 deletion openai/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "0.24.0"
VERSION = "0.25.0"