feat(chatbot): integrate OpenRouter API for AI assistance in dashboard

- Added a Chatbot component to the dashboard for user interaction and support.
- Created a README for the Chatbot detailing setup, features, and usage instructions.
- Introduced environment variables for secure API key management.
- Updated app.js to include the Chatbot component.
- Implemented a configuration server to serve API keys securely.
- Enhanced styles for the Chatbot interface to improve user experience.
This commit is contained in:
2025-09-27 15:00:30 +08:00
parent c0c3fb7b5a
commit ec3c7320d7
12 changed files with 1194 additions and 1 deletions

47
dashboard/server.py Normal file
View File

@@ -0,0 +1,47 @@
#!/usr/bin/env python3
"""
Simple configuration server for CityPulse Dashboard Chatbot
Serves API keys securely without exposing them in frontend code
"""
import os
import json
from flask import Flask, jsonify
from flask_cors import CORS
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
app = Flask(__name__)
CORS(app) # Enable CORS for all routes
@app.route('/api/chatbot-config', methods=['GET'])
def get_chatbot_config():
"""Serve chatbot configuration securely"""
try:
config = {
'OPENROUTER_API_KEY': os.getenv('OPENROUTER_API_KEY'),
'OPENROUTER_BASE_URL': os.getenv('OPENROUTER_BASE_URL', 'https://openrouter.ai/api/v1'),
'OPENROUTER_MODEL': os.getenv('OPENROUTER_MODEL', 'x-ai/grok-4-fast:free')
}
# Validate that API key is present
if not config['OPENROUTER_API_KEY']:
return jsonify({'error': 'API key not configured'}), 500
return jsonify(config)
except Exception as e:
return jsonify({'error': f'Failed to load configuration: {str(e)}'}), 500
@app.route('/api/config', methods=['GET'])
def get_config():
"""Legacy config endpoint"""
return get_chatbot_config()
if __name__ == '__main__':
print("Starting CityPulse Dashboard Configuration Server...")
print("Server will run on http://localhost:3001")
print("Make sure your .env file contains OPENROUTER_API_KEY")
app.run(host='localhost', port=3001, debug=True)