Here's a simple AI-powered chatbot using Python and OpenAI's GPT model. You can install the required package using:
bash
pip install openai
Then, use this Python script:
python
import openai
# Replace with your OpenAI API key
API_KEY = "your-api-key"
def chat_with_ai(prompt):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "system", "content": "You are a helpful chatbot."},
{"role": "user", "content": prompt}]
)
return response["choices"][0]["message"]["content"]
print("AI Chatbot: Type 'exit' to end the chat.")
while True:
user_input = input("You: ")
if user_input.lower() == "exit":
print("Chatbot: Goodbye!")
break
response = chat_with_ai(user_input)
print("Chatbot:", response)
### Features:
Uses OpenAI’s GPT model
Keeps a simple user-chatbot interaction loop
Exits when the user types "exit"