#!/usr/bin/env python3
from openai import OpenAI
from dotenv import load_dotenv

load_dotenv()
client = OpenAI()

def get_response(conversation):
    response = client.responses.create(
        model = "gpt-5-mini",
        instructions = """Respond code only if possible. Keep
                          explanations to a minimum (2 paragraphs
                          max). Don't use markdown formatting,
                          output plain text.""",
        input = conversation
    )
    return response.output_text.strip()

print("Welcome to your programming assistant!")
print("Type 'exit' to quit.")

conversation = []

while True:
    prompt = input("You: ")
    if prompt.lower() == 'exit':
        print("Goodbye!")
        break

    conversation.append({"role": "user", "content": prompt})
    response = get_response(conversation)
    print("AI:")
    print(response)
    print()

    conversation.append({"role": "assistant", "content": response})
