Created
March 16, 2023 04:01
-
-
Save hahastudio/dcce15b4a5a6fa2075de3ef1036c59af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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