import openai # Set your API key openai.api_key = "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" def programming_chatbot(): print("Programming Bot: Hi! I'm here to assist you with programming questions. Type 'exit' to end the chat.") while True: user_input = input("You: ") if user_input.lower() == "exit": print("Programming Bot: Goodbye!") break try: response = openai.ChatCompletion.create( model="gpt-4", # Or "gpt-3.5-turbo" messages=[ {"role": "system", "content": "You are a helpful programming assistant."}, {"role": "user", "content": user_input}, ], ) print("Programming Bot:", response['choices'][0]['message']['content'].strip()) except Exception as e: print("Programming Bot: Sorry, an error occurred.", str(e)) if __name__ == "__main__": programming_chatbot()