Your own ChatGPT Plus using OpenAI's new API
You have to love Python. 18 lines of code, 19 if you include the comment. Here you go!
You can currently pay $20 a month and get access to ChatGPT Plus, or you can now access the same powerful AI engine through OpenAI’s API.
With this AI you can:
Draft an email or other piece of writing
Write Python code
Answer questions about a set of documents
Create conversational agents
Give your software a natural language interface
Tutor in a range of subjects
Translate languages
Simulate characters for video games and much more
Like I’m about to show you …
Yes, you need some tech skills … but you don’t need the code because I’ve got it for you here:
And here’s the code:
# Your own ChatGPT Plus written in Python
import os
import openai
from dotenv import load_dotenv
load_dotenv() # Load all the ENV variables into your os enviroment.
openai.api_key = os.getenv("OPENAI_API_KEY") # Get your API key from an environment variable
msgs = []
system_msg = input("What type of chatbot would you like to create?\n")
msgs.append ({"role": "system", "content": system_msg})
print("Say hello to your new chatbot! Type quit() when done.")
while True:
msg = input("YOU: ")
if "quit()" in msg:
break
msgs.append ({"role": "user", "content": msg})
response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=msgs)
reply = response["choices"][0]["message"]["content"]
msgs.append({"role": "assistant", "content": reply})
print("\nAI: " + reply + "\n")