import openai
import tkinter as tk
Set the API key
openai.api_key = " key here "
Create a function to generate a response using the GPT-3 API
def generate_response(prompt):
Use the Completion API to generate a response
response = openai.Completion.create(engine="text-davinci-002", prompt=prompt, max_tokens=1024)
return response.text
Create the main window
window = tk.Tk()
window.title("GPT-3 Chat Bot")
Create a text box for the user input
input_text = tk.Text(window, height=2)
input_text.pack()
Create a button to send the input
send_button = tk.Button(window, text="Send", command=lambda: send_input())
send_button.pack()
Create a text box for the chatbot's response
response_text = tk.Text(window)
response_text.pack()
Create a function to send the user's input to the chatbot
def send_input():
Get the user's input
input_str = input_text.get("1.0", "end")
Clear the user's input
input_text.delete("1.0", "end")
Generate a response
response = generate_response(input_str)
Display the response in the response text box
response_text.insert("end", response)
Run the main loop
window.mainloop()