Devrajsinh bharatsinh gohil commited on
Commit
fb96efc
·
1 Parent(s): b0b150b

docker_add

Browse files
.gitignore CHANGED
@@ -1,3 +1,9 @@
 
 
 
 
 
 
1
  # Python
2
  __pycache__/
3
  *.py[cod]
@@ -7,7 +13,11 @@ __pycache__/
7
  venv/
8
  .venv/
9
  env/
 
10
  .env
 
 
 
11
  *.egg-info/
12
  .eggs/
13
  *.egg
 
1
+ # Models (FastEmbed cache)
2
+ .cache/
3
+ models/
4
+ *.bin
5
+ *.onnx
6
+
7
  # Python
8
  __pycache__/
9
  *.py[cod]
 
13
  venv/
14
  .venv/
15
  env/
16
+ ENV/
17
  .env
18
+ .env.local
19
+ .env.production
20
+ *.env
21
  *.egg-info/
22
  .eggs/
23
  *.egg
CHANGES_IMAGE_PREVIEW_FIX.md DELETED
@@ -1,217 +0,0 @@
1
- # Image Preview and Groq API Fix - Summary
2
-
3
- ## Changes Made
4
-
5
- ### 1. Image Preview UI Fix (Frontend)
6
-
7
- **Issue:** Image preview was showing as a large card above the input field, not matching the desired inline thumbnail appearance from the screenshot.
8
-
9
- **Solution:**
10
- - Removed the large preview card that appeared above the input
11
- - Added a small **60px inline thumbnail** that appears next to the input controls
12
- - Thumbnail includes:
13
- - Clickable to view full size in lightbox
14
- - Small close button overlay (top-right)
15
- - Proper border and styling matching the purple theme
16
- - Uses `objectFit: 'cover'` for clean thumbnail appearance
17
-
18
- **Files Modified:**
19
- - `frontend/src/pages/Chat.jsx` (lines 687-793)
20
-
21
- **Visual Changes:**
22
- ```
23
- Before: [Large preview card]
24
- [Input field with buttons]
25
-
26
- After: [Input field with buttons] [60px thumbnail]
27
- ```
28
-
29
- ---
30
-
31
- ### 2. Image Display in Chat Messages
32
-
33
- **Issue:** When sending an image, it wasn't appearing in the user's chat bubble.
34
-
35
- **Solution:**
36
- - Added `multimodal_data` with `image_url` to the user message object
37
- - This stores the base64 preview URL for immediate display
38
- - The existing message rendering code (lines 483-521) already handles displaying images in chat bubbles
39
-
40
- **Files Modified:**
41
- - `frontend/src/pages/Chat.jsx` (lines 241-266)
42
-
43
- **Code Added:**
44
- ```javascript
45
- multimodal_data: {
46
- image_url: imagePreview // Store preview URL for display
47
- }
48
- ```
49
-
50
- ---
51
-
52
- ### 3. Groq API Image Processing Error Handling (Backend)
53
-
54
- **Issue:** Groq API image processing errors were causing the entire multimodal chat to fail.
55
-
56
- **Solution:**
57
- - Improved error handling in the multimodal chat endpoint
58
- - Now catches and logs image processing errors without breaking the chat flow
59
- - Provides fallback context when image analysis fails
60
- - Better error messages for debugging
61
-
62
- **Files Modified:**
63
- - `backend/api/chat.py` (lines 212-240)
64
-
65
- **Error Handling Flow:**
66
- ```python
67
- try:
68
- processor = create_multimodal_processor()
69
- image_result = processor.process_image(str(temp_path))
70
-
71
- if image_result.get("success"):
72
- # Use AI-generated description
73
- multimodal_context += f"\n[IMAGE DESCRIPTION]: {image_desc}"
74
- else:
75
- # Fallback: mention the image was uploaded
76
- logger.warning(f"Image analysis failed: {error}")
77
- multimodal_context += f"\n[IMAGE]: User uploaded an image"
78
- except Exception as e:
79
- # Graceful degradation
80
- logger.error(f"Image processing exception: {e}")
81
- multimodal_context += f"\n[IMAGE]: User uploaded an image"
82
- ```
83
-
84
- ---
85
-
86
- ## Testing Checklist
87
-
88
- ### Image Preview
89
- - [ ] Upload an image using the image upload button
90
- - [ ] Verify small 60px thumbnail appears inline with input controls
91
- - [ ] Click thumbnail to view full size in lightbox
92
- - [ ] Click close button (X) on thumbnail to remove
93
- - [ ] Verify thumbnail disappears after sending message
94
-
95
- ### Chat Message Display
96
- - [ ] Send a message with an image attached
97
- - [ ] Verify image appears in your chat bubble as a thumbnail
98
- - [ ] Verify image can be clicked to view full size
99
- - [ ] Verify text message appears below the image
100
-
101
- ### Groq API Processing
102
- - [ ] Check backend logs when sending an image
103
- - [ ] Verify "Analyzing image" log appears
104
- - [ ] If Groq API works: Should see image description in reasoning
105
- - [ ] If Groq API fails: Should see warning but chat still works
106
-
107
- ---
108
-
109
- ## Common Issues and Solutions
110
-
111
- ### Issue: GROQ_API_KEY not found
112
- **Solution:** Create `.env` file in `backend/` directory:
113
- ```
114
- GROQ_API_KEY=your_groq_api_key_here
115
- ```
116
-
117
- ### Issue: Image processing fails with "model not found"
118
- **Solution:** Groq's vision model is: `llama-3.2-90b-vision-preview`
119
- - This is already configured in `utils/groq_client.py`
120
- - Ensure your API key has access to vision models
121
-
122
- ### Issue: Image doesn't appear after sending
123
- **Solution:** Check:
124
- 1. Browser console for errors
125
- 2. Network tab to verify image was uploaded to Supabase
126
- 3. Backend logs for processing errors
127
-
128
- ---
129
-
130
- ## Architecture Overview
131
-
132
- ### Frontend Flow
133
- ```
134
- 1. User selects image → handleFileSelect()
135
- 2. FileReader creates base64 preview → setImagePreview()
136
- 3. Preview shows as inline thumbnail
137
- 4. User sends message → handleSend()
138
- 5. Image included in userMessage.multimodal_data
139
- 6. API call: sendMultimodalMessage()
140
- 7. Preview clears, message appears in chat
141
- ```
142
-
143
- ### Backend Flow
144
- ```
145
- 1. Receive multimodal request at /api/chat/multimodal
146
- 2. Upload image to Supabase Storage → image_url
147
- 3. Save temp copy for AI processing
148
- 4. Groq Vision analyzes image → description
149
- 5. Description added to multimodal_context
150
- 6. Reasoning engine processes query + context
151
- 7. Return answer + image_url to frontend
152
- 8. Cleanup temp file
153
- ```
154
-
155
- ---
156
-
157
- ## Files Changed Summary
158
-
159
- ### Frontend
160
- - `frontend/src/pages/Chat.jsx`
161
- - Removed large preview card (removed ~50 lines)
162
- - Added inline 60px thumbnail preview (+50 lines)
163
- - Added multimodal_data to user message (+3 lines)
164
-
165
- ### Backend
166
- - `backend/api/chat.py`
167
- - Improved image processing error handling (+16 lines)
168
- - Added try-catch for graceful degradation
169
-
170
- - `backend/test_groq_vision.py` (new file)
171
- - Diagnostic script to test Groq configuration
172
-
173
- ---
174
-
175
- ## Next Steps
176
-
177
- 1. **Test the changes:**
178
- - Start backend: `cd backend && uvicorn main:app --reload`
179
- - Frontend should already be running
180
- - Upload and send an image
181
-
182
- 2. **Verify Groq API:**
183
- ```bash
184
- cd backend
185
- python test_groq_vision.py
186
- ```
187
-
188
- 3. **Check logs** if issues occur:
189
- - Backend console for API errors
190
- - Browser DevTools console for frontend errors
191
- - Network tab for upload status
192
-
193
- ---
194
-
195
- ## Visual Reference
196
-
197
- Based on your screenshot, the final result should look like:
198
-
199
- ```
200
- ┌─────────────────────────────────────────────────┐
201
- │ Input field text here... │
202
- │ │
203
- │ [🎤] [📷] [60x60 img] [Send ➤] │
204
- │ thumbnail │
205
- └─────────────────────────────────────────────────┘
206
- ```
207
-
208
- When sent, appears in chat as:
209
- ```
210
- User bubble:
211
- ┌────────────────┐
212
- │ [thumbnail] │ ← clickable
213
- │ │
214
- │ Your message │
215
- │ text here │
216
- └────────────────┘
217
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
COMPLETE_FIX_SUMMARY.md DELETED
@@ -1,316 +0,0 @@
1
- # Complete Fix Summary - Image Preview & Groq API
2
-
3
- ## ✅ All Issues Fixed
4
-
5
- ### Issue 1: Image Preview Position ✓
6
- **Problem:** Image was showing as inline thumbnail, not matching your reference screenshots
7
-
8
- **Solution:** Restored large preview card ABOVE the input field
9
- - Preview now appears above the input (like screenshot #3)
10
- - Max size: 300px wide, 200px tall
11
- - Close button in top-right corner
12
- - Click to view full-size in lightbox
13
- - Purple border matching app theme
14
-
15
- **Files Changed:**
16
- - `frontend/src/pages/Chat.jsx` (lines 691-744)
17
-
18
- ---
19
-
20
- ### Issue 2: Duplicate Preview Removed ✓
21
- **Problem:** There were two previews (above AND inline)
22
-
23
- **Solution:** Removed the inline 60px thumbnail
24
- - Only one preview now - the large one above input
25
- - Cleaner UI matching your screenshots
26
-
27
- **Files Changed:**
28
- - `frontend/src/pages/Chat.jsx` (lines 785-853)
29
-
30
- ---
31
-
32
- ### Issue 3: Groq API Not Recognizing Images ✓
33
- **Problem:** Groq was returning "I don't have information about the image"
34
-
35
- **Solution:** Added comprehensive logging to track the entire flow
36
- - Added logging at every step of image processing
37
- - File size validation
38
- - Base64 encoding verification
39
- - API call tracking
40
- - Detailed error messages
41
-
42
- **Files Changed:**
43
- - `backend/utils/groq_client.py` (lines 156-230)
44
- - `backend/api/chat.py` (lines 220-270)
45
-
46
- **Logging Format:**
47
- ```
48
- [MULTIMODAL] Image uploaded to Supabase: https://...
49
- [MULTIMODAL] Saving temp file: data/temp/abc123.jpg
50
- [MULTIMODAL] Temp file saved, size: 45678 bytes
51
- [MULTIMODAL] Starting image analysis with Groq Vision...
52
- [GROQ VISION] Starting image analysis for: data/temp/abc123.jpg
53
- [GROQ VISION] Image file size: 45678 bytes
54
- [GROQ VISION] Image encoded to base64, length: 61234 chars
55
- [GROQ VISION] Detected MIME type: image/jpeg
56
- [GROQ VISION] Calling Groq API with model: llama-3.2-90b-vision-preview
57
- [GROQ VISION] Success! Response length: 234 chars
58
- [GROQ VISION] Response preview: This image shows a financial literacy infographic...
59
- [MULTIMODAL] ✓ Image analyzed successfully
60
- ```
61
-
62
- ---
63
-
64
- ## Testing Steps
65
-
66
- ### 1. Test Image Preview (Frontend)
67
-
68
- 1. **Navigate to any agent chat**
69
- 2. **Click the image upload button** 📷
70
- 3. **Select an image file**
71
- 4. **Verify:**
72
- - ✓ Large preview appears ABOVE the input field
73
- - ✓ Preview is max 300x200px
74
- - ✓ Close button (X) appears in top-right
75
- - ✓ Click image to view full-size
76
- - ✓ Click X to remove preview
77
- 5. **Type a message** describing the image
78
- 6. **Click Send**
79
- 7. **Verify:**
80
- - ✓ Preview disappears from input area
81
- - ✓ Image appears in YOUR message bubble (right side, purple)
82
- - ✓ Image is clickable for full view
83
-
84
- ### 2. Test Groq Image Recognition (Backend)
85
-
86
- 1. **Open backend terminal** to watch logs
87
- 2. **Upload and send an image** with text "what this image about"
88
- 3. **Check backend logs** for:
89
- ```
90
- [MULTIMODAL] Image uploaded to Supabase...
91
- [MULTIMODAL] Starting image analysis with Groq Vision...
92
- [GROQ VISION] Starting image analysis...
93
- [GROQ VISION] Success! Response length: XXX chars
94
- ```
95
- 4. **Verify in chat:**
96
- - ✓ MEXAR responds with actual description of the image
97
- - ✓ NOT "I don't have information about the image"
98
- - ✓ Response shows confidence score
99
- - ✓ "Explain reasoning" button available
100
-
101
- ### 3. What to Look For in Logs
102
-
103
- **✓ SUCCESS PATTERN:**
104
- ```
105
- [MULTIMODAL] Image uploaded to Supabase: https://...
106
- [MULTIMODAL] Temp file saved, size: 45678 bytes
107
- [GROQ VISION] Image encoded to base64, length: 61234 chars
108
- [GROQ VISION] Calling Groq API with model: llama-3.2-90b-vision-preview
109
- [GROQ VISION] Success! Response length: 234 chars
110
- [MULTIMODAL] ✓ Image analyzed successfully
111
- ```
112
-
113
- **❌ ERROR PATTERNS:**
114
-
115
- **Pattern 1 - Missing API Key:**
116
- ```
117
- [GROQ VISION] API call failed: ValueError: GROQ_API_KEY not found
118
- ```
119
- **Fix:** Add GROQ_API_KEY to backend/.env
120
-
121
- **Pattern 2 - File Not Found:**
122
- ```
123
- [MULTIMODAL] Image processing exception: FileNotFoundError
124
- ```
125
- **Fix:** Check Supabase storage permissions
126
-
127
- **Pattern 3 - API Error:**
128
- ```
129
- [GROQ VISION] API call failed: HTTPError: 401 Unauthorized
130
- ```
131
- **Fix:** Check API key is valid
132
-
133
- **Pattern 4 - Model Not Available:**
134
- ```
135
- [GROQ VISION] API call failed: Model not found
136
- ```
137
- **Fix:** Verify Groq account has vision access
138
-
139
- ---
140
-
141
- ## Visual Comparison
142
-
143
- ### BEFORE (Your Issue)
144
- ```
145
- ┌─────────────────────────────────────┐
146
- │ [User Message with Image] │
147
- │ [Small inline thumbnail] │
148
- │ "what this image about" │
149
- └─────────────────────────────────────┘
150
-
151
- └─[MEXAR Response]──────────────────┐
152
- │ "I don't have information about │
153
- │ the image 'download (1).jpg'..." │
154
- │ │
155
- │ 🔴 NOT WORKING - No recognition │
156
- └────────────────────────────────────┘
157
-
158
- Input: [inline 60px thumbnail] [text]
159
- ```
160
-
161
- ### AFTER (Fixed)
162
- ```
163
- ┌─[Large Preview Above Input]───┐
164
- │ ┌─────────────────────┐ [X] │
165
- │ │ │ │
166
- │ │ [Image Preview] │ │
167
- │ │ (300x200px) │ │
168
- │ │ │ │
169
- │ └─────────────────────┘ │
170
- └───────────────────────────────┘
171
-
172
- Input: [🎤] [📷] [text field] [Send]
173
-
174
-
175
- └─[User Message]────────────────────┐
176
- │ ┌────────────┐ │
177
- │ │ [Image] │ ← clickable │
178
- │ └────────────┘ │
179
- │ "what this image about" │
180
- └───────────────────────────────────┘
181
-
182
- └─[MEXAR Response]──────────────────┐
183
- │ "This image shows a financial │
184
- │ literacy infographic with a │
185
- │ light bulb and text about..." │
186
- │ │
187
- │ ✅ WORKING - Image recognized! │
188
- │ Confidence: 85% [Explain] │
189
- └────────────────────────────────────┘
190
- ```
191
-
192
- ---
193
-
194
- ## Common Issues & Solutions
195
-
196
- ### Issue: Preview not appearing
197
- **Check:**
198
- 1. Browser console for errors
199
- 2. Image file type (jpg, png, gif, webp only)
200
- 3. File size (should be < 10MB)
201
-
202
- ### Issue: "I don't have information about the image"
203
- **Debug:**
204
- 1. Check backend logs for `[GROQ VISION]` messages
205
- 2. Look for API errors or exceptions
206
- 3. Verify GROQ_API_KEY is set
207
- 4. Test API key with: `cd backend && python test_groq_vision.py`
208
-
209
- ### Issue: Image disappears after sending
210
- **This is normal!** The preview should:
211
- - Disappear from input area after sending
212
- - Appear in your message bubble
213
- - Stay visible in chat history
214
-
215
- If it's not appearing in message bubble:
216
- 1. Check browser console
217
- 2. Verify response includes `image_url`
218
- 3. Check Supabase storage upload succeeded
219
-
220
- ---
221
-
222
- ## Architecture Flow
223
-
224
- ### Upload → Display → Send → AI Process
225
-
226
- ```
227
- 1. User selects image
228
-
229
- 2. FileReader creates base64 preview
230
-
231
- 3. Preview shows ABOVE input (300x200px)
232
-
233
- 4. User types message + clicks Send
234
-
235
- 5. Frontend: sendMultimodalMessage()
236
- - Uploads original file to Supabase
237
- - Includes base64 in message for display
238
-
239
- 6. Backend: /api/chat/multimodal
240
- - Saves temp copy of image
241
- - Calls Groq Vision API
242
- - Gets AI description
243
-
244
- 7. Groq Vision: describe_image()
245
- - Encodes to base64
246
- - Sends to llama-3.2-90b-vision-preview
247
- - Returns description
248
-
249
- 8. Backend: Reasoning Engine
250
- - Combines: user text + image description
251
- - Generates answer
252
-
253
- 9. Response to frontend
254
- - Answer text
255
- - Confidence score
256
- - Image URL for display
257
- - Explainability data
258
-
259
- 10. Display in chat
260
- - User bubble: image + text
261
- - AI bubble: answer + confidence
262
- ```
263
-
264
- ---
265
-
266
- ## Files Modified Summary
267
-
268
- ### Frontend (`frontend/src/pages/Chat.jsx`)
269
- - **Added:** Large preview card above input (lines 691-744)
270
- - **Removed:** Inline 60px thumbnail (lines 785-853)
271
- - **Result:** Single, large preview matching your screenshots
272
-
273
- ### Backend (`backend/api/chat.py`)
274
- - **Enhanced:** Image processing logging (lines 220-270)
275
- - **Added:** Detailed step-by-step tracking
276
- - **Added:** Error type logging
277
- - **Result:** Full visibility into image processing
278
-
279
- ### Backend (`backend/utils/groq_client.py`)
280
- - **Enhanced:** describe_image() function (lines 156-230)
281
- - **Added:** File validation
282
- - **Added:** API call logging
283
- - **Added:** Response preview logging
284
- - **Result:** Complete Groq API debugging
285
-
286
- ---
287
-
288
- ## Next Steps
289
-
290
- 1. **Test the changes** - Upload an image and verify:
291
- - Preview appears above input (large, not inline)
292
- - MEXAR recognizes and describes the image
293
- - Backend logs show successful Groq API calls
294
-
295
- 2. **Watch backend logs** - Look for:
296
- - `[MULTIMODAL]` tags for upload/processing
297
- - `[GROQ VISION]` tags for API calls
298
- - Success messages with description preview
299
-
300
- 3. **If Groq still fails:**
301
- - Share the backend log output
302
- - Check if GROQ_API_KEY has vision access
303
- - Try test script: `python backend/test_groq_vision.py`
304
-
305
- ---
306
-
307
- ## Success Criteria ✅
308
-
309
- - [ ] Image preview appears ABOVE input (like screenshot #3)
310
- - [ ] Preview is large (300x200px max), not tiny (60px)
311
- - [ ] Image shows in your message bubble after sending
312
- - [ ] MEXAR actually describes the image content
313
- - [ ] Backend logs show `[GROQ VISION] Success!`
314
- - [ ] No more "I don't have information about the image"
315
-
316
- All changes are complete and ready for testing!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
FIX_SQLALCHEMY_F405.md DELETED
@@ -1,78 +0,0 @@
1
- # SQLAlchemy f405 Error Fix
2
-
3
- ## Error
4
- ```
5
- sqlalchemy.exc.AmbiguousForeignKeysError:
6
- Could not determine join condition between parent/child tables on relationship
7
- (Background on this error at: https://sqlalche.me/e/20/f405)
8
- ```
9
-
10
- ## Root Cause
11
- The `User` model was missing the `conversations` relationship, causing SQLAlchemy to be unable to properly join the tables when querying conversations.
12
-
13
- ## Fix Applied
14
-
15
- **File:** `backend/models/user.py`
16
-
17
- **Added:**
18
- ```python
19
- from sqlalchemy.orm import relationship
20
-
21
- # Inside User class:
22
- # Relationships
23
- conversations = relationship("Conversation", backref="user", cascade="all, delete-orphan")
24
- ```
25
-
26
- ## Why This Fixes It
27
-
28
- The SQLAlchemy f405 error occurs when there's an ambiguous or missing relationship definition. In this case:
29
-
30
- - `Conversation` model had:
31
- - `user_id = ForeignKey("users.id")`
32
- - Trying to create a back-reference to User
33
-
34
- - `User` model was missing the corresponding relationship definition
35
-
36
- - SQLAlchemy couldn't determine how to join the tables
37
-
38
- By adding the `conversations` relationship to the User model:
39
- - ✅ Complete bidirectional relationship established
40
- - ✅ SQLAlchemy can now properly join User ↔ Conversation
41
- - ✅ Cascade delete works properly (when user deleted, conversations deleted)
42
- - ✅ No ambiguity in foreign key relationships
43
-
44
- ## Testing
45
-
46
- The uvicorn server should have automatically reloaded. Try:
47
-
48
- 1. Upload an image in the chat
49
- 2. Send a message
50
- 3. Check that no SQLAlchemy errors appear in backend logs
51
- 4. Verify message is saved to database
52
-
53
- ## Related Models
54
-
55
- All relationships are now properly defined:
56
-
57
- ```
58
- User
59
- ↓ (one-to-many)
60
- conversations[] ✅
61
- agents[] ✅
62
-
63
- Agent
64
- ↓ (one-to-many)
65
- conversations[] ✅
66
- compilation_jobs[] ✅
67
- chunks[] ✅
68
-
69
- Conversation
70
- ↓ (one-to-many)
71
- messages[] ✅
72
- ↑ (many-to-one)
73
- user ✅ (via backref)
74
- agent ✅ (via back_populates)
75
- ```
76
-
77
- ## Status
78
- ✅ **FIXED** - The relationship is now complete and the error should be resolved.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
backend/Dockerfile ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # Install system dependencies
6
+ RUN apt-get update && apt-get install -y \
7
+ gcc \
8
+ g++ \
9
+ postgresql-client \
10
+ && rm -rf /var/lib/apt/lists/*
11
+
12
+ # Copy requirements and install Python packages
13
+ COPY requirements.txt .
14
+ RUN pip install --no-cache-dir -r requirements.txt
15
+
16
+ # Copy application code
17
+ COPY . .
18
+
19
+ # Set environment for model caching to /tmp (only writable dir in HF Spaces)
20
+ ENV HF_HOME=/tmp/.cache/huggingface
21
+ ENV FASTEMBED_CACHE_PATH=/tmp/.cache/fastembed
22
+ ENV SENTENCE_TRANSFORMERS_HOME=/tmp/.cache/sentence-transformers
23
+
24
+ # Expose port 7860 (required by Hugging Face Spaces)
25
+ EXPOSE 7860
26
+
27
+ # Run FastAPI with uvicorn
28
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
backend/main.py CHANGED
@@ -73,9 +73,21 @@ app = FastAPI(
73
  )
74
 
75
  # Configure CORS
 
 
 
 
 
 
 
 
 
 
 
 
76
  app.add_middleware(
77
  CORSMiddleware,
78
- allow_origins=["*"],
79
  allow_credentials=True,
80
  allow_methods=["*"],
81
  allow_headers=["*"],
 
73
  )
74
 
75
  # Configure CORS
76
+ # Configure CORS
77
+ # CRITICAL: Configure CORS for Vercel frontend
78
+ FRONTEND_URL = os.getenv("FRONTEND_URL", "http://localhost:3000")
79
+
80
+ allow_origins = [
81
+ "*",
82
+ FRONTEND_URL,
83
+ "https://*.vercel.app",
84
+ "http://localhost:3000",
85
+ "http://localhost:3001"
86
+ ]
87
+
88
  app.add_middleware(
89
  CORSMiddleware,
90
+ allow_origins=allow_origins,
91
  allow_credentials=True,
92
  allow_methods=["*"],
93
  allow_headers=["*"],
backend/modules/knowledge_compiler.py CHANGED
@@ -48,8 +48,13 @@ class KnowledgeCompiler:
48
 
49
  # Initialize embedding model (384 dim default)
50
  try:
51
- self.embedding_model = TextEmbedding(model_name="BAAI/bge-small-en-v1.5")
52
- logger.info("FastEmbed model loaded")
 
 
 
 
 
53
  except Exception as e:
54
  logger.warning(f"Failed to load embedding model: {e}")
55
  self.embedding_model = None
 
48
 
49
  # Initialize embedding model (384 dim default)
50
  try:
51
+ # Force cache to /tmp for HF Spaces or use env var
52
+ cache_dir = os.getenv("FASTEMBED_CACHE_PATH", "/tmp/.cache/fastembed")
53
+ self.embedding_model = TextEmbedding(
54
+ model_name="BAAI/bge-small-en-v1.5",
55
+ cache_dir=cache_dir
56
+ )
57
+ logger.info(f"FastEmbed model loaded (cache: {cache_dir})")
58
  except Exception as e:
59
  logger.warning(f"Failed to load embedding model: {e}")
60
  self.embedding_model = None