网络问题:openai-chatGPT的API调用异常处理
官方手册:https://platform.openai.com/docs/api-reference
visgpt
gitlab代码
https://github.com/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)
结果
文章来源:https://www.toymoban.com/news/detail-520071.html
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()
结果:氛围有了,但是细节不够
文章来源地址https://www.toymoban.com/news/detail-520071.html
到了这里,关于openai visgpt,chatgpt,DALLE2 使用测试的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!