|
| 1 | +--- |
| 2 | +title: API Reference |
| 3 | +order: 1 |
| 4 | +--- |
| 5 | + |
| 6 | +# API Route Documentation |
| 7 | + |
| 8 | +Introduction |
| 9 | +Welcome to the Amica API Documentation. Amica is a powerful 3D VRM (Virtual Reality Model) agent interface and hub that allows users to connect with external web services and servers, enabling seamless remote control and puppetry of the VRM characters. With Amica, you can create interactive agents that serve as dynamic 3D character interfaces for applications and users. |
| 10 | + |
| 11 | +The Amica API provides a set of flexible and robust routes for interacting with Amica’s system, including functions like real-time client connections, memory retrieval, system updates, social media integration, and more. These capabilities enable you to build custom logic, including reasoning and memory management, on external servers. |
| 12 | + |
| 13 | +Whether you're using Amica to handle real-time interactions or to trigger complex actions based on user input, this documentation will guide you through the supported API routes, input types, and examples. Use Amica’s APIs to bring your 3D agents to life with rich functionality and integration. |
| 14 | + |
| 15 | +This documentation will help you get started with the following key features: |
| 16 | + |
| 17 | +- Real-Time Interaction: Establish and manage connections through Server-Sent Events (SSE). |
| 18 | + |
| 19 | +- Memory Management: Store and retrieve subconscious prompts or custom data. |
| 20 | + |
| 21 | +- Custom Logic & Reasoning: Trigger actions like animations, playback, and social media posts. |
| 22 | + |
| 23 | +- Voice and Image Processing: Leverage transcription and image-to-text capabilities. |
| 24 | + |
| 25 | +- Data Handling: Retrieve and update server-side data via simple file-based operations. (Coming soon) |
| 26 | + |
| 27 | + |
| 28 | +Dive in and start integrating Amica’s capabilities into your applications! |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## Route: `/api/amicaHandler` |
| 33 | + |
| 34 | +This API route handles multiple types of requests, including social media integration, system prompt updates, memory requests, and real-time client connections via Server-Sent Events (SSE). It ensures robust logging and provides error handling for incoming requests. |
| 35 | + |
| 36 | +### Supported HTTP Methods: |
| 37 | + |
| 38 | +- **GET**: Establishes an SSE connection. |
| 39 | +- **POST**: Processes various input types based on the `inputType` provided in the request body. |
| 40 | + |
| 41 | +## Input Types |
| 42 | + |
| 43 | +### 1. **Normal Chat Message**: Retrieve normal chat response from Amica LLM without make avatar speaking. |
| 44 | + |
| 45 | +#### JSON Input Example |
| 46 | + |
| 47 | +```json |
| 48 | +{ |
| 49 | + "inputType": "Normal Chat Message", |
| 50 | + "payload": { |
| 51 | + "message": "Hello, how are you?" |
| 52 | + } |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +#### JSON Output Example |
| 57 | + |
| 58 | +```json |
| 59 | +{ |
| 60 | + "outputType": "Complete stream", |
| 61 | + "response": "I'm doing great! How can I assist you?" |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +### 2. **Memory Request**: Fetches memory data (Subconscious stored prompt). |
| 66 | + |
| 67 | +#### JSON Input Example |
| 68 | + |
| 69 | +```json |
| 70 | +{ |
| 71 | + "inputType": "Memory Request" |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +#### JSON Output Example |
| 76 | + |
| 77 | +```json |
| 78 | +{ |
| 79 | + "outputType": "Memory Array", |
| 80 | + "response": [ |
| 81 | + { |
| 82 | + "timestamp": "2024-12-30T12:00:00Z", |
| 83 | + "prompt": "Stored memory prompt example" |
| 84 | + } |
| 85 | + ] |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +### 3. **RPC Logs**: Fetches logs. |
| 90 | + |
| 91 | +#### JSON Input Example |
| 92 | + |
| 93 | +```json |
| 94 | +{ |
| 95 | + "inputType": "RPC Logs" |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +#### JSON Output Example |
| 100 | + |
| 101 | +```json |
| 102 | +{ |
| 103 | + "outputType": "Webhook", |
| 104 | + "response": [ |
| 105 | + { |
| 106 | + "sessionId": "a1b2c3d4e5f6g7h8", |
| 107 | + "timestamp": "2024-12-30T12:00:00Z", |
| 108 | + "inputType": "Normal Chat Message", |
| 109 | + "outputType": "Complete stream", |
| 110 | + "response": "I'm doing great! How can I assist you?" |
| 111 | + } |
| 112 | + ] |
| 113 | +} |
| 114 | +``` |
| 115 | + |
| 116 | +### 4. **RPC User Input Messages**: Fetches user input messages. |
| 117 | + |
| 118 | +#### JSON Input Example |
| 119 | + |
| 120 | +```json |
| 121 | +{ |
| 122 | + "inputType": "RPC User Input Messages" |
| 123 | +} |
| 124 | +``` |
| 125 | + |
| 126 | +#### JSON Output Example |
| 127 | + |
| 128 | +```json |
| 129 | +{ |
| 130 | + "outputType": "Webhook", |
| 131 | + "response": [ |
| 132 | + { |
| 133 | + "message": "What is the weather today?", |
| 134 | + "timestamp": "2024-12-30T12:05:00Z" |
| 135 | + } |
| 136 | + ] |
| 137 | +} |
| 138 | +``` |
| 139 | + |
| 140 | +### 5. **Update System Prompt**: Updates the system prompt. |
| 141 | + |
| 142 | +#### JSON Input Example |
| 143 | + |
| 144 | +```json |
| 145 | +{ |
| 146 | + "inputType": "Update System Prompt", |
| 147 | + "payload": { |
| 148 | + "prompt": "This is the new system prompt." |
| 149 | + } |
| 150 | +} |
| 151 | +``` |
| 152 | + |
| 153 | +#### JSON Output Example |
| 154 | + |
| 155 | +```json |
| 156 | +{ |
| 157 | + "outputType": "Updated system prompt", |
| 158 | + "response": "System prompt updated successfully." |
| 159 | +} |
| 160 | +``` |
| 161 | + |
| 162 | +### 6. **Twitter Message / Brain Message**: Posts to social media or returns a simple text. |
| 163 | + |
| 164 | +#### JSON Input Example |
| 165 | + |
| 166 | +```json |
| 167 | +{ |
| 168 | + "inputType": "Twitter Message", |
| 169 | + "payload": { |
| 170 | + "text": "Excited to share this update!" |
| 171 | + } |
| 172 | +} |
| 173 | +``` |
| 174 | + |
| 175 | +#### JSON Output Example |
| 176 | + |
| 177 | +```json |
| 178 | +{ |
| 179 | + "outputType": "Text", |
| 180 | + "response": "Posted to Twitter: 'Excited to share this update!'" |
| 181 | +} |
| 182 | +``` |
| 183 | + |
| 184 | +### 7. **Reasoning Server**: Triggers actions like playback, animation, socialMedia and reprocess. |
| 185 | + |
| 186 | +The **Reasoning Server** allows you to execute various actions based on the provided payload. Below are the supported properties and their accepted values: |
| 187 | + |
| 188 | +- **text**: A string message or `null`. |
| 189 | +- **socialMedia**: Options include `"twitter"`, `"tg"`, or `"none"`. |
| 190 | +- **playback**: A boolean value (`true` or `false`). |
| 191 | +- **animation**: A string specifying the animation file name (`file_name.vrma`) or `null`. |
| 192 | +- **reprocess**: A boolean value (`true` or `false`). |
| 193 | + |
| 194 | +#### JSON Input Example |
| 195 | + |
| 196 | +```json |
| 197 | +{ |
| 198 | + "inputType": "Reasoning Server", |
| 199 | + "payload": { |
| 200 | + "text": "Let's begin the presentation.", |
| 201 | + "socialMedia": "twitter", |
| 202 | + "playback": true, |
| 203 | + "animation": "dance.vrma", |
| 204 | + "reprocess": false |
| 205 | + } |
| 206 | +} |
| 207 | +``` |
| 208 | + |
| 209 | +#### JSON Output Example |
| 210 | + |
| 211 | +```json |
| 212 | +{ |
| 213 | + "outputType": "Action Triggered", |
| 214 | + "response": { |
| 215 | + "playback": "Broadcasted to clients", |
| 216 | + "animation": "dance.vrma executed" |
| 217 | + } |
| 218 | +} |
| 219 | +``` |
| 220 | + |
| 221 | +--- |
| 222 | + |
| 223 | +## Route: `/api/mediaHandler` |
| 224 | + |
| 225 | +This API route handles voice and image inputs, leveraging multiple backends for processing, such as transcription with Whisper OpenAI/WhisperCPP and image-to-text processing using Vision LLM. It ensures robust error handling, session logging, and efficient processing for each request. |
| 226 | + |
| 227 | +### Supported HTTP Methods: |
| 228 | + |
| 229 | +- **POST**: Processes voice and image inputs based on the `inputType` and `payload` provided in the request. |
| 230 | + |
| 231 | + |
| 232 | +## Input Types |
| 233 | + |
| 234 | +### 1. **Voice**: Converts audio input to text using specified STT (Speech-to-Text) backends. |
| 235 | + |
| 236 | +### 2. **Image**: Processes an image file to extract text using Vision LLM. |
| 237 | + |
| 238 | +### Form-Data Input Example |
| 239 | + |
| 240 | +| Field Name | Type | Description | |
| 241 | +|---------------|---------------|--------------------------------------------| |
| 242 | +| `inputType` | Text | Specifies the type of input (`Voice` or `Image`). | |
| 243 | +| `payload` | File | The file to be processed (e.g., audio or image). | |
| 244 | + |
| 245 | +#### Curl Input Example |
| 246 | + |
| 247 | +```bash |
| 248 | +curl -X POST "https://example.com/api/mediaHandler" \ |
| 249 | + -H "Content-Type: multipart/form-data" \ |
| 250 | + -F "inputType=Voice" \ |
| 251 | + -F "payload=@input.wav" |
| 252 | +``` |
| 253 | + |
| 254 | +#### JSON Output Example |
| 255 | + |
| 256 | +```json |
| 257 | +{ |
| 258 | + "sessionId": "a1b2c3d4e5f6g7h8", |
| 259 | + "outputType": "Text", |
| 260 | + "response": "Transcription of the audio." |
| 261 | +} |
| 262 | +``` |
| 263 | + |
| 264 | +--- |
| 265 | + |
| 266 | +## Error Handling |
| 267 | + |
| 268 | +- Validates essential fields (`inputType`, `payload`). |
| 269 | +- Logs errors with timestamps and session IDs. |
| 270 | +- Returns appropriate HTTP status codes (e.g., 400 for bad requests, 503 for disabled API). |
| 271 | + |
| 272 | + |
| 273 | +## Logging |
| 274 | + |
| 275 | +Logs each request with: |
| 276 | + |
| 277 | +- `sessionId` |
| 278 | +- `timestamp` |
| 279 | +- `inputType` |
| 280 | +- `outputType` |
| 281 | +- `response` or `error` |
| 282 | + |
| 283 | + |
| 284 | +## Notes |
| 285 | + |
| 286 | +- Ensure environment variable `API_ENABLED` is set to `true` for the API to function. |
| 287 | +- The SSE connection remains active until the client disconnects. |
| 288 | + |
| 289 | +--- |
| 290 | + |
| 291 | +## Route: `/api/dataHandler` |
| 292 | + |
| 293 | +This API route is used to retrieve and update client-side information through server-side operations. Since the application cannot directly update or retrieve data from the server side, these operations involve writing and reading data from static files that are continuously updated. |
| 294 | + |
| 295 | +The primary purpose of this route is to utilize the data written to files for operations performed in the /api/mediaHandler and /api/amicaHandler routes. |
| 296 | + |
| 297 | +### File Paths |
| 298 | + |
| 299 | +1. **`config.json`** |
| 300 | + - **Path**: `config.json` (Root directory) |
| 301 | + - **Description**: Contains the configuration data used throughout the application. This file is read and updated dynamically by the API. |
| 302 | + |
| 303 | +2. **`subconscious.json`** |
| 304 | + - **Path**: `src/features/amicaLife/subconscious.json` |
| 305 | + - **Description**: Stores data related to subconscious operations. It is cleared on startup and updated via the API. |
| 306 | + |
| 307 | +3. **`logs.json`** |
| 308 | + - **Path**: `logs.json` (Root directory) |
| 309 | + - **Description**: Keeps track of log entries, including types, timestamps, and arguments. The data is cleared on startup and updated via the API. |
| 310 | + |
| 311 | +4. **`userInputMessages.json`** |
| 312 | + - **Path**: `src/features/chat/userInputMessages.json` |
| 313 | + - **Description**: Maintains user input messages for chat functionalities. Data is cleared on startup and appended to this file through the API. |
| 314 | + |
| 315 | + |
| 316 | +### Features |
| 317 | + |
| 318 | +- **Retrieve data**: Supports fetching configurations, subconscious data, logs, and user input messages. |
| 319 | +- **Update data**: Enables modifications to configurations, subconscious data, logs, and user input messages. |
| 320 | + |
| 321 | + |
| 322 | +#### **GET** |
| 323 | +Retrieve specific data from the server. |
| 324 | + |
| 325 | +- **Query Parameters**: |
| 326 | + - `type` (required): Specifies the type of data to retrieve. Accepted values: `config`, `subconscious`, `logs`, `userInputMessages`. |
| 327 | + |
| 328 | +- **Example Request**: |
| 329 | + ```bash |
| 330 | + curl -X GET "http://localhost:3000/api/dataHandler?type=config" |
| 331 | + ``` |
| 332 | + |
| 333 | + |
| 334 | +#### **POST** |
| 335 | +Update data on the server. |
| 336 | + |
| 337 | +- **Query Parameters**: |
| 338 | + - `type` (required): Specifies the type of data to update. Accepted values: `config`, `subconscious`, `logs`, `userInputMessages`. |
| 339 | + |
| 340 | +- **Example Request**: |
| 341 | + ```bash |
| 342 | + curl -X POST "http://localhost:3000/api/dataHandler?type=config" \ |
| 343 | + -H "Content-Type: application/json" \ |
| 344 | + -d '{"key": "exampleKey", "value": "exampleValue"}' |
| 345 | + ``` |
| 346 | + |
| 347 | +--- |
0 commit comments