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

Add comprehensive API endpoints documentation

Browse files
Files changed (1) hide show
  1. Endpoints.md +311 -0
Endpoints.md ADDED
@@ -0,0 +1,311 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Galatea AI API Endpoints
2
+
3
+ This document describes all available API endpoints for the Galatea AI application.
4
+
5
+ ## Base URL
6
+ - Local: `http://localhost:7860`
7
+ - Production: Configured via `PORT` environment variable (default: 7860)
8
+
9
+ ## Endpoints
10
+
11
+ ### 1. Home Page
12
+ **GET** `/`
13
+
14
+ Returns the main web interface HTML page.
15
+
16
+ **Response:**
17
+ - `200 OK`: HTML page rendered
18
+ - `500 Internal Server Error`: Template rendering error
19
+
20
+ ---
21
+
22
+ ### 2. Chat Endpoint
23
+ **POST** `/api/chat`
24
+
25
+ Sends a user message to Galatea AI and receives a response.
26
+
27
+ **Request Body:**
28
+ ```json
29
+ {
30
+ "message": "Hello, how are you?"
31
+ }
32
+ ```
33
+
34
+ **Response (Success):**
35
+ ```json
36
+ {
37
+ "response": "I'm doing well, thank you for asking!",
38
+ "avatar_shape": "Circle",
39
+ "emotions": {
40
+ "joy": 0.3,
41
+ "sadness": 0.2,
42
+ "anger": 0.1,
43
+ "fear": 0.15,
44
+ "curiosity": 0.25
45
+ },
46
+ "is_initialized": true
47
+ }
48
+ ```
49
+
50
+ **Response (Not Initialized):**
51
+ ```json
52
+ {
53
+ "error": "System is not initialized yet. Please wait for initialization to complete.",
54
+ "is_initialized": false,
55
+ "status": "initializing"
56
+ }
57
+ ```
58
+ - Status Code: `503 Service Unavailable`
59
+
60
+ **Response (Missing API Key):**
61
+ ```json
62
+ {
63
+ "error": "GEMINI_API_KEY is missing. Chat is unavailable.",
64
+ "status": "missing_gemini_key",
65
+ "is_initialized": false
66
+ }
67
+ ```
68
+ - Status Code: `503 Service Unavailable`
69
+
70
+ **Response (No Message):**
71
+ ```json
72
+ {
73
+ "error": "No message provided"
74
+ }
75
+ ```
76
+ - Status Code: `400 Bad Request`
77
+
78
+ **Notes:**
79
+ - The system must be fully initialized before chat requests are processed
80
+ - If Pi-3.1 model fails to generate a response, the application will exit immediately
81
+ - Emotional state is updated based on sentiment analysis of the user's message
82
+ - Avatar shape changes based on emotional state
83
+
84
+ ---
85
+
86
+ ### 3. Avatar Endpoint
87
+ **GET** `/api/avatar`
88
+
89
+ Retrieves the current avatar state and emotional information.
90
+
91
+ **Response:**
92
+ ```json
93
+ {
94
+ "avatar_shape": "Circle",
95
+ "emotions": {
96
+ "joy": 0.3,
97
+ "sadness": 0.2,
98
+ "anger": 0.1,
99
+ "fear": 0.15,
100
+ "curiosity": 0.25
101
+ },
102
+ "sentiment": {
103
+ "sentiment": "positive",
104
+ "positive": 0.85,
105
+ "negative": 0.15
106
+ },
107
+ "is_initialized": true,
108
+ "last_updated": "2025-11-07T18:00:00",
109
+ "status": "ready"
110
+ }
111
+ ```
112
+
113
+ **Avatar Shapes:**
114
+ - `Circle`: Default/neutral state
115
+ - `Triangle`: High energy/active emotions
116
+ - `Square`: Stable/grounded emotions
117
+
118
+ **Response (Error):**
119
+ ```json
120
+ {
121
+ "error": "Failed to get avatar information",
122
+ "avatar_shape": "Circle",
123
+ "status": "error"
124
+ }
125
+ ```
126
+ - Status Code: `500 Internal Server Error`
127
+
128
+ ---
129
+
130
+ ### 4. Health Check
131
+ **GET** `/health`
132
+
133
+ Simple health check endpoint to verify the server is running.
134
+
135
+ **Response:**
136
+ ```json
137
+ {
138
+ "status": "healthy",
139
+ "timestamp": "2025-11-07T18:00:00"
140
+ }
141
+ ```
142
+ - Status Code: `200 OK`
143
+
144
+ ---
145
+
146
+ ### 5. Availability Check
147
+ **GET** `/api/availability`
148
+
149
+ Checks if the system is available and ready to handle requests.
150
+
151
+ **Response (Available):**
152
+ ```json
153
+ {
154
+ "available": true,
155
+ "is_initialized": true,
156
+ "status": "ready"
157
+ }
158
+ ```
159
+
160
+ **Response (Not Available):**
161
+ ```json
162
+ {
163
+ "available": false,
164
+ "is_initialized": false,
165
+ "status": "initializing",
166
+ "message": "System is still initializing. Please wait."
167
+ }
168
+ ```
169
+
170
+ ---
171
+
172
+ ### 6. Initialization Status
173
+ **GET** `/api/is_initialized`
174
+
175
+ Lightweight endpoint for polling initialization progress (used by frontend).
176
+
177
+ **Response (Initialized):**
178
+ ```json
179
+ {
180
+ "is_initialized": true,
181
+ "initializing": false,
182
+ "missing_gemini_key": false
183
+ }
184
+ ```
185
+
186
+ **Response (Initializing):**
187
+ ```json
188
+ {
189
+ "is_initialized": false,
190
+ "initializing": true,
191
+ "missing_gemini_key": false,
192
+ "status": "initializing",
193
+ "message": "Initializing components..."
194
+ }
195
+ ```
196
+
197
+ **Response (Missing API Key):**
198
+ ```json
199
+ {
200
+ "is_initialized": false,
201
+ "initializing": false,
202
+ "missing_gemini_key": true,
203
+ "error_page": "/error",
204
+ "status": "missing_api_key"
205
+ }
206
+ ```
207
+
208
+ ---
209
+
210
+ ### 7. Status Endpoint
211
+ **GET** `/status`
212
+
213
+ Returns detailed status information about the system.
214
+
215
+ **Response:**
216
+ ```json
217
+ {
218
+ "is_initialized": true,
219
+ "initializing": false,
220
+ "emotions": {
221
+ "joy": 0.3,
222
+ "sadness": 0.2,
223
+ "anger": 0.1,
224
+ "fear": 0.15,
225
+ "curiosity": 0.25
226
+ },
227
+ "avatar_shape": "Circle",
228
+ "missing_gemini_key": false
229
+ }
230
+ ```
231
+
232
+ ---
233
+
234
+ ### 8. Error Page
235
+ **GET** `/error`
236
+
237
+ Renders an informative error page when the app is unavailable.
238
+
239
+ **Response:**
240
+ - `200 OK`: HTML error page
241
+ - Displays information about missing API keys or initialization failures
242
+
243
+ ---
244
+
245
+ ## System Architecture
246
+
247
+ ### Initialization Flow
248
+ 1. **Parallel Initialization** - Runs before Flask app starts:
249
+ - JSON Memory initialization
250
+ - Sentiment Analyzer initialization
251
+ - Gemini API validation
252
+ - Inflection AI API validation
253
+ - Quantum API validation (optional)
254
+
255
+ 2. **Component Initialization** - After parallel init completes:
256
+ - GalateaAI instance creation
257
+ - DialogueEngine initialization
258
+ - AvatarEngine initialization
259
+ - Quantum Emotion Service startup (if API key available)
260
+
261
+ 3. **Flask Server Start** - Only starts if all critical components are ready
262
+
263
+ ### Critical Components
264
+ - **JSON Memory System**: Required
265
+ - **Sentiment Analyzer**: Required
266
+ - **Gemini API**: Required (but allows quota exceeded errors)
267
+ - **Inflection AI API**: Required
268
+
269
+ ### Optional Components
270
+ - **Quantum API**: Optional (falls back to pseudo-random)
271
+
272
+ ---
273
+
274
+ ## Error Handling
275
+
276
+ ### Rate Limits
277
+ - **Gemini API 429**: Treated as valid API key, initialization continues
278
+ - **Quantum API 429**: Falls back to pseudo-random, initialization continues
279
+
280
+ ### Critical Failures
281
+ If any critical component fails to initialize, the application will:
282
+ 1. Log detailed error information
283
+ 2. Exit immediately with `sys.exit(1)`
284
+ 3. No partial functionality is allowed
285
+
286
+ ---
287
+
288
+ ## Emotional State
289
+
290
+ Emotions are stored in `emotions.json` and persist across restarts. The system uses:
291
+ - **Sentiment Analysis**: Updates emotions based on user message sentiment
292
+ - **Quantum Influence**: Background service updates emotions every 10 seconds using quantum random numbers (if available)
293
+ - **Decay**: Emotions slowly decay over time (3% per interaction)
294
+
295
+ ### Emotion Values
296
+ All emotions are normalized to values between 0.0 and 1.0:
297
+ - `joy`: Positive emotions
298
+ - `sadness`: Negative emotions
299
+ - `anger`: Aggressive emotions
300
+ - `fear`: Anxious emotions
301
+ - `curiosity`: Exploratory emotions
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
+