From 6d2272519cb514cd518aa288d3ccf61657cb2a2c Mon Sep 17 00:00:00 2001 From: furofo Date: Sun, 17 Dec 2023 00:21:56 +0200 Subject: [PATCH 1/2] Added a file to the examples folder to provide a simple example of retrieving and printing a picture to the console using the new API. Previously, no examples were provided for images, making it unclear. --- examples/picture.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 examples/picture.py diff --git a/examples/picture.py b/examples/picture.py new file mode 100644 index 0000000000..ea19ecfb0a --- /dev/null +++ b/examples/picture.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +from pathlib import Path + +from openai import OpenAI + +# gets OPENAI_API_KEY from your environment variables +openai = OpenAI() +prompt = "An astronaut lounging in a tropical resort in space, pixel art" +def main() -> None: + # Generate the image based on the prompt + response = openai.images.generate(prompt=prompt) + # Prints response with url link to image + print(response) +if __name__ == "__main__": + main() From 323afe1be94634329845329eb0d8087e3475e304 Mon Sep 17 00:00:00 2001 From: Logan Kilpatrick <23kilpatrick23@gmail.com> Date: Wed, 3 Jan 2024 10:52:08 -0600 Subject: [PATCH 2/2] Update picture.py --- examples/picture.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/picture.py b/examples/picture.py index ea19ecfb0a..7bf22aa790 100644 --- a/examples/picture.py +++ b/examples/picture.py @@ -1,16 +1,19 @@ #!/usr/bin/env python -from pathlib import Path - from openai import OpenAI # gets OPENAI_API_KEY from your environment variables openai = OpenAI() + prompt = "An astronaut lounging in a tropical resort in space, pixel art" +model = "dall-e-3" + def main() -> None: - # Generate the image based on the prompt - response = openai.images.generate(prompt=prompt) - # Prints response with url link to image + # Generate an image based on the prompt + response = openai.images.generate(prompt=prompt, model=model) + + # Prints response containing a URL link to image print(response) + if __name__ == "__main__": main()