图像生成
使用 Portkey AI 网关生成图像
# Constants for use later - Please enter your own
PORTKEY_API_KEY="" # Get this from your Portkey Account
OPENAI_API_KEY = "" # Your OpenAI key here
STABILITY_API_KEY = "" # Add your stability ai API key1. 使用 OpenAI 生成图像
from openai import OpenAI
from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders
from IPython.display import display, Image
client = OpenAI(
api_key=OPENAI_API_KEY,
base_url=PORTKEY_GATEWAY_URL,
default_headers=createHeaders(
provider="openai",
api_key=PORTKEY_API_KEY
)
)
image = client.images.generate(
model="dall-e-3",
prompt="Lucy in the sky with diamonds",
n=1,
size="1024x1024"
)
# Display the image
display(Image(url=image.data[0].url))2. 使用 Stability AI 生成图像
3. 使用负载均衡和回退的配置
4. 缓存图像请求
Last updated