import openai
print("欢迎使用ChatGPT智能问答,请在Q:后面输入你的问题,输入quit退出!")
openai.api_key = "" #把api_key 填写到这里
start_sequence = "\nA:"
restart_sequence = "\nQ: "
while 1==1:
prompt = input(restart_sequence)
if prompt == 'quit':
break
else:
try:
response = openai.Completion.create(
model="text-davinci-003",
prompt=prompt,
temperature=1,
max_tokens=2000,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
resp = response.to_dict()
print(start_sequence,resp["choices"][0]["text"].strip())
except Exception as exc:
print(exc)