| Current Path : /var/www/pythonian/qwen/ |
| Current File : /var/www/pythonian/qwen/readme.md |
**How to Run the PAI Knowledge Base Chatbot Locally** This guide will help you set up and run the chatbot on your Windows, macOS, or Linux computer. What you’ll get: A working chat interface in your browser that connects to a local AI assistant powered by Alibaba Cloud PAI. --- **Step 1: Install Python** **For Windows** 1. Go to https://www.python.org/downloads/ 2. Click the "Download Python" button (e.g., Python 3.10 or newer). 3. Run the downloaded .exe file. 4. Important: Check the box "Add Python to PATH" at the bottom of the installer window. 5. Click "Install Now". 6. After installation, open Command Prompt (press Windows key, type "cmd", and press Enter) and type: ``` python --version ``` You should see a response like: Python 3.11.9 **For macOS** 1. Open the Terminal application. 2. Install Homebrew by running: ``` /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` 3. Then install Python: ``` brew install python ``` 4. Check the version by running: ``` python3 --version ``` **For Linux (Ubuntu/Debian)** Open a terminal and run: ``` sudo apt update sudo apt install python3 python3-pip -y ``` --- **Step 2: Prepare the Project Files** 1. Unzip the file you received (e.g., pai-chatbot.zip). 2. Inside, you should see two files: - backend.py (the backend server) - index.html (the chat interface) --- **Step 3: Add Your PAI Credentials** You must have an Alibaba Cloud account and a published PAI Knowledge Base application. 1. Open backend.py in a text editor (e.g., Notepad, TextEdit, or VS Code). 2. Locate these two lines: ``` APP_ID = 'your-pai-app-id-here' API_KEY = 'your-dashscope-api-key' ``` 3. Replace them with your actual credentials: - APP_ID: Found in the PAI Console under Knowledge Base > Application Details - API_KEY: Found in the DashScope Console under API Key Management Example: ``` APP_ID = '293e8581e7cb48958750505aa0cd866f' API_KEY = 'sk-3b1a7b5659b94c72acfdba7110144b35' ``` 4. Save the file. Note: Do not share this file publicly—it contains your secret key. --- **Step 4: Install Required Python Packages** 1. Open Command Prompt (Windows) or Terminal (macOS/Linux). 2. Navigate to the folder where you unzipped the files. Example (Windows): ``` cd C:\Users\YourName\Downloads\pai-chatbot ``` Example (macOS/Linux): ``` cd ~/Downloads/pai-chatbot ``` 3. Run the following command to install dependencies: ``` pip install flask flask-cors dashscope ``` You should see messages confirming successful installation. --- **Step 5: Start the Backend Server** In the same terminal window, run: ``` python backend.py ``` You should see output similar to: ``` * Running on http://127.0.0.1:5000 ``` Leave this window open—it is running your AI server. --- **Step 6: Open the Chat Interface** 1. Open the folder containing the unzipped files. 2. Double-click index.html to open it in your default web browser. 3. Type a question (e.g., "What is CIDOS?") and press Enter or click Send. 4. After a few seconds, you will see a response generated from your knowledge base. Note: The chat interface connects to http://localhost:5000/chat, so the Python server must be running. --- **Stopping the Server** To stop the server, go back to the terminal window where python backend.py is running and press: Ctrl + C --- **Troubleshooting** - If you see "'python' is not recognized as a command": Reinstall Python and ensure "Add Python to PATH" is checked during installation. - If you get "403 Forbidden" or "Invalid API key": Verify your APP_ID and API_KEY in backend.py. - If the chat shows no response: Open your browser’s Developer Tools (press F12), go to the Console or Network tab, and check for error messages. - If you see a CORS error: Ensure flask-cors is installed by running `pip install flask-cors`.