# web-qwen-code **Repository Path**: colin5063/web-qwen-code ## Basic Information - **Project Name**: web-qwen-code - **Description**: 基于阿里云qwen-code 终端改造的web 界面的qwen,提供session记忆;支持钉钉和飞书 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-07 - **Last Updated**: 2026-04-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Qwen Chat App A web-based chat interface for conversing with Qwen (via local CLI or API), featuring session management with Redis storage and multi-platform bot support. ## Features - 💬 Real-time chat with Qwen - 🔄 Dual mode: **CLI** (local qwen command) or **API** (API key) - 📁 Multiple chat sessions support - 💾 Sessions stored in Redis with TTL - 🎨 Modern dark theme UI with Markdown rendering - 📋 Copy as Markdown or HTML - 🤖 **DingTalk bot** integration with WebSocket Stream - 🕊️ **Feishu (Lark) bot** integration with HTTP callback - ⚡ FastAPI backend with async support - 🔧 Session management (create, delete, rename) ## Prerequisites - Python 3.10+ - Redis server - Either: - **CLI Mode**: `qwen` command installed and configured - **API Mode**: Qwen API key from Alibaba Cloud - Optional: DingTalk/Feishu bot credentials ## Installation ### 1. Clone and setup ```bash cd qwen_chat_app python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt ``` ### 2. Start Redis ```bash # macOS (with Homebrew) brew services start redis # Or using Docker docker run -d -p 6379:6379 redis:latest ``` ### 3. Configure environment ```bash cp .env.example .env ``` ## Configuration ### CLI Mode (Development/Testing) ```env QWEN_MODE=cli # Optional: specify model QWEN_CLI_MODEL=qwen-max # MCP Servers to allow (comma-separated) QWEN_ALLOWED_MCP_SERVERS=sre-tidb,sre-confluence # Redis REDIS_HOST=localhost REDIS_PORT=6379 REDIS_DB=0 SESSION_TTL=3600 ``` **Important for MCP Tools:** 1. Run `qwen mcp list` to see configured MCP servers 2. Add server names to `QWEN_ALLOWED_MCP_SERVERS` in `.env` 3. Restart the application ### API Mode (Production) ```env QWEN_MODE=api QWEN_API_KEY=your_api_key_here QWEN_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1 QWEN_MODEL=qwen-plus ``` ### DingTalk Bot (WebSocket Stream) 1. Create a bot in [DingTalk Open Platform](https://open.dingtalk.com/) 2. Get Client ID and Client Secret 3. Configure event subscriptions in DingTalk developer console 4. Update `.env`: ```env DINGTALK_ENABLED=true DINGTALK_CLIENT_ID=your_client_id DINGTALK_CLIENT_SECRET=your_client_secret ``` **Note:** DingTalk uses WebSocket Stream mode via `dingtalk-stream` SDK. The bot connects to DingTalk's servers and receives messages in real-time. ### Feishu (Lark) Bot (HTTP Callback) 1. Create a bot in [Feishu Open Platform](https://open.feishu.cn/) 2. Get App ID, App Secret, and Verification Token 3. Configure event subscription: - Event: `im.message.receive_v1` - Callback URL: `http://your-server:8002/feishu/callback` 4. Update `.env`: ```env FEISHU_ENABLED=true FEISHU_PORT=8002 FEISHU_APP_ID=your_app_id FEISHU_APP_SECRET=your_app_secret FEISHU_VERIFICATION_TOKEN=your_verification_token ``` **Note:** Feishu uses HTTP callback mode. The platform sends POST requests to your server when messages arrive. ### 4. Run the application ```bash python main.py ``` Or with uvicorn: ```bash uvicorn main:app --host 0.0.0.0 --port 8000 --reload ``` ### 5. Open in browser Navigate to `http://localhost:8000` ## Project Structure ``` qwen_chat_app/ ├── main.py # FastAPI application entry point ├── routes.py # API routes ├── schemas.py # Pydantic models ├── session_manager.py # Redis session management ├── qwen_client.py # Qwen API client ├── qwen_cli_client.py # Qwen CLI client (local command) ├── dingtalk_bot.py # DingTalk WebSocket stream bot ├── feishu_bot.py # Feishu HTTP callback bot ├── requirements.txt # Python dependencies ├── .env.example # Environment template ├── templates/ │ └── index.html # Main HTML page └── static/ ├── style.css # Styles └── app.js # Frontend JavaScript ``` ## API Endpoints | Method | Endpoint | Description | |--------|----------|-------------| | GET | `/` | Home page | | GET | `/api/mode` | Get current mode (cli/api) | | GET | `/api/health` | Health check | | POST | `/api/sessions` | Create new session | | GET | `/api/sessions` | List all sessions | | GET | `/api/sessions/{id}` | Get session details | | PUT | `/api/sessions/{id}` | Update session title | | DELETE | `/api/sessions/{id}` | Delete session | | POST | `/api/sessions/{id}/chat` | Send message (with streaming) | ## Bot Commands | Command | Description | |---------|-------------| | `/new` | Start a new chat session | | Any other message | Continue current conversation | ## Features Detail ### Web Interface - **Markdown Rendering**: All responses are rendered with Markdown support - **Syntax Highlighting**: Code blocks are highlighted automatically (Python, JS, SQL, etc.) - **Copy Buttons**: Each message has buttons to copy as Markdown or HTML - **Session Management**: Create, rename, and delete chat sessions - **Session Switching**: Switch between different chat sessions seamlessly ### DingTalk Bot - **WebSocket Stream mode** using official `dingtalk-stream` SDK - Real-time message delivery - Session persistence (same conversation = same session) - Type `/new` to start a fresh conversation - Markdown support in replies ### Feishu Bot - **HTTP callback mode** with event subscription - Session persistence (same conversation = same session) - Type `/new` to start a fresh conversation - Markdown support in replies ## Configuration Options | Variable | Default | Description | |----------|---------|-------------| | `QWEN_MODE` | cli | Mode: "cli" or "api" | | `REDIS_HOST` | localhost | Redis server host | | `REDIS_PORT` | 6379 | Redis server port | | `REDIS_DB` | 0 | Redis database number | | `QWEN_CLI_MODEL` | - | Model for CLI mode | | `QWEN_ALLOWED_MCP_SERVERS` | - | MCP servers to allow | | `QWEN_API_KEY` | - | Your Qwen API key | | `QWEN_BASE_URL` | dashscope API | Qwen API endpoint | | `QWEN_MODEL` | qwen-plus | Model for API mode | | `SESSION_TTL` | 3600 | Session expiry (seconds) | | `DINGTALK_ENABLED` | false | Enable DingTalk bot | | `DINGTALK_CLIENT_ID` | - | DingTalk client ID | | `DINGTALK_CLIENT_SECRET` | - | DingTalk client secret | | `FEISHU_ENABLED` | false | Enable Feishu bot | | `FEISHU_APP_ID` | - | Feishu app ID | | `FEISHU_APP_SECRET` | - | Feishu app secret | | `FEISHU_VERIFICATION_TOKEN` | - | Feishu verification token | | `FEISHU_PORT` | 8002 | Feishu bot port | ## Troubleshooting ### Redis connection error ```bash redis-cli ping # Should return: PONG ``` ### CLI Mode: qwen command not found ```bash qwen --help # Verify installation ``` ### MCP tools not working 1. Check `qwen mcp list` for configured servers 2. Add server names to `QWEN_ALLOWED_MCP_SERVERS` 3. Restart the application ### DingTalk bot not receiving messages 1. Verify Client ID and Client Secret are correct 2. Check bot is subscribed to message events in DingTalk console 3. Check logs for connection errors ### Feishu bot not receiving messages 1. Verify App ID, App Secret, and Verification Token 2. Check callback URL is configured in Feishu console 3. Verify event subscription includes `im.message.receive_v1` 4. Check firewall rules for bot port (8002) ### Session switching issue If session content doesn't update when switching: 1. Clear browser cache 2. Check browser console for JavaScript errors 3. Verify Redis is running and accessible ## Bot Architecture Comparison | Feature | DingTalk | Feishu | |---------|----------|--------| | Connection | WebSocket (persistent) | HTTP Callback (request/response) | | SDK | `dingtalk-stream` | Custom HTTP handler | | Message Delivery | Push via WebSocket | Push via HTTP POST | | Port | N/A (outbound connection) | 8002 (inbound) | | Firewall | No special requirements | Allow inbound on port 8002 | ## License MIT