my code

mail@pastecode.io avatar
unknown
plain_text
a month ago
881 B
1
Indexable
Never
import openai

# Replace 'your_actual_api_key_here' with the key you obtained from OpenAI
openai.api_key = "your_actual_api_key_here"

end_program = False

while not end_program:
    get_input = input("Enter a prompt: ")
    if get_input.lower() == "goodbye" or get_input.lower() == "exit":
        end_program = True
        print("Have a great day!")
    else:
        system_data = [
            {"role": "system", "content": "You are an assistant that only answers math questions."},
            {"role": "user", "content": get_input}
        ]
        response = openai.ChatCompletion.create(
            model="gpt-3.5-turbo",
            messages=system_data
        )
        assistant_response = response['choices'][0]['message']['content']
        system_data.append({"role": "assistant", "content": assistant_response})
        print("Assistant: " + assistant_response)
Leave a Comment