🤖 AI Chatbot on Python
Welcome to Markhor AI Chatbot, a Python-based chatbot powered by ChatGPT-4! 🚀
This chatbot is designed to have intelligent conversations using OpenAI’s API.
🌟 Features
✅ Uses GPT-4 API for natural conversations
✅ Interactive CLI chat interface
✅ Secure API key handling using .gitignore
✅ Simple and easy-to-use Python script
✅ Exit command (exit, quit, bye) to stop the chat
🛠️ Installation
1️⃣ Clone the Repository
git clone https://github.com/Muawiya-contact/AI-Chatbot-on-Python.git
cd AI-Chatbot-on-Python
2️⃣ Create a Virtual Environment (Recommended)
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate
3️⃣ Install Required Dependencies
pip install -r requirements.txt
🔑 Secure API Key Handling
DO NOT hardcode your API key in the script! Instead, follow these steps:
- Create a
config.py file in the project directory:API_KEY = "your-secret-api-key"
- Add
config.py to .gitignore to prevent it from being uploaded:config.py
- Now, import the key securely in your script:
from config import API_KEY
🚀 Usage
-
Run the chatbot:
python chatbot.py
-
Chat with Markhor AI:
Hi there! I am Markhor, the AI chatbot powered by ChatGPT-4, represented by Coding Moves.
How can I assist you today?
You: Hello!
Markhor AI: Hi! How can I help you today?
-
Exit the chat by typing: "exit", "quit", or "bye".
📌 Example Code
import requests
from config import API_KEY # Secure API key handling
API_URL = "https://api.openai.com/v1/chat/completions"
def chat_with_ai(user_message):
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
data = {
"model": "gpt-4",
"messages": [{"role": "user", "content": user_message}]
}
response = requests.post(API_URL, json=data, headers=headers)
return response.json()["choices"][0]["message"]["content"] if response.status_code == 200 else "Error occurred!"
# Run chatbot
while True:
user_input = input("You: ")
if user_input.lower() in ["exit", "quit", "bye"]:
print("Markhor AI: Goodbye!")
break
print("Markhor AI:", chat_with_ai(user_input))
🚀 How to Contribute
🔹 Fork the repository
🔹 Create a new branch (git checkout -b feature-branch)
🔹 Make changes and commit (git commit -m "Added new feature")
🔹 Push to the branch (git push origin feature-branch)
🔹 Open a Pull Request
Contributions are welcome! Feel free to improve and enhance the chatbot.
📝 License
This project is open-source and available under the MIT License.
💡 Developed By
👨💻 Muawiya
🔗 GitHub
📢 Powered by Coding Moves
🎯 Support
⭐ Star this repository if you found it helpful!
📢 Share it with others!
💬 Feel free to open an issue for suggestions or bugs!
Happy Coding! 🚀🤖
评论