File size: 9,918 Bytes
e83f5e9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 |
# API Documentation
## Frontend Setup
```javascript
// Basic Axios setup
import axios from 'axios';
const api = axios.create({
baseURL: 'https://api.your-domain.com',
timeout: 10000,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
});
// Error handling
api.interceptors.response.use(
response => response.data,
error => {
const errorMessage = error.response?.data?.detail || 'An error occurred';
console.error('API Error:', errorMessage);
return Promise.reject(errorMessage);
}
);
```
## Caching System
- All GET endpoints support `use_cache=true` parameter (default)
- Cache TTL: 300 seconds (5 minutes)
- Cache is automatically invalidated on data changes
## Authentication
Currently no authentication is required. If implemented in the future, use JWT Bearer tokens:
```javascript
const api = axios.create({
// ...other config
headers: {
// ...other headers
'Authorization': `Bearer ${token}`
}
});
```
## Error Codes
| Code | Description |
|------|-------------|
| 400 | Bad Request |
| 404 | Not Found |
| 500 | Internal Server Error |
| 503 | Service Unavailable |
## PostgreSQL Endpoints
### FAQ Endpoints
#### Get FAQs List
```
GET /postgres/faq
```
Parameters:
- `skip`: Number of items to skip (default: 0)
- `limit`: Maximum items to return (default: 100)
- `active_only`: Return only active items (default: false)
- `use_cache`: Use cached data if available (default: true)
Response:
```json
[
{
"question": "How do I book a hotel?",
"answer": "You can book a hotel through our app or website.",
"is_active": true,
"id": 1,
"created_at": "2023-01-01T00:00:00",
"updated_at": "2023-01-01T00:00:00"
}
]
```
Example:
```javascript
async function getFAQs() {
try {
const data = await api.get('/postgres/faq', {
params: { active_only: true, limit: 20 }
});
return data;
} catch (error) {
console.error('Error fetching FAQs:', error);
throw error;
}
}
```
#### Create FAQ
```
POST /postgres/faq
```
Request Body:
```json
{
"question": "How do I book a hotel?",
"answer": "You can book a hotel through our app or website.",
"is_active": true
}
```
Response: Created FAQ object
#### Get FAQ Detail
```
GET /postgres/faq/{faq_id}
```
Parameters:
- `faq_id`: ID of FAQ (required)
- `use_cache`: Use cached data if available (default: true)
Response: FAQ object
#### Update FAQ
```
PUT /postgres/faq/{faq_id}
```
Parameters:
- `faq_id`: ID of FAQ to update (required)
Request Body: Partial or complete FAQ object
Response: Updated FAQ object
#### Delete FAQ
```
DELETE /postgres/faq/{faq_id}
```
Parameters:
- `faq_id`: ID of FAQ to delete (required)
Response:
```json
{
"status": "success",
"message": "FAQ item 1 deleted"
}
```
#### Batch Operations
Create multiple FAQs:
```
POST /postgres/faqs/batch
```
Update status of multiple FAQs:
```
PUT /postgres/faqs/batch-update-status
```
Delete multiple FAQs:
```
DELETE /postgres/faqs/batch
```
### Emergency Contact Endpoints
#### Get Emergency Contacts
```
GET /postgres/emergency
```
Parameters:
- `skip`: Number of items to skip (default: 0)
- `limit`: Maximum items to return (default: 100)
- `active_only`: Return only active items (default: false)
- `use_cache`: Use cached data if available (default: true)
Response: Array of Emergency Contact objects
#### Create Emergency Contact
```
POST /postgres/emergency
```
Request Body:
```json
{
"name": "Fire Department",
"phone_number": "114",
"description": "Fire rescue services",
"address": "Da Nang",
"location": "16.0544, 108.2022",
"priority": 1,
"is_active": true
}
```
Response: Created Emergency Contact object
#### Get Emergency Contact
```
GET /postgres/emergency/{emergency_id}
```
#### Update Emergency Contact
```
PUT /postgres/emergency/{emergency_id}
```
#### Delete Emergency Contact
```
DELETE /postgres/emergency/{emergency_id}
```
#### Batch Operations
Create multiple Emergency Contacts:
```
POST /postgres/emergency/batch
```
Update status of multiple Emergency Contacts:
```
PUT /postgres/emergency/batch-update-status
```
Delete multiple Emergency Contacts:
```
DELETE /postgres/emergency/batch
```
### Event Endpoints
#### Get Events
```
GET /postgres/events
```
Parameters:
- `skip`: Number of items to skip (default: 0)
- `limit`: Maximum items to return (default: 100)
- `active_only`: Return only active items (default: false)
- `featured_only`: Return only featured items (default: false)
- `use_cache`: Use cached data if available (default: true)
Response: Array of Event objects
#### Create Event
```
POST /postgres/events
```
Request Body:
```json
{
"name": "Da Nang Fireworks Festival",
"description": "International Fireworks Festival Da Nang 2023",
"address": "Dragon Bridge, Da Nang",
"location": "16.0610, 108.2277",
"date_start": "2023-06-01T19:00:00",
"date_end": "2023-06-01T22:00:00",
"price": [
{"type": "VIP", "amount": 500000},
{"type": "Standard", "amount": 300000}
],
"url": "https://danangfireworks.com",
"is_active": true,
"featured": true
}
```
Response: Created Event object
#### Get Event
```
GET /postgres/events/{event_id}
```
#### Update Event
```
PUT /postgres/events/{event_id}
```
#### Delete Event
```
DELETE /postgres/events/{event_id}
```
#### Batch Operations
Create multiple Events:
```
POST /postgres/events/batch
```
Update status of multiple Events:
```
PUT /postgres/events/batch-update-status
```
Delete multiple Events:
```
DELETE /postgres/events/batch
```
### About Pixity Endpoints
#### Get About Pixity
```
GET /postgres/about-pixity
```
Response:
```json
{
"content": "PiXity is your smart, AI-powered local companion...",
"id": 1,
"created_at": "2023-01-01T00:00:00",
"updated_at": "2023-01-01T00:00:00"
}
```
#### Update About Pixity
```
PUT /postgres/about-pixity
```
Request Body:
```json
{
"content": "PiXity is your smart, AI-powered local companion..."
}
```
Response: Updated About Pixity object
### Da Nang Bucket List Endpoints
#### Get Da Nang Bucket List
```
GET /postgres/danang-bucket-list
```
Response: Bucket List object with JSON content string
#### Update Da Nang Bucket List
```
PUT /postgres/danang-bucket-list
```
### Solana Summit Endpoints
#### Get Solana Summit
```
GET /postgres/solana-summit
```
Response: Solana Summit object with JSON content string
#### Update Solana Summit
```
PUT /postgres/solana-summit
```
### Health Check
```
GET /postgres/health
```
Response:
```json
{
"status": "healthy",
"message": "PostgreSQL connection is working",
"timestamp": "2023-01-01T00:00:00"
}
```
## MongoDB Endpoints
### Session Endpoints
#### Create Session
```
POST /session
```
Request Body:
```json
{
"user_id": "user123",
"query": "How do I book a room?",
"timestamp": "2023-01-01T00:00:00",
"metadata": {
"client_info": "web",
"location": "Da Nang"
}
}
```
Response: Created Session object with session_id
#### Update Session with Response
```
PUT /session/{session_id}/response
```
Request Body:
```json
{
"response": "You can book a room through our app or website.",
"response_timestamp": "2023-01-01T00:00:05",
"metadata": {
"response_time_ms": 234,
"model_version": "gpt-4"
}
}
```
Response: Updated Session object
#### Get Session
```
GET /session/{session_id}
```
Response: Session object
#### Get User History
```
GET /history
```
Parameters:
- `user_id`: User ID (required)
- `limit`: Maximum sessions to return (default: 10)
- `skip`: Number of sessions to skip (default: 0)
Response:
```json
{
"user_id": "user123",
"sessions": [
{
"session_id": "60f7a8b9c1d2e3f4a5b6c7d8",
"query": "How do I book a room?",
"timestamp": "2023-01-01T00:00:00",
"response": "You can book a room through our app or website.",
"response_timestamp": "2023-01-01T00:00:05"
}
],
"total_count": 1
}
```
#### Health Check
```
GET /health
```
## RAG Endpoints
### Create Embedding
```
POST /embedding
```
Request Body:
```json
{
"text": "Text to embed"
}
```
Response:
```json
{
"embedding": [0.1, 0.2, 0.3, ...],
"dimensions": 1536
}
```
### Process Chat Request
```
POST /chat
```
Request Body:
```json
{
"query": "Can you tell me about Pixity?",
"chat_history": [
{"role": "user", "content": "Hello"},
{"role": "assistant", "content": "Hello! How can I help you?"}
]
}
```
Response:
```json
{
"answer": "Pixity is a platform...",
"sources": [
{
"document_id": "doc123",
"chunk_id": "chunk456",
"chunk_text": "Pixity was founded in...",
"relevance_score": 0.92
}
]
}
```
### Direct RAG Query
```
POST /rag
```
Request Body:
```json
{
"query": "Can you tell me about Pixity?",
"namespace": "about_pixity",
"top_k": 3
}
```
Response: Query results with relevance scores
### Health Check
```
GET /health
```
## PDF Processing Endpoints
### Upload and Process PDF
```
POST /pdf/upload
```
Form Data:
- `file`: PDF file (required)
- `namespace`: Vector database namespace (default: "Default")
- `index_name`: Vector database index name (default: "testbot768")
- `title`: Document title (optional)
- `description`: Document description (optional)
- `user_id`: User ID for WebSocket updates (optional)
Response: Processing results with document_id
### Delete Documents in Namespace
```
DELETE /pdf/namespace
```
Parameters:
- `namespace`: Vector database namespace (default: "Default")
- `index_name`: Vector database index name (default: "testbot768")
- `user_id`: User ID for WebSocket updates (optional)
Response: Deletion results
### Get Documents List
```
GET /pdf/documents
```
Parameters:
- `namespace`: Vector database namespace (default: "Default")
- `index_name`: Vector database index name (default: "testbot768")
Response: List of documents in the namespace |