Skip to content

Instantly share code, notes, and snippets.

@OhadRubin
Created March 2, 2023 12:32
Show Gist options
  • Save OhadRubin/88aeb29b6c642c574587fcc3872617ef to your computer and use it in GitHub Desktop.
Save OhadRubin/88aeb29b6c642c574587fcc3872617ef to your computer and use it in GitHub Desktop.
chat.py
from colorama import Fore, Back, Style
import os
import openai
# Set up OpenAI API key
openai.api_key = os.getenv("OPENAI_API_KEY")
prompt = """Your prompts here"""
# Set up initial message
messages = [{"role": "system", "content": }]
while True:
# Get user input
user_input = input("You: ")
# Exit loop if the user inputs "exit"
if user_input.lower() == "exit":
break
# Add user message to messages list
messages.append({"role": "user", "content": user_input})
# Call OpenAI API
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages
)
# Get response from API and add to messages list
response = completion.choices[0].message
messages.append(response)
# Print response
print(Fore.RED + f"Bot: {response['content']}"+Style.RESET_ALL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment