File size: 8,851 Bytes
3f0e018
 
 
 
 
 
 
 
 
 
 
439ebb4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4b28fb0
439ebb4
 
4b28fb0
439ebb4
4b28fb0
 
 
 
439ebb4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4b28fb0
 
 
 
 
 
 
 
 
 
 
 
 
 
439ebb4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4b28fb0
439ebb4
 
 
4b28fb0
 
 
 
 
439ebb4
 
 
4b28fb0
 
f0b765c
4b28fb0
 
 
 
 
f0b765c
4b28fb0
 
 
f0b765c
439ebb4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4b34d35
 
f0b765c
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
---
title: Atlas - AI Chat API
emoji: πŸ€–
colorFrom: blue
colorTo: purple
sdk: docker
sdk_version: "4.36.0"
app_file: app.py
pinned: false
---

# Atlas - AI Chat API with Anonymous & Authenticated Modes

Atlas is an enhanced chat API service that provides intelligent question-answering capabilities with web search augmentation and comprehensive analytics. It supports both anonymous usage (no authentication required) and authenticated user tracking.

## πŸš€ Quick Start (Anonymous Mode)

Get started immediately without any setup or authentication:

```bash
# Simple anonymous chat request
curl -X POST https://your-atlas-api.com/chat \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "What is artificial intelligence?",
    "use_search": true
  }'
```

## πŸ“‹ Features

### πŸ€– AI-Powered Chat
- Uses Google's Gemini 1.5 Flash model
- Configurable parameters (temperature, max tokens)
- Intelligent responses based on web search results
- Session-based conversation tracking

### πŸ” Advanced Web Search & Optimization
- **Dual Search Engine Strategy**: Brave Search + DuckDuckGo
- **Resilient Fallback**: Automatic fallback if one engine fails
- **Smart Query Extraction**: NLP-powered search term extraction using spaCy and RAKE
- **Deduplication**: Removes duplicate results across engines
- **🧠 Intelligent Search Optimization**: AI-powered search decision engine
- **⚑ Context-Aware Flow**: Cache-first for new conversations, smart decisions for follow-ups
- **πŸ—„οΈ ChromaDB Vector Caching**: Semantic similarity matching with persistent storage
- **πŸ“Š Search Analytics**: Comprehensive search decision and performance tracking

### πŸ‘€ Flexible User Modes
- **Anonymous Mode**: Use immediately without authentication
- **Authenticated Mode**: User tracking and personalized history
- **Progressive Enhancement**: Start anonymous, add auth later
- **Privacy-First**: No tracking in anonymous mode

### πŸ“Š Comprehensive Analytics
- **Real-time Session Tracking**: Monitor user sessions and activity
- **Message Analytics**: Track response times, search usage, and success rates
- **Interactive Dashboard**: Beautiful HTML dashboard with charts and metrics
- **Data Export**: Export analytics data in JSON or CSV format
- **Anonymous vs Authenticated**: Separate tracking for different user modes

## πŸ”§ API Usage Examples

### Anonymous Usage (No Authentication)

**Basic Request:**
```javascript
const response = await fetch('/chat', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    prompt: "Explain quantum computing",
    use_search: true
  })
});
```

**With Conversation History:**
```javascript
const response = await fetch('/chat', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    prompt: "Can you elaborate on that?",
    use_search: false,
    history: [
      {role: "user", content: "What is machine learning?"},
      {role: "assistant", content: "Machine learning is..."}
    ]
  })
});
```

**With Search Optimization Controls:**
```javascript
const response = await fetch('/chat', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    prompt: "What are the latest AI developments?",
    use_search: true,
    search_decision_mode: "aggressive", // "conservative", "balanced", "aggressive"
    force_search: true // Override smart search optimization
  })
});
```

### Authenticated Usage (With User Tracking)

**Authenticated Request:**
```javascript
const response = await fetch('/chat', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    prompt: "What's my chat history?",
    user_id: "user123",
    use_search: true
  })
});
```

### Python Client Example

```python
import requests

def chat_anonymous(prompt, use_search=True):
    """Send anonymous chat request"""
    response = requests.post('https://your-atlas-api.com/chat', 
        json={
            'prompt': prompt,
            'use_search': use_search
        }
    )
    return response.json()

def chat_authenticated(prompt, user_id, use_search=True):
    """Send authenticated chat request"""
    response = requests.post('https://your-atlas-api.com/chat', 
        json={
            'prompt': prompt,
            'user_id': user_id,
            'use_search': use_search
        }
    )
    return response.json()

# Anonymous usage
result = chat_anonymous("What is AI?")
print(result['response'])

# Authenticated usage  
result = chat_authenticated("What is AI?", "user123")
print(result['response'])
```

## 🌐 API Endpoints

### Core Functionality
- **`/`** - Health check and status
- **`/chat`** - Main chat endpoint (supports both anonymous and authenticated)
- **`/search`** - Direct search functionality
- **`/docs`** - Interactive API documentation (Swagger UI)

### Analytics & Cache Management
- **`/analytics/stats`** - JSON API with analytics statistics
- **`/analytics/dashboard`** - Interactive HTML dashboard with charts
- **`/analytics/export`** - Export analytics data (JSON/CSV format)
- **`/analytics/cache`** - Cache performance metrics and statistics
- **`/analytics/cache/clear`** - Cache management and maintenance
- **`/analytics/users`** - User statistics and anonymous vs authenticated metrics
- **`/analytics/user/{user_id}`** - Individual user analytics and insights
- **`/analytics/comparison`** - Detailed authenticated vs anonymous comparison

## πŸ“– Documentation

### API & Integration
- **[API Integration Guide](docs/api/integration-guide.md)** - Comprehensive integration examples with new parameters
- **[Anonymous API Examples](docs/api/anonymous-examples.md)** - Sample API calls for anonymous usage
- **[Search Optimization Guide](docs/features/search-optimization.md)** - Smart search features and configuration

### Development & Setup  
- **[Setup Guide](docs/setup/SETUP.md)** - Local development setup with all features
- **[Developer Guide](docs/developer/search-optimizer-guide.md)** - Search optimization internals and customization
- **[Deployment Guide](docs/deployment/DEPLOYMENT.md)** - Production deployment instructions

### Troubleshooting & Reference
- **[Optimization Troubleshooting](docs/troubleshooting/optimization-troubleshooting.md)** - Search and cache issues
- **[Migration Guide](docs/reference/migration-guide.md)** - Database migration instructions

## πŸ”’ Privacy & Security

### Anonymous Mode
- **No Tracking**: Zero personal data collection
- **No Registration**: Use immediately without accounts
- **Privacy-First**: Requests processed without user identification
- **Same Functionality**: Full AI and search capabilities

### Authenticated Mode
- **Optional**: Only when you need user-specific features
- **Secure**: Proper user ID validation and sanitization
- **Flexible**: Easy to switch between modes
- **Data Control**: Users control their data association

## πŸš€ Getting Started

### 1. Anonymous Usage (Immediate)
```bash
curl -X POST https://your-atlas-api.com/chat \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Hello, how are you?"}'
```

### 2. With Session Continuity
```bash
curl -X POST https://your-atlas-api.com/chat \
  -H "Content-Type: application/json" \
  -H "X-Session-ID: your-session-id" \
  -d '{"prompt": "Continue our conversation"}'
```

### 3. Authenticated Usage
```bash
curl -X POST https://your-atlas-api.com/chat \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "What is my history?",
    "user_id": "user123"
  }'
```

## πŸ“Š Analytics & Monitoring

Access comprehensive analytics at `/analytics/dashboard`:

- **Usage Statistics**: Total messages, sessions, active users
- **Performance Metrics**: Response times, success rates
- **Search Analytics**: Engine performance, query patterns
- **User Modes**: Anonymous vs authenticated usage breakdown
- **Real-time Updates**: Live dashboard with auto-refresh

## πŸ› οΈ Integration Patterns

### Progressive Enhancement
```javascript
class ChatClient {
  constructor(apiUrl) {
    this.apiUrl = apiUrl;
    this.userId = null; // Start anonymous
  }
  
  authenticate(userId) {
    this.userId = userId; // Enable user tracking
  }
  
  logout() {
    this.userId = null; // Return to anonymous
  }
  
  async sendMessage(prompt) {
    const body = { prompt, use_search: true };
    if (this.userId) body.user_id = this.userId;
    
    return fetch(`${this.apiUrl}/chat`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(body)
    });
  }
}
```

## πŸ“„ License

MIT License - see LICENSE file for details.

---

**Ready to get started?** Try an anonymous request right now, or check out the [API Integration Guide](docs/api/integration-guide.md) for comprehensive examples!