File size: 6,398 Bytes
7643a03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b0538ac
7643a03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# **Auto-Analyst API Documentation**

The core application routes are designed to manage the data and AI analysis capabilities of the Auto-Analyst application.

## **1. Core Application Routes**
### **Data Management**

#### **POST /upload_dataframe**  
Uploads a CSV dataset for analysis.  
**Request:**  
- `file`: CSV file  
- `name`: Dataset name  
- `description`: Dataset description  
**Headers:**
- `X-Force-Refresh`: "true" (optional) - Forces session reset before upload
**Response:**  
```json
{ "message": "Dataframe uploaded successfully", "session_id": "abc123" }
```

#### **POST /upload_excel**  
Uploads an Excel file with a specific sheet for analysis.  
**Request:**  
- `file`: Excel file  
- `name`: Dataset name  
- `description`: Dataset description  
- `sheet_name`: Name of the Excel sheet to use
**Headers:**
- `X-Force-Refresh`: "true" (optional) - Forces session reset before upload
**Response:**  
```json
{ "message": "Excel file processed successfully", "session_id": "abc123", "sheet": "Sheet1" }
```

#### **POST /api/excel-sheets**  
Gets the list of sheet names from an Excel file.  
**Request:**  
- `file`: Excel file  
**Response:**  
```json
{ "sheets": ["Sheet1", "Sheet2", "Data"] }
```

#### **GET /api/default-dataset**  
Gets the default dataset.  
**Response:**  
```json
{
  "headers": ["column1", "column2", ...],
  "rows": [[val1, val2, ...], ...],
  "name": "Housing Dataset",
  "description": "A comprehensive dataset containing housing information..."
}
```

#### **POST /reset-session**  
Resets session to default dataset.  
**Request Body:**  
```json
{
  "name": "optional name",
  "description": "optional description",
  "preserveModelSettings": false
}
```
**Response:**  
```json
{
  "message": "Session reset to default dataset",
  "session_id": "abc123",
  "dataset": "Housing.csv"
}
```

#### **GET /api/preview-csv** / **POST /api/preview-csv**  
Preview the current dataset in the session.
**Response:**  
```json
{
  "headers": ["column1", "column2", ...],
  "rows": [[val1, val2, ...], ...],
  "name": "Dataset Name",
  "description": "Dataset description..."
}
```

---

### **2. AI Analysis**

#### **POST /chat/{agent_name}**  
Processes a query using a specific AI agent.  
**Path Parameters:** `agent_name`  
**Request Body:**  
```json
{ "query": "Analyze the relationship between price and size" }
```
**Query Parameters:** `user_id` (optional), `chat_id` (optional)  
**Response:**  
```json
{
  "agent_name": "data_viz_agent",
  "query": "Analyze the relationship between price and size",
  "response": "# Analysis\n\nThere appears to be a strong positive correlation...",
  "session_id": "abc123"
}
```

#### **POST /chat**  
Processes a query using multiple AI agents with streaming responses.  
**Request Body:**  
```json
{ "query": "Analyze the housing data" }
```
**Query Parameters:** `user_id` (optional), `chat_id` (optional)  
**Response:** *Streaming JSON objects:*  
```json
{"agent": "data_viz_agent", "content": "# Visualization\n\n...", "status": "success"}
{"agent": "statistical_analytics_agent", "content": "# Statistical Analysis\n\n...", "status": "success"}
```

#### **POST /chat_history_name**  
Generates a name for a chat based on the query.  
**Request Body:**  
```json
{ "query": "Analyze sales data for Q4" }
```
**Response:**  
```json
{ "name": "Chat about sales data analysis" }
```

#### **GET /agents**  
Lists available AI agents.  
**Response:**  
```json
{
  "available_agents": ["data_viz_agent", "sk_learn_agent", "statistical_analytics_agent", "preprocessing_agent"],
  "standard_agents": ["preprocessing_agent", "statistical_analytics_agent", "sk_learn_agent", "data_viz_agent"],
  "template_agents": ["custom_template_1", "custom_template_2"],
  "custom_agents": []
}
```

---

### **3. Deep Analysis**

#### **POST /deep_analysis_streaming**  
Performs comprehensive deep analysis with real-time streaming updates.  
**Request Body:**  
```json
{ "goal": "Perform comprehensive analysis of the sales data" }
```
**Query Parameters:** `user_id` (optional), `chat_id` (optional)  
**Response:** *Streaming JSON objects with progress updates*

#### **POST /deep_analysis/download_report**  
Downloads an HTML report from deep analysis results.  
**Request Body:**  
```json
{
  "analysis_data": { ... },
  "report_uuid": "optional-uuid"
}
```
**Response:** HTML file download

---

### **4. Model Settings**

#### **GET /api/model-settings**  
Fetches current model settings.  
**Response:**  
```json
{
  "provider": "openai",
  "model": "gpt-4o-mini",
  "hasCustomKey": true,
  "temperature": 1.0,
  "maxTokens": 6000
}
```

#### **POST /settings/model**  
Updates model settings.  
**Request Body:**  
```json
{
  "provider": "openai",
  "model": "gpt-4",
  "api_key": "sk-...",
  "temperature": 0.7,
  "max_tokens": 8000
}
```
**Response:**  
```json
{ "message": "Model settings updated successfully" }
```

---

### **5. Session Management**

#### **GET /api/session-info**  
Gets information about the current session.  
**Response:**  
```json
{
  "session_id": "abc123",
  "dataset_name": "Housing Dataset",
  "dataset_description": "...",
  "model_config": { ... }
}
```

#### **POST /set-message-info**  
Associates message tracking information with the session.  
**Request Body:**  
```json
{
  "chat_id": 123,
  "message_id": 456,
  "user_id": 789
}
```

#### **POST /create-dataset-description**  
Creates an AI-generated description for a dataset.  
**Request Body:**  
```json
{
  "df_preview": "column1,column2\nvalue1,value2\n...",
  "name": "Dataset Name"
}
```

---

### **6. System Endpoints**

#### **GET /**  
Returns API welcome information and feature list.

#### **GET /health**  
Health check endpoint.  
**Response:**  
```json
{ "message": "API is healthy and running" }
```

---

---

### **7. Authentication & Session Management**
- **Session ID Sources:**  
  - Query parameter: `session_id`  
  - Header: `X-Session-ID`  
  - Auto-generated if not provided  
- **Session State Includes:**  
  - Current dataset  
  - AI system instance  
  - Model configuration  
  - User and chat associations

### **9. Error Handling**
- Comprehensive error handling with appropriate HTTP status codes
- Detailed error messages for debugging
- Fallback encoding support for CSV files (UTF-8, unicode_escape, ISO-8859-1)
- Session state preservation during errors