Added explanations to example.py
This commit is contained in:
parent
bbd0f64f54
commit
e8b3b97da9
1 changed files with 6 additions and 1 deletions
|
@ -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]
|
||||
|
|
Reference in a new issue