Created
March 19, 2023 11:21
-
-
Save liamzebedee/0ca91461deb31da249575e62906c80d5 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 | |
messages = [] | |
def prompt_and_print_response(): | |
prompt = input(">> ") | |
messages.append({"role": "user", "content": prompt}) | |
response = openai.ChatCompletion.create( | |
model="gpt-3.5-turbo", | |
messages=messages | |
) | |
choice = response['choices'][0] | |
finish_reason = choice['finish_reason'] | |
if finish_reason != "stop": | |
print(response) | |
# prompt to continue | |
continue_input = input("Continue? ") | |
if continue_input.lower() in ["y", "yes"]: | |
return True | |
else: | |
exit(0) | |
message = choice['message'] | |
print(message['content']) | |
messages.append(message) | |
while True: | |
try: | |
prompt_and_print_response() | |
except (KeyboardInterrupt, EOFError): | |
print("\nExiting...") | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment