1.准备一个OPENAI的API_KEY。
2.在pycharm中新建一个GPT-3.5.py
:
import openai
# 填入你的api_key
openai.api_key = ""models = openai.Model.list()# 定义API参数
params = {'role': "user", "content": ''}# 定义循环
while True:# 获取用户输入user_input = input("请输入您的消息:")if user_input.lower() == "quit":break# 更新API参数params["content"] = user_input# 发送请求到API#response = requests.get(url, params=params)completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[params])print(completion.choices[0].message.content)