import openai
openai.api_key = OPENAI_KEY#改成你自己的
def 新对话():
my_messages=[]
while True:
my_input=input('我:')
my_messages.append({"role": "user", "content": my_input})
if not my_input:
return
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo-0301",
messages=my_messages,
temperature=0.2
)
response = completion.choices[0].message["content"]
print("AI:",response)
my_messages.append({"role":"assistant","content":response})
运行效果: