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.
β
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
git clone https://github.com/Muawiya-contact/AI-Chatbot-on-Python.git
cd AI-Chatbot-on-Python
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate
pip install -r requirements.txt
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
-
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"
.
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))
πΉ 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.
This project is open-source and available under the MIT License.
π¨βπ» Muawiya
π GitHub
π’ Powered by Coding Moves
β Star this repository if you found it helpful!
π’ Share it with others!
π¬ Feel free to open an issue for suggestions or bugs!
Happy Coding! ππ€