Added the initial version of the library source code

This commit is contained in:
Julian Müller (ChaoticByte) 2023-03-09 16:50:46 +01:00
parent 645101cc46
commit b5a5920722
3 changed files with 103 additions and 0 deletions

21
example.py Executable file
View file

@ -0,0 +1,21 @@
#!/usr/bin/env python3
from os import environ
from chatgpt_pyapi import ChatGPT
from chatgpt_pyapi import Models
from chatgpt_pyapi import Message
API_KEY = environ["OPENAI_API_KEY"]
if __name__ == "__main__":
cgpt = ChatGPT(API_KEY, model=Models.GPT_35_TURBO_0301)
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("\nMessage History:")
[print(m.to_api()) for m in cgpt.message_history]