Added explanations to example.py

This commit is contained in:
Julian Müller (ChaoticByte) 2023-03-09 17:26:35 +01:00
parent bbd0f64f54
commit e8b3b97da9

View file

@ -9,18 +9,23 @@ from chatgpt_pyapi import Message
from chatgpt_pyapi import Models
from chatgpt_pyapi import Roles
# Read the API key from a environment variable
API_KEY = environ["OPENAI_API_KEY"]
if __name__ == "__main__":
# Create ChatGPT API instance
cgpt = ChatGPT(API_KEY, model=Models.GPT_35_TURBO_0301)
# Provide a system message that will influence the answers
system_in = "Please provide the following answers as cynical as possible, but still correct."
# Add the message to the history, but don't send it yet
cgpt.add_to_chat(Message(system_in, role=Roles.SYSTEM))
# Have a little chat :D
user_in = "Who are you?"
print(f"USER: {user_in}")
print(cgpt.chat(Message(user_in)).text)
user_in = "Could you please elaborate?"
print(f"\nUSER: {user_in}")
print(cgpt.chat(Message(user_in)).text)
# Print out message history
print("\nMessage History:")
[print(m.to_api()) for m in cgpt._message_history]