160人参与 • 2024-07-31 • 三星
网络问题:openai-chatgpt的api调用异常处理
官方手册:https://platform.openai.com/docs/api-reference
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上没有生成
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)
结果
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()
结果:氛围有了,但是细节不够
您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论