From e8b3b97da95b1aaeed0f1bd3872145e3ecd7769e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller=20=28ChaoticByte=29?= Date: Thu, 9 Mar 2023 17:26:35 +0100 Subject: [PATCH] Added explanations to example.py --- example.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/example.py b/example.py index 1f2592d..52cfba6 100755 --- a/example.py +++ b/example.py @@ -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]