程序
import openai
import os
import base64
openai.api_key = os.getenv("OPENAI_API_KEY")
response = openai.Image.create(
prompt="阳光很好,山上风吹树林,花瓣飘落",
n=1,
size="256x256",
response_format="b64_json"
)
image_json = response['data'][0]['b64_json']
# 将Base64编码的图片数据解码为字节
image_data = base64.b64decode(image_json)
# 将解码的字节数据保存为文件(请根据实际情况选择合适的文件名和格式)
with open('画图程序.jpg', 'wb') as f:
f.write(image_data)