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
use crate::{
    rpc::{ExecutionLocationProvider, LauncherConfig, LauncherSpec, ParameterDefinitions},
    DecthingsParameterProvider,
};
use serde::Serialize;

#[derive(Debug, Clone)]
pub struct StateKeyData<'a, D: AsRef<[u8]>> {
    pub key: &'a str,
    pub data: D,
}

impl<D: AsRef<[u8]>> serde::Serialize for StateKeyData<'_, D> {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.key)
    }
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", tag = "method")]
#[serde(bound(serialize = ""))]
pub enum CreateModelInitialState<'a, D: AsRef<[u8]>> {
    Copy,
    #[serde(rename_all = "camelCase")]
    Create {
        name: &'a str,
        params: Vec<DecthingsParameterProvider<'a>>,
        launcher_spec: &'a LauncherSpec,
    },
    #[serde(rename_all = "camelCase")]
    Upload {
        name: &'a str,
        #[serde(rename = "stateKeyNames")]
        data: &'a [StateKeyData<'a, D>],
    },
}

impl<'a> CreateModelInitialState<'a, &'static [u8]> {
    pub fn copy() -> Self {
        Self::Copy
    }
}
impl<'a> CreateModelInitialState<'a, &'static [u8]> {
    pub fn create(
        name: &'a str,
        params: Vec<DecthingsParameterProvider<'a>>,
        launcher_spec: &'a LauncherSpec,
    ) -> Self {
        Self::Create {
            name,
            params,
            launcher_spec,
        }
    }
}
impl<'a, D: AsRef<[u8]>> CreateModelInitialState<'a, D> {
    pub fn upload(name: &'a str, data: &'a [StateKeyData<'a, D>]) -> Self {
        Self::Upload { name, data }
    }
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", tag = "type")]
#[serde(bound(serialize = ""))]
pub enum CreateModelOptions<'a, D: AsRef<[u8]>> {
    #[serde(rename_all = "camelCase")]
    Code {
        /// Tags are used to specify things like model type (image classifier, etc.) and other metadata.
        tags: Option<&'a [super::super::TagProvider<'a>]>,
        #[serde(skip_serializing_if = "Option::is_none")]
        parameter_definitions: Option<ParameterDefinitions>,
        language: super::response::Language,
        /// At the time of writing, presets "none", "empty", "tensorflowjs", "pytorch" and "tensorflow" are available.
        #[serde(skip_serializing_if = "Option::is_none")]
        preset: Option<&'a str>,
        #[serde(skip_serializing_if = "Option::is_none")]
        wasm: Option<bool>,
    },
    #[serde(rename_all = "camelCase")]
    Upload {
        /// Tags are used to specify things like model type (image classifier, etc.) and other metadata.
        tags: Option<&'a [super::super::TagProvider<'a>]>,
        #[serde(skip_serializing_if = "Option::is_none")]
        parameter_definitions: Option<ParameterDefinitions>,
        /// At the time of writing, formats "tflite" and "onnx" are available.
        format: &'a str,
        #[serde(skip_serializing)]
        data: &'a [u8],
    },
    #[serde(rename_all = "camelCase")]
    BasedOnModelSnapshot {
        model_id: &'a str,
        snapshot_id: &'a str,
        initial_state: CreateModelInitialState<'a, D>,
    },
    #[serde(rename_all = "camelCase")]
    FromExisting {
        model_id: &'a str,
        #[serde(skip_serializing_if = "Option::is_none")]
        snapshot_id: Option<&'a str>,
    },
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
#[serde(bound(serialize = ""))]
pub struct CreateModelParams<'a, D: AsRef<[u8]>> {
    /// The model's name.
    pub name: &'a str,
    /// A description of the model.
    pub description: &'a str,
    /// Required configuration for this model, such as model type, language to use, etc.
    pub options: CreateModelOptions<'a, D>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WaitForModelToBeCreatedParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DeleteModelParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SnapshotModelParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// The name of the snapshot.
    pub snapshot_name: &'a str,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateSnapshotProperties<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<&'a str>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateSnapshotParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// The snapshot's id.
    pub snapshot_id: &'a str,
    /// Properties and values to change. Empty fields will not be changed.
    pub properties: UpdateSnapshotProperties<'a>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DeleteSnapshotParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// The snapshot's id.
    pub snapshot_id: &'a str,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OptionalDefaultLauncherSpecs<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub create_state: Option<&'a LauncherSpec>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub evaluate: Option<&'a LauncherSpec>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateModelProperties<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<&'a str>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<&'a str>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<&'a [super::super::TagProvider<'a>]>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub parameter_definitions: Option<ParameterDefinitions>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub default_launcher_specs: Option<OptionalDefaultLauncherSpecs<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_durations_seconds: Option<super::response::MaxDurationsSeconds>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub launcher_config: Option<&'a LauncherConfig>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateModelParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// Properties and values to change. Empty fields will not be changed.
    pub properties: UpdateModelProperties<'a>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetModelsParams<'a, S: AsRef<str>> {
    /// Which models to fetch. If unspecified, all models will be fetched.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(serialize_with = "super::super::serialize_option_asref_str_seq")]
    pub model_ids: Option<&'a [S]>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SetFilesystemSizeParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// The new size to use.
    pub new_filesystem_size_mebibytes: u32,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetFilesystemUsageParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateStateMountModel<'a> {
    /// Id of the other model to mount.
    pub model_id: &'a str,
    /// Specifies which state on the other model to use. Defaults to the active state.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub state_id: Option<&'a str>,
    /// If specified, this snapshot on the other model will be used. Cannot be used together with stateId, as the state
    /// in the snapshot will be used if snapshotId is specified.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub snapshot_id: Option<&'a str>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateStateParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// Name of the new state.
    pub name: &'a str,
    /// Parameters to provide to the createModelState function on the running model.
    pub params: Vec<DecthingsParameterProvider<'a>>,
    /// Allows your model to access to files and state of these additional models. Can be useful for merging models
    /// together.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mount_models: Option<&'a [CreateStateMountModel<'a>]>,
    /// Which launcher to use for running the operation.
    pub execution_location: ExecutionLocationProvider<'a>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct MountModel<'a> {
    /// Id of the other model to mount.
    pub model_id: &'a str,
    /// If specified, this snapshot on the other model will be used.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub snapshot_id: Option<&'a str>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UploadStateParams<'a, S: AsRef<str>, D: AsRef<[u8]>> {
    /// The model's id.
    pub model_id: &'a str,
    /// Name of the new state.
    pub name: &'a str,
    /// Data to upload.
    #[serde(skip_serializing)]
    pub data: &'a [StateKeyData<'a, D>],
    /// If provided, these states will be deleted when the new state has been uploaded, in a single atomic operation.
    /// If either the upload or the delete fails, both the upload and the delete operations are aborted and an error is
    /// returned.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(serialize_with = "super::super::serialize_option_asref_str_seq")]
    pub delete_states: Option<&'a [S]>,
    /// Allows your model to access to files and state of these additional models. Can be useful for merging models
    /// together.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mount_models: Option<&'a [MountModel<'a>]>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CancelCreateStateParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// The state's id.
    pub state_id: &'a str,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetCreatingStatesParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WaitForStateToBeCreatedParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// The state's id.
    pub state_id: &'a str,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateModelStateProperties<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<&'a str>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateModelStateParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// The state's id.
    pub state_id: &'a str,
    /// Properties and values to change. Empty fields will not be changed.
    pub properties: UpdateModelStateProperties<'a>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SetActiveModelStateParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// The state's id.
    pub state_id: &'a str,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DeleteModelStateParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// The state's id.
    pub state_id: &'a str,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetModelStateParams<'a, S: AsRef<str>> {
    /// The model's id.
    pub model_id: &'a str,
    /// The state's id. Defaults to the active state.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub state_id: Option<&'a str>,
    /// Which keys to fetch. Defaults to all keys.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(serialize_with = "super::super::serialize_option_asref_str_seq")]
    pub keys: Option<&'a [S]>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetSnapshotStateParams<'a, S: AsRef<str>> {
    /// The model's id.
    pub model_id: &'a str,
    /// The snapshot's id.
    pub snapshot_id: &'a str,
    /// Which keys to fetch. Defaults to all keys.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(serialize_with = "super::super::serialize_option_asref_str_seq")]
    pub keys: Option<&'a [S]>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TrainParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// Which state to use when instantiating the model. Defaults to the active state.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub state_id: Option<&'a str>,
    /// A name to give the new state once it is created.
    pub new_state_name: &'a str,
    /// Parameters to provide to the train function on the running model.
    pub params: Vec<DecthingsParameterProvider<'a>>,
    /// Which launcher to use for running the operation.
    pub execution_location: ExecutionLocationProvider<'a>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetTrainingStatusParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// The training session's id.
    pub training_session_id: &'a str,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TrainingMetricsToFetch<'a> {
    pub name: &'a str,
    pub start_index: u32,
    pub amount: u32,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetTrainingMetricsParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// The training session's id.
    pub training_session_id: &'a str,
    /// Which metrics to fetch
    pub metrics: &'a [TrainingMetricsToFetch<'a>],
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetTrainingSysinfoParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// The training session's id.
    pub training_session_id: &'a str,
    /// If specified, only data points after this time are included.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub from_timestamp: Option<i64>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CancelTrainingSessionParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// The training session's id.
    pub training_session_id: &'a str,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ClearPreviousTrainingSessionParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// The training session's id.
    pub training_session_id: &'a str,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct EvaluateParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// Parameters to provide to the train function on the running model.
    pub params: Vec<DecthingsParameterProvider<'a>>,
    /// If provided, the snapshot with this id will be evaluated.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub snapshot_id: Option<&'a str>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetEvaluationsParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetFinishedEvaluationResultParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// The evaluation's id.
    pub evaluation_id: &'a str,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CancelEvaluationParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// The evaluation's id.
    pub evaluation_id: &'a str,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PersistentLauncherToUse<'a> {
    pub persistent_launcher_id: &'a str,
    pub level: super::response::UsedPersistentLauncherLevel,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SetUsedPersistentLaunchersForEvaluateParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    pub persistent_launchers: &'a [PersistentLauncherToUse<'a>],
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetUsedPersistentLaunchersForEvaluateParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
}