Skip to content

Commit 26ced5f

Browse files
furofologankilpatrick
authored andcommitted
Add Picture API file example to the Examples Folder (openai#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 <[email protected]>
1 parent 2c3d84f commit 26ced5f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

examples/picture.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python
2+
3+
from openai import OpenAI
4+
5+
# gets OPENAI_API_KEY from your environment variables
6+
openai = OpenAI()
7+
8+
prompt = "An astronaut lounging in a tropical resort in space, pixel art"
9+
model = "dall-e-3"
10+
11+
def main() -> None:
12+
# Generate an image based on the prompt
13+
response = openai.images.generate(prompt=prompt, model=model)
14+
15+
# Prints response containing a URL link to image
16+
print(response)
17+
18+
if __name__ == "__main__":
19+
main()

0 commit comments

Comments
 (0)