Also, by using davinci on the completion endpoint, you’d be spending 10x as much on a model from last year.
After you pay up and have a working API key, here’s a chatbot that will stream the words like ChatGPT, use the messages format for gpt-3.5-turbo, remember some conversation (and not word-wrap at words because that’s just as many lines of code to do elegantly).
import openai
openai.api_key = "sk-1234yourkey1234"
system = [{"role": "system", "content":
"You are Jbot, a helpful AI assistant."}]
user = [{"role": "user", "content":
"brief introduction?"}]
chat = []
while not user[0]['content'] == "exit":
response = openai.ChatCompletion.create(
messages = system + chat[-10:] + user,
model="gpt-3.5-turbo", top_p=0.5, stream=True)
reply = ""
for delta in response:
if not delta['choices'][0]['finish_reason']:
word = delta['choices'][0]['delta']['content']
reply += word
print(word, end ="")
chat += user + [{"role": "assistant", "content": reply}]
user = [{"role": "user", "content": input("\nPrompt: ")}]