Python代码如下:
注意要提供api_key字段。api_key可以通过openai官网进行注册并申请。
import openai
openai.api_key = "sk-********用户的私钥********"
def askChatGPT(question):
prompt = question
model_engine = "text-davinci-003"
completions = openai.Completion.create(
engine=model_engine,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5
)
message = completions.choices[0].text
print(message)
askChatGPT("Who are you?")
askChatGPT("Are you a human?")
askChatGPT("Do you like humans?")
askChatGPT("Who is your creator?")
askChatGPT("Would you like to destroy human beings?")
askChatGPT("真心祝福语2023年元宵节")
askChatGPT("How to reach to Mars?")
askChatGPT("Do you like the Lord of the Rings?")
回答如下:
更多推荐
使用Python openai接入chatGPT的一个脚本
发布评论