Your Name commited on
Commit
46c32a9
·
1 Parent(s): 46e4d40

Add frontend emotion update mechanism documentation

Browse files
Files changed (1) hide show
  1. Endpoints.md +50 -0
Endpoints.md CHANGED
@@ -302,10 +302,60 @@ All emotions are normalized to values between 0.0 and 1.0:
302
 
303
  ---
304
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
  ## Notes
306
 
307
  - All timestamps are in ISO 8601 format
308
  - Emotional state values are rounded to 2 decimal places in responses
309
  - The system requires all critical components to be ready before serving requests
310
  - Debug mode is enabled by default (`debug=True`)
 
311
 
 
302
 
303
  ---
304
 
305
+ ## Frontend Emotion Updates
306
+
307
+ The frontend updates emotions in two ways:
308
+
309
+ ### 1. Immediate Update (After Chat Messages)
310
+ When a user sends a message via `POST /api/chat`, the response includes the current emotional state:
311
+ ```json
312
+ {
313
+ "response": "...",
314
+ "emotions": {
315
+ "joy": 0.3,
316
+ "sadness": 0.2,
317
+ "anger": 0.1,
318
+ "fear": 0.15,
319
+ "curiosity": 0.25
320
+ }
321
+ }
322
+ ```
323
+ The frontend immediately updates the emotion bars using `updateEmotionBars(data.emotions)`.
324
+
325
+ ### 2. Continuous Polling (Every 1 Second)
326
+ The frontend polls `GET /api/avatar` every 1 second to get real-time emotion updates:
327
+ - **Polling Interval**: 1 second
328
+ - **Endpoint**: `GET /api/avatar`
329
+ - **Purpose**: Updates emotions even when the user is not chatting
330
+ - **Updates Include**:
331
+ - Sentiment-based emotion changes from user messages
332
+ - Quantum-influenced emotion changes (every 10 seconds)
333
+ - Natural emotion decay over time
334
+
335
+ ### Emotion Bar Update Function
336
+ The frontend uses the `updateEmotionBars()` function which:
337
+ - Takes emotion values (0.0 to 1.0 range)
338
+ - Converts to percentages (multiplies by 100)
339
+ - Updates the width of each emotion bar:
340
+ - `joy-bar`
341
+ - `sadness-bar`
342
+ - `anger-bar`
343
+ - `fear-bar`
344
+ - `curiosity-bar`
345
+
346
+ ### Real-Time Updates
347
+ This dual-update mechanism ensures:
348
+ - **Immediate feedback**: Emotions update right after each message
349
+ - **Continuous updates**: Emotions change in real-time even without user interaction
350
+ - **Smooth transitions**: CSS transitions (0.5s ease) provide smooth visual updates
351
+
352
+ ---
353
+
354
  ## Notes
355
 
356
  - All timestamps are in ISO 8601 format
357
  - Emotional state values are rounded to 2 decimal places in responses
358
  - The system requires all critical components to be ready before serving requests
359
  - Debug mode is enabled by default (`debug=True`)
360
+ - Frontend polls `/api/avatar` every 1 second for real-time emotion updates
361