Skip to content

Instantly share code, notes, and snippets.

@hahastudio
Created March 16, 2023 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hahastudio/dcce15b4a5a6fa2075de3ef1036c59af to your computer and use it in GitHub Desktop.
Save hahastudio/dcce15b4a5a6fa2075de3ef1036c59af to your computer and use it in GitHub Desktop.
import openai
# add your API key here
openai.api_key = ''
messages = []
system_msg = input("你想要创建什么样的聊天机器人?")
messages.append({"role": "system", "content": system_msg})
print("和你的聊天机器人问好!输入quit来退出。")
while True:
message = input('> ')
if message.strip().lower() == 'quit':
break
messages.append({"role": "user", "content": message})
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-0301",
messages=messages)
reply = response["choices"][0]["message"]["content"]
messages.append({"role": "assistant", "content": reply})
print("\nChatGPT: " + reply + "\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment