python调用chatgpt4


import openai
import os
# optional; defaults to `os.environ['OPENAI_API_KEY']`
openai.api_key = "sk-XXXX"  # 你的 OpenAI API Key


prompt = "The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.\n\nHuman: Hello, who are you?\nAI: I am an AI created by OpenAI. How can I help you today?\n"
response = openai.Completion.create(
    engine="gpt-3.5-turbo",
    prompt=prompt,
    max_tokens=150,
)
print(response.choices[0].text)

如果出现以下的错误

RateLimitError: You exceeded your current quota, please check your plan and billing details.

说明你的帐号没有钱,需要充值,但是chatgpt4和openAPI不是一个帐号,你需要单独为openAPI的帐号充值,充值后根据调用次数消耗。

猜你喜欢

转载自blog.csdn.net/sunyuhua_keyboard/article/details/134714726
今日推荐