2023-03-09 16:50:46 +01:00
#!/usr/bin/env python3
2023-03-09 16:55:18 +01:00
# Copyright (c) 2023 Julian Müller (ChaoticByte)
2023-03-09 16:50:46 +01:00
from os import environ
2023-03-13 10:44:01 +01:00
from sys import argv
2023-03-09 16:50:46 +01:00
2023-03-13 10:44:01 +01:00
example_system_message = " Please provide the following answers as cynical as possible, but still correct. "
example_questions = [
" Who are you? " ,
" Could you please elaborate? "
]
2023-03-09 16:50:46 +01:00
if __name__ == " __main__ " :
2023-03-13 10:44:01 +01:00
bing = False
if len ( argv ) > 1 :
bing = argv [ 1 ] == " bing "
if bing :
from chatgpt_pyapi . bing import ChatGPT , Message , ConversationStyle
# Read the path to the cookies file from a environment variable
BING_COOKIES_FILE = environ [ " BING_COOKIES_FILE " ]
# Create ChatGPT API instance (with creative answers)
cgpt = ChatGPT ( BING_COOKIES_FILE , ConversationStyle . creative )
cgpt . chat ( Message ( example_system_message ) )
else :
from chatgpt_pyapi . openai import ChatGPT , Message , Models , Roles
# Read the API key from a environment variable
API_KEY = environ [ " OPENAI_API_KEY " ]
# Create ChatGPT API instance
cgpt = ChatGPT ( API_KEY , model = Models . GPT_35_TURBO_0301 )
# Provide a system message that will influence the answers
sys_msg = Message ( example_system_message , role = Roles . SYSTEM )
# Add the message to the history, but don't send it yet
cgpt . add_to_chat ( sys_msg )
2023-03-09 17:26:35 +01:00
# Have a little chat :D
2023-03-13 10:44:01 +01:00
for q in example_questions :
print ( f " \n USER: { q } " )
print ( cgpt . chat ( Message ( q ) ) . text )
2023-03-09 17:26:35 +01:00
# Print out message history
2023-03-09 16:50:46 +01:00
print ( " \n Message History: " )
2023-03-13 10:44:01 +01:00
[ print ( str ( m ) ) for m in cgpt . _message_history ]