From b2010835638043d7b146a1f4f9cfa09b3bc7f1a8 Mon Sep 17 00:00:00 2001 From: Christian Malpass Date: Wed, 3 Jan 2024 18:52:30 +0200 Subject: [PATCH] Add Picture API file example to the Examples Folder (#977) * 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. * Update picture.py --------- Co-authored-by: Logan Kilpatrick <23kilpatrick23@gmail.com> --- examples/picture.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 examples/picture.py diff --git a/examples/picture.py b/examples/picture.py new file mode 100644 index 0000000000..7bf22aa790 --- /dev/null +++ b/examples/picture.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python + +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 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()