|
| 1 | +# π€ AI Chatbot on Python |
| 2 | + |
| 3 | +Welcome to **Markhor AI Chatbot**, a Python-based chatbot powered by **ChatGPT-4**! π |
| 4 | +This chatbot is designed to have intelligent conversations using OpenAI's API. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## π Features |
| 9 | + |
| 10 | +β
Uses **GPT-4 API** for natural conversations |
| 11 | +β
Interactive **CLI chat interface** |
| 12 | +β
Secure API key handling using `.gitignore` |
| 13 | +β
Simple and **easy-to-use Python script** |
| 14 | +β
Exit command (`exit`, `quit`, `bye`) to stop the chat |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## π οΈ Installation |
| 19 | + |
| 20 | +### **1οΈβ£ Clone the Repository** |
| 21 | +```sh |
| 22 | +git clone https://github.com/Muawiya-contact/AI-Chatbot-on-Python.git |
| 23 | +cd AI-Chatbot-on-Python |
| 24 | +``` |
| 25 | + |
| 26 | +### **2οΈβ£ Create a Virtual Environment (Recommended)** |
| 27 | +```sh |
| 28 | +python -m venv venv |
| 29 | +source venv/bin/activate # On Windows use: venv\Scripts\activate |
| 30 | +``` |
| 31 | + |
| 32 | +### **3οΈβ£ Install Required Dependencies** |
| 33 | +```sh |
| 34 | +pip install -r requirements.txt |
| 35 | +``` |
| 36 | + |
| 37 | +--- |
| 38 | + |
| 39 | +## π Secure API Key Handling |
| 40 | + |
| 41 | +**DO NOT** hardcode your API key in the script! Instead, follow these steps: |
| 42 | + |
| 43 | +1. **Create a `config.py` file** in the project directory: |
| 44 | + ```python |
| 45 | + API_KEY = "your-secret-api-key" |
| 46 | + ``` |
| 47 | +2. **Add `config.py` to `.gitignore`** to prevent it from being uploaded: |
| 48 | + ``` |
| 49 | + config.py |
| 50 | + ``` |
| 51 | +3. **Now, import the key securely in your script:** |
| 52 | + ```python |
| 53 | + from config import API_KEY |
| 54 | + ``` |
| 55 | + |
| 56 | +--- |
| 57 | + |
| 58 | +## π Usage |
| 59 | + |
| 60 | +1. **Run the chatbot**: |
| 61 | + ```sh |
| 62 | + python chatbot.py |
| 63 | + ``` |
| 64 | + |
| 65 | +2. **Chat with Markhor AI**: |
| 66 | + ``` |
| 67 | + Hi there! I am Markhor, the AI chatbot powered by ChatGPT-4, represented by Coding Moves. |
| 68 | + How can I assist you today? |
| 69 | +
|
| 70 | + You: Hello! |
| 71 | + Markhor AI: Hi! How can I help you today? |
| 72 | + ``` |
| 73 | + |
| 74 | +3. **Exit the chat** by typing: `"exit"`, `"quit"`, or `"bye"`. |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +## π Example Code |
| 79 | + |
| 80 | +```python |
| 81 | +import requests |
| 82 | +from config import API_KEY # Secure API key handling |
| 83 | + |
| 84 | +API_URL = "https://api.openai.com/v1/chat/completions" |
| 85 | + |
| 86 | +def chat_with_ai(user_message): |
| 87 | + headers = { |
| 88 | + "Authorization": f"Bearer {API_KEY}", |
| 89 | + "Content-Type": "application/json" |
| 90 | + } |
| 91 | + data = { |
| 92 | + "model": "gpt-4", |
| 93 | + "messages": [{"role": "user", "content": user_message}] |
| 94 | + } |
| 95 | + response = requests.post(API_URL, json=data, headers=headers) |
| 96 | + return response.json()["choices"][0]["message"]["content"] if response.status_code == 200 else "Error occurred!" |
| 97 | + |
| 98 | +# Run chatbot |
| 99 | +while True: |
| 100 | + user_input = input("You: ") |
| 101 | + if user_input.lower() in ["exit", "quit", "bye"]: |
| 102 | + print("Markhor AI: Goodbye!") |
| 103 | + break |
| 104 | + print("Markhor AI:", chat_with_ai(user_input)) |
| 105 | +``` |
| 106 | + |
| 107 | +--- |
| 108 | + |
| 109 | +## π How to Contribute |
| 110 | + |
| 111 | +πΉ Fork the repository |
| 112 | +πΉ Create a new branch (`git checkout -b feature-branch`) |
| 113 | +πΉ Make changes and commit (`git commit -m "Added new feature"`) |
| 114 | +πΉ Push to the branch (`git push origin feature-branch`) |
| 115 | +πΉ Open a **Pull Request** |
| 116 | + |
| 117 | +Contributions are welcome! Feel free to improve and enhance the chatbot. |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +## π License |
| 122 | + |
| 123 | +This project is open-source and available under the **MIT License**. |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +## π‘ Developed By |
| 128 | + |
| 129 | +π¨βπ» **Muawiya** |
| 130 | +π [GitHub](https://github.com/Muawiya-contact) |
| 131 | +π’ **Powered by Coding Moves** |
| 132 | + |
| 133 | +--- |
| 134 | + |
| 135 | +## π― Support |
| 136 | + |
| 137 | +β **Star** this repository if you found it helpful! |
| 138 | +π’ Share it with others! |
| 139 | +π¬ Feel free to open an **issue** for suggestions or bugs! |
| 140 | + |
| 141 | +--- |
| 142 | + |
| 143 | +**Happy Coding! ππ€** |
0 commit comments