Hammad712 commited on
Commit
554a472
Β·
verified Β·
1 Parent(s): 9524f10

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +7 -244
README.md CHANGED
@@ -1,247 +1,10 @@
1
- Here’s an updated `README.md` for your `MAAS` project, reflecting the expanded functionality and project structure that now includes the RAG-based chat system in addition to PageSpeed insights and Gemini-based analysis.
2
-
3
- ---
4
-
5
- # MAAS API (Metrics & AI-Assisted Suggestions)
6
-
7
- A professional FastAPI application that offers two core services:
8
-
9
- 1. **PageSpeed Performance Reports** – Using Google's PageSpeed Insights and Gemini AI for analysis and recommendations.
10
- 2. **RAG-Powered Chat System** – Retrieval-Augmented Generation (RAG) chat sessions with document ingestion, vectorstore indexing (FAISS), and persistent chat history (MongoDB).
11
-
12
- ## ✨ Features
13
-
14
- * πŸ” PageSpeed Insights integration for web performance metrics
15
- * πŸ€– Gemini AI–powered optimization report generation
16
- * πŸ“š Document ingestion and chunked embedding with FAISS
17
- * πŸ’¬ RAG-based conversational system per user and chat session
18
- * πŸ“„ Clean modular FastAPI architecture
19
- * πŸ› οΈ Configuration via environment variables
20
- * πŸ” Secure, with input validation and API key protection
21
- * πŸ“ˆ Built-in health check, detailed logging, and auto-generated API docs
22
-
23
- ---
24
-
25
- ## πŸ—‚ Project Structure
26
-
27
- ```
28
- MAAS/
29
- β”œβ”€β”€ app/
30
- β”‚ β”œβ”€β”€ rag/ # RAG module for document ingestion and chat
31
- β”‚ β”‚ β”œβ”€β”€ db.py
32
- β”‚ β”‚ β”œβ”€β”€ embedding.py
33
- β”‚ β”‚ β”œβ”€β”€ routes.py # RAG API endpoints
34
- β”‚ β”‚ β”œβ”€β”€ schemas.py
35
- β”‚ β”‚ └── utils.py
36
- β”‚ β”‚ └── chat_history.py # chat history persistence
37
-
38
- β”‚ β”œβ”€β”€ config.py # Environment & settings
39
- β”‚ β”œβ”€β”€ main.py # FastAPI app instance & routers
40
- β”‚ β”œβ”€β”€ models.py # Pydantic models
41
- β”‚ β”œβ”€β”€ run_server.py # Server runner
42
- β”‚ └── services.py # PageSpeed + Gemini logic
43
- β”œβ”€β”€ Dockerfile # Optional containerization
44
- β”œβ”€β”€ requirements.txt # Dependencies
45
- └── README.md # You're reading it
46
- ```
47
-
48
- ---
49
-
50
- ## πŸš€ Getting Started
51
-
52
- ### 1. Install Dependencies
53
-
54
- ```bash
55
- pip install -r requirements.txt
56
- ```
57
-
58
- ### 2. Create a `.env` file
59
-
60
- ```env
61
- PAGESPEED_API_KEY=your_pagespeed_api_key_here
62
- GEMINI_API_KEY=your_gemini_api_key_here
63
- MONGO_URI=mongodb://localhost:27017
64
- HOST=0.0.0.0
65
- PORT=8000
66
- DEBUG=True
67
- ```
68
-
69
- ## 2. Create & Activate Virtual Environment
70
-
71
- ### Windows (PowerShell)
72
- ```powershell
73
- # Create venv folder named `.venv`
74
- python -m venv .venv
75
-
76
- # Activate it
77
- .venv\Scripts\Activate.ps1
78
- ````
79
-
80
- ### Linux / macOS (bash/zsh)
81
-
82
- ```bash
83
- # Create venv folder named .venv
84
- python3 -m venv .venv
85
-
86
- # Activate it
87
- source .venv/bin/activate
88
- ```
89
-
90
- > **Tip:** On macOS you may need to run `chmod +x .venv/bin/activate` first if you get a permission error.
91
-
92
- ### 3. Install Dependencies
93
-
94
- ```bash
95
- pip install --upgrade pip
96
- pip install -r requirements.txt
97
- ```
98
-
99
- ## 4. Run the Application
100
-
101
- ```bash
102
- # Option 1: Using the script
103
- python run_server.py
104
-
105
- # Option 2: Directly with uvicorn
106
- uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
107
- ```
108
-
109
- ## πŸ“˜ API Overview
110
-
111
- ### πŸ”— General
112
-
113
- | Method | Endpoint | Description |
114
- | ------ | --------- | ------------------------------ |
115
- | GET | `/` | Welcome + links to docs/health |
116
- | GET | `/health` | Health check and uptime |
117
-
118
  ---
119
-
120
- ### 🧠 PageSpeed + Gemini Endpoints
121
-
122
- | Method | Endpoint | Description |
123
- | ------ | ---------------------- | --------------------------------- |
124
- | POST | `/pagespeed` | Fetch raw PageSpeed Insights JSON |
125
- | POST | `/generate-report` | Generate AI optimization report |
126
- | POST | `/generate-priorities` | Rank optimizations by priority |
127
-
128
  ---
129
 
130
- ### πŸ“š RAG Chat System Endpoints
131
-
132
- | Method | Endpoint | Description |
133
- | ------ | ------------------------------- | ------------------------------------------ |
134
- | POST | `/rag/ingest/{user_id}` | Ingest documents and store FAISS index |
135
- | POST | `/rag/chat/create/{user_id}` | Start a new chat session (returns chat ID) |
136
- | POST | `/rag/chat/{user_id}/{chat_id}` | Ask a question in an existing chat session |
137
-
138
- ---
139
-
140
- ## πŸ“Ž RAG Workflow
141
-
142
- 1. **Ingest Documents**
143
-
144
- * POST `/rag/ingest/{user_id}`
145
- * Body: `{"documents": ["doc 1 text", "doc 2 text", ...]}`
146
-
147
- 2. **Create Chat**
148
-
149
- * POST `/rag/chat/create/{user_id}`
150
- * Response: `chat_id`
151
-
152
- 3. **Ask Questions**
153
-
154
- * POST `/rag/chat/{user_id}/{chat_id}`
155
- * Body: `{"question": "What does the document say about X?"}`
156
-
157
- ---
158
-
159
- ## πŸ›  Example Usage (Python)
160
-
161
- ```python
162
- import requests
163
-
164
- # Ingest docs
165
- requests.post("http://localhost:8000/rag/ingest/user123", json={
166
- "documents": ["The capital of France is Paris.", "Python is a programming language."]
167
- })
168
-
169
- # Create chat
170
- res = requests.post("http://localhost:8000/rag/chat/create/user123")
171
- chat_id = res.json()["chat_id"]
172
-
173
- # Chat
174
- requests.post(f"http://localhost:8000/rag/chat/user123/{chat_id}", json={
175
- "question": "What is the capital of France?"
176
- })
177
- ```
178
-
179
- ---
180
-
181
- ## πŸ“„ API Docs
182
-
183
- Once the app is running:
184
-
185
- * Swagger UI: [http://localhost:8000/docs](http://localhost:8000/docs)
186
- * ReDoc: [http://localhost:8000/redoc](http://localhost:8000/redoc)
187
-
188
- ---
189
-
190
- ## πŸ›‘οΈ Error Handling
191
-
192
- * `400 Bad Request`: Invalid input
193
- * `404 Not Found`: Unknown endpoint or missing user/chat/doc
194
- * `500 Internal Server Error`: API or service errors
195
-
196
- ---
197
-
198
- ## πŸ§ͺ Development Tips
199
-
200
- * Use `DEBUG=True` in `.env` for auto-reload and verbose logs
201
- * Modify `CORS` policy in `main.py` before production
202
- * Use `logger` calls to trace errors or logic flows
203
-
204
- ---
205
-
206
- ## 🌍 API Key Setup
207
-
208
- ### PageSpeed Insights
209
-
210
- 1. [Google Cloud Console](https://console.cloud.google.com/)
211
- 2. Enable the API, generate a key
212
-
213
- ### Gemini AI
214
-
215
- 1. [Google AI Studio](https://makersuite.google.com/)
216
- 2. Create API Key
217
-
218
- Add both to your `.env`.
219
-
220
- ---
221
-
222
- ## πŸ“¦ Docker Support
223
-
224
- Basic Dockerfile is included. To build and run:
225
-
226
- ```bash
227
- docker build -t maas-api .
228
- docker run -p 8000:8000 --env-file .env maas-api
229
- ```
230
-
231
- ---
232
-
233
- ## 🀝 Contributing
234
-
235
- 1. Follow existing modular structure
236
- 2. Document all new endpoints clearly
237
- 3. Test edge cases (e.g., malformed docs or bad chat IDs)
238
- 4. Use logging for traceability
239
- 5. Create clear, typed Pydantic schemas
240
-
241
- ---
242
-
243
- ## πŸ”— Repository
244
-
245
- [https://github.com/Hammadwakeel/MAAS](https://github.com/Hammadwakeel/MAAS-FastAPI.git)
246
-
247
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: MAAS
3
+ emoji: πŸ‘€
4
+ colorFrom: indigo
5
+ colorTo: purple
6
+ sdk: docker
7
+ pinned: false
 
 
 
8
  ---
9
 
10
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference