Skip to content

Commit 24e70d3

Browse files
committed
added DTO for engine node manager endpoints
1 parent a24aac7 commit 24e70d3

18 files changed

+1635
-467
lines changed

.vscode/settings.json

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"files.associations": {
3+
"algorithm": "cpp",
4+
"any": "cpp",
5+
"array": "cpp",
6+
"atomic": "cpp",
7+
"bit": "cpp",
8+
"bitset": "cpp",
9+
"cctype": "cpp",
10+
"charconv": "cpp",
11+
"chrono": "cpp",
12+
"cinttypes": "cpp",
13+
"clocale": "cpp",
14+
"cmath": "cpp",
15+
"codecvt": "cpp",
16+
"compare": "cpp",
17+
"concepts": "cpp",
18+
"condition_variable": "cpp",
19+
"csignal": "cpp",
20+
"cstdarg": "cpp",
21+
"cstddef": "cpp",
22+
"cstdint": "cpp",
23+
"cstdio": "cpp",
24+
"cstdlib": "cpp",
25+
"cstring": "cpp",
26+
"ctime": "cpp",
27+
"cwchar": "cpp",
28+
"deque": "cpp",
29+
"exception": "cpp",
30+
"coroutine": "cpp",
31+
"resumable": "cpp",
32+
"filesystem": "cpp",
33+
"format": "cpp",
34+
"forward_list": "cpp",
35+
"fstream": "cpp",
36+
"functional": "cpp",
37+
"future": "cpp",
38+
"initializer_list": "cpp",
39+
"iomanip": "cpp",
40+
"ios": "cpp",
41+
"iosfwd": "cpp",
42+
"iostream": "cpp",
43+
"istream": "cpp",
44+
"iterator": "cpp",
45+
"limits": "cpp",
46+
"list": "cpp",
47+
"locale": "cpp",
48+
"map": "cpp",
49+
"memory": "cpp",
50+
"mutex": "cpp",
51+
"new": "cpp",
52+
"numeric": "cpp",
53+
"optional": "cpp",
54+
"ostream": "cpp",
55+
"queue": "cpp",
56+
"random": "cpp",
57+
"ranges": "cpp",
58+
"ratio": "cpp",
59+
"regex": "cpp",
60+
"set": "cpp",
61+
"shared_mutex": "cpp",
62+
"span": "cpp",
63+
"sstream": "cpp",
64+
"stdexcept": "cpp",
65+
"stop_token": "cpp",
66+
"streambuf": "cpp",
67+
"string": "cpp",
68+
"system_error": "cpp",
69+
"thread": "cpp",
70+
"tuple": "cpp",
71+
"type_traits": "cpp",
72+
"typeinfo": "cpp",
73+
"unordered_map": "cpp",
74+
"unordered_set": "cpp",
75+
"utility": "cpp",
76+
"valarray": "cpp",
77+
"variant": "cpp",
78+
"vector": "cpp",
79+
"xfacet": "cpp",
80+
"xhash": "cpp",
81+
"xiosbase": "cpp",
82+
"xlocale": "cpp",
83+
"xlocbuf": "cpp",
84+
"xlocinfo": "cpp",
85+
"xlocmes": "cpp",
86+
"xlocmon": "cpp",
87+
"xlocnum": "cpp",
88+
"xloctime": "cpp",
89+
"xmemory": "cpp",
90+
"xstring": "cpp",
91+
"xtr1common": "cpp",
92+
"xtree": "cpp",
93+
"xutility": "cpp"
94+
}
95+
}

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/nlohmann)
2222
# Define source files.
2323
set(SOURCES
2424
src/server.cpp
25-
src/server_api.cpp
25+
src/server_api.cpp
2626
src/logger.cpp
2727
src/routes/chat_completion_route.cpp
2828
src/routes/completion_route.cpp
29-
src/routes/models_route.cpp
3029
src/routes/add_engine_route.cpp
3130
src/routes/list_engines_route.cpp
3231
src/routes/remove_engine_route.cpp

docs/add_engine_dto_model.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Add Engine Request DTO Model
2+
3+
This document demonstrates how to use the new `AddEngineRequest` DTO model in the `add_engine_route.cpp`.
4+
5+
## Overview
6+
7+
The `AddEngineRequest` model provides a structured way to handle JSON request parsing for the add engine endpoint, replacing manual JSON parsing with a type-safe, validated model approach.
8+
9+
## Usage Example
10+
11+
### Before (Manual JSON Parsing)
12+
```cpp
13+
// Old approach - manual JSON parsing
14+
auto j = json::parse(body);
15+
std::string engineId = j["engine_id"];
16+
std::string modelPath = j["model_path"];
17+
bool loadImmediately = j.value("load_immediately", true);
18+
19+
if (j.contains("loading_parameters")) {
20+
auto loadParamsJson = j["loading_parameters"];
21+
loadParams.n_ctx = loadParamsJson.value("n_ctx", 4096);
22+
// ... more manual parsing
23+
}
24+
```
25+
26+
### After (DTO Model Approach)
27+
```cpp
28+
// New approach - structured DTO model
29+
auto j = json::parse(body);
30+
AddEngineRequest request;
31+
request.from_json(j);
32+
33+
if (!request.validate()) {
34+
// Handle validation error
35+
return;
36+
}
37+
38+
// Access validated fields
39+
std::string engineId = request.engine_id;
40+
std::string modelPath = request.model_path;
41+
bool loadImmediately = request.load_immediately;
42+
43+
// Convert to LoadingParameters struct
44+
LoadingParameters loadParams;
45+
loadParams.n_ctx = request.loading_parameters.n_ctx;
46+
loadParams.n_keep = request.loading_parameters.n_keep;
47+
// ... etc
48+
```
49+
50+
## JSON Schema
51+
52+
The `AddEngineRequest` model expects JSON in the following format:
53+
54+
```json
55+
{
56+
"engine_id": "my-engine",
57+
"model_path": "/path/to/model.gguf",
58+
"load_immediately": true,
59+
"main_gpu_id": 0,
60+
"loading_parameters": {
61+
"n_ctx": 4096,
62+
"n_keep": 2048,
63+
"use_mlock": true,
64+
"use_mmap": true,
65+
"cont_batching": true,
66+
"warmup": false,
67+
"n_parallel": 1,
68+
"n_gpu_layers": 100,
69+
"n_batch": 2048,
70+
"n_ubatch": 512
71+
}
72+
}
73+
```
74+
75+
## Validation
76+
77+
The model includes comprehensive validation:
78+
79+
### Required Fields
80+
- `engine_id` (non-empty string)
81+
- `model_path` (non-empty string)
82+
83+
### Optional Fields with Defaults
84+
- `load_immediately` (boolean, default: true)
85+
- `main_gpu_id` (integer, default: 0, range: -1 to 15)
86+
- `loading_parameters` (object with nested validation)
87+
88+
### Loading Parameters Validation
89+
- `n_ctx`: 1 to 1,000,000
90+
- `n_keep`: 0 to n_ctx
91+
- `n_batch`: 1 to 8,192
92+
- `n_ubatch`: 1 to n_batch
93+
- `n_parallel`: 1 to 16
94+
- `n_gpu_layers`: 0 to 1,000
95+
96+
## Benefits
97+
98+
1. **Type Safety**: Compile-time checking of field types
99+
2. **Validation**: Built-in parameter validation with detailed error messages
100+
3. **Maintainability**: Centralized request structure definition
101+
4. **Consistency**: Follows the same pattern as `CompletionRequest` model
102+
5. **Error Handling**: Structured exception handling for validation errors
103+
6. **Documentation**: Self-documenting code with clear field definitions
104+
105+
## Files Created
106+
107+
- `include/kolosal/models/add_engine_request_model.hpp` - Request DTO model
108+
- `include/kolosal/models/add_engine_response_model.hpp` - Response DTO model (optional)
109+
110+
## Integration
111+
112+
The model is integrated into `add_engine_route.cpp` with:
113+
- JSON parsing and validation
114+
- Type-safe field access
115+
- Structured error handling
116+
- Response generation using the validated model data

0 commit comments

Comments
 (0)