admin 管理员组

文章数量: 886992

网络问题:openai-chatGPT的API调用异常处理
官方手册:https://platform.openai/docs/api-reference

visgpt

gitlab代码

https://github/microsoft/visual-chatgpt

visual_chatgpt.py运行前添加密匙

os.environ['OPENAI_API_KEY']=""

更改参数为cpu

parser.add_argument('--load', type=str, default="ImageCaptioning_cpu,Text2Image_cpu")

非常非常慢7min,而且根据控制台查看图片,发现已经生成,而UI上没有生成

chatGPT

import openai

# Apply the API key
openai.api_key = "xxx"

# Define the text prompt
prompt = "to be or not to be "

# Generate completions using the API
completions = openai.Completion.create(
    engine="text-davinci-002",
    prompt=prompt,
    max_tokens=100,
    n=1,
    stop=None,
    temperature=0.5,
)

# Extract the message from the API response
message = completions.choices[0].text
print(message)

结果

DALLE2

import requests
import openai
from PIL import Image
openai.api_key = "xxx"
response=openai.Image.create(
  prompt="the little prince and the fox in the story, they sit together",
  n=1,
  size="1024x1024"
)
image_url = response['data'][0]['url']
r = requests.get(image_url)
with open('test.png', 'wb') as f:
    f.write(r.content)
img = Image.open('test.png')
img.show()

结果:氛围有了,但是细节不够

本文标签: 测试 visgpt OpenAI ChatGpt