decthings_api/client/rpc/model/
request.rs

1use crate::{
2    client::rpc::{ExecutionLocationProvider, LauncherSpec, ParameterDefinitions, TagProvider},
3    client::DecthingsParameterProvider,
4};
5use serde::Serialize;
6
7#[derive(Debug, Clone)]
8pub struct StateKeyData<'a, D: AsRef<[u8]>> {
9    pub key: &'a str,
10    pub data: D,
11}
12
13impl<D: AsRef<[u8]>> serde::Serialize for StateKeyData<'_, D> {
14    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
15    where
16        S: serde::Serializer,
17    {
18        serializer.serialize_str(self.key)
19    }
20}
21
22#[derive(Debug, Clone, Serialize)]
23#[serde(rename_all = "camelCase", tag = "method")]
24#[serde(bound(serialize = ""))]
25pub enum CreateModelInitialState<'a, D: AsRef<[u8]>> {
26    Copy,
27    #[serde(rename_all = "camelCase")]
28    Create {
29        name: &'a str,
30        params: Vec<DecthingsParameterProvider<'a>>,
31        launcher_spec: &'a LauncherSpec,
32    },
33    #[serde(rename_all = "camelCase")]
34    Upload {
35        name: &'a str,
36        #[serde(rename = "stateKeyNames")]
37        data: &'a [StateKeyData<'a, D>],
38    },
39}
40
41impl<'a> CreateModelInitialState<'a, &'static [u8]> {
42    pub fn copy() -> Self {
43        Self::Copy
44    }
45}
46impl<'a> CreateModelInitialState<'a, &'static [u8]> {
47    pub fn create(
48        name: &'a str,
49        params: Vec<DecthingsParameterProvider<'a>>,
50        launcher_spec: &'a LauncherSpec,
51    ) -> Self {
52        Self::Create {
53            name,
54            params,
55            launcher_spec,
56        }
57    }
58}
59impl<'a, D: AsRef<[u8]>> CreateModelInitialState<'a, D> {
60    pub fn upload(name: &'a str, data: &'a [StateKeyData<'a, D>]) -> Self {
61        Self::Upload { name, data }
62    }
63}
64
65#[derive(Debug, Clone, Serialize)]
66#[serde(rename_all = "camelCase", tag = "type")]
67#[serde(bound(serialize = ""))]
68pub enum CreateModelOptions<'a, D: AsRef<[u8]>> {
69    #[serde(rename_all = "camelCase")]
70    Code {
71        /// Tags are used to specify things like model type (image classifier, etc.) and other metadata.
72        #[serde(skip_serializing_if = "Option::is_none")]
73        tags: Option<&'a [TagProvider<'a>]>,
74        #[serde(skip_serializing_if = "Option::is_none")]
75        parameter_definitions: Option<ParameterDefinitions>,
76        language: super::response::Language,
77        /// At the time of writing, presets "none", "empty", "tensorflowjs", "pytorch" and "tensorflow" are available.
78        #[serde(skip_serializing_if = "Option::is_none")]
79        preset: Option<&'a str>,
80        #[serde(skip_serializing_if = "Option::is_none")]
81        wasm: Option<bool>,
82    },
83    #[serde(rename_all = "camelCase")]
84    Upload {
85        /// Tags are used to specify things like model type (image classifier, etc.) and other metadata.
86        #[serde(skip_serializing_if = "Option::is_none")]
87        tags: Option<&'a [TagProvider<'a>]>,
88        #[serde(skip_serializing_if = "Option::is_none")]
89        parameter_definitions: Option<ParameterDefinitions>,
90        /// At the time of writing, formats "tflite" and "onnx" are available.
91        format: &'a str,
92        #[serde(skip_serializing)]
93        data: D,
94    },
95    #[serde(rename_all = "camelCase")]
96    BasedOnModelSnapshot {
97        /// Tags are used to specify things like model type (image classifier, etc.) and other metadata.
98        #[serde(skip_serializing_if = "Option::is_none")]
99        tags: Option<&'a [TagProvider<'a>]>,
100        model_id: &'a str,
101        snapshot_id: &'a str,
102        initial_state: CreateModelInitialState<'a, D>,
103    },
104    #[serde(rename_all = "camelCase")]
105    FromExisting {
106        /// Tags are used to specify things like model type (image classifier, etc.) and other metadata.
107        #[serde(skip_serializing_if = "Option::is_none")]
108        tags: Option<&'a [TagProvider<'a>]>,
109        model_id: &'a str,
110        #[serde(skip_serializing_if = "Option::is_none")]
111        snapshot_id: Option<&'a str>,
112    },
113}
114
115#[derive(Debug, Clone, Serialize)]
116#[serde(rename_all = "camelCase")]
117#[serde(bound(serialize = ""))]
118pub struct CreateModelParams<'a, D: AsRef<[u8]>> {
119    /// The model's name.
120    pub name: &'a str,
121    /// A description of the model.
122    pub description: &'a str,
123    /// If true, all Decthings users can find and use this model. Defaults to false.
124    #[serde(skip_serializing_if = "Option::is_none")]
125    pub public_access: Option<bool>,
126    /// Required configuration for this model, such as model type, language to use, etc.
127    pub options: CreateModelOptions<'a, D>,
128}
129
130#[derive(Debug, Clone, Serialize)]
131#[serde(rename_all = "camelCase")]
132pub struct WaitForModelToBeCreatedParams<'a> {
133    /// The model's id.
134    pub model_id: &'a str,
135}
136
137#[derive(Debug, Clone, Serialize)]
138#[serde(rename_all = "camelCase")]
139pub struct DeleteModelParams<'a> {
140    /// The model's id.
141    pub model_id: &'a str,
142}
143
144#[derive(Debug, Clone, Serialize)]
145#[serde(rename_all = "camelCase")]
146pub struct SnapshotModelParams<'a> {
147    /// The model's id.
148    pub model_id: &'a str,
149    /// The name of the snapshot.
150    pub snapshot_name: &'a str,
151}
152
153#[derive(Debug, Clone, Serialize)]
154#[serde(rename_all = "camelCase")]
155pub struct UpdateSnapshotProperties<'a> {
156    #[serde(skip_serializing_if = "Option::is_none")]
157    pub name: Option<&'a str>,
158}
159
160#[derive(Debug, Clone, Serialize)]
161#[serde(rename_all = "camelCase")]
162pub struct UpdateSnapshotParams<'a> {
163    /// The model's id.
164    pub model_id: &'a str,
165    /// The snapshot's id.
166    pub snapshot_id: &'a str,
167    /// Properties and values to change. Empty fields will not be changed.
168    pub properties: UpdateSnapshotProperties<'a>,
169}
170
171#[derive(Debug, Clone, Serialize)]
172#[serde(rename_all = "camelCase")]
173pub struct DeleteSnapshotParams<'a> {
174    /// The model's id.
175    pub model_id: &'a str,
176    /// The snapshot's id.
177    pub snapshot_id: &'a str,
178}
179
180#[derive(Debug, Clone, Serialize)]
181#[serde(rename_all = "camelCase")]
182pub struct OptionalDefaultLauncherSpecs<'a> {
183    #[serde(skip_serializing_if = "Option::is_none")]
184    pub create_state: Option<&'a LauncherSpec>,
185    #[serde(skip_serializing_if = "Option::is_none")]
186    pub evaluate: Option<&'a LauncherSpec>,
187}
188
189#[derive(Debug, Clone, Serialize)]
190#[serde(rename_all = "camelCase")]
191pub struct UpdateModelProperties<'a> {
192    #[serde(skip_serializing_if = "Option::is_none")]
193    pub name: Option<&'a str>,
194    #[serde(skip_serializing_if = "Option::is_none")]
195    pub description: Option<&'a str>,
196    #[serde(skip_serializing_if = "Option::is_none")]
197    pub public_access: Option<bool>,
198    #[serde(skip_serializing_if = "Option::is_none")]
199    pub tags: Option<&'a [TagProvider<'a>]>,
200    #[serde(skip_serializing_if = "Option::is_none")]
201    pub parameter_definitions: Option<ParameterDefinitions>,
202    #[serde(skip_serializing_if = "Option::is_none")]
203    pub default_launcher_specs: Option<OptionalDefaultLauncherSpecs<'a>>,
204    #[serde(skip_serializing_if = "Option::is_none")]
205    pub max_durations_seconds: Option<super::response::MaxDurationsSeconds>,
206}
207
208#[derive(Debug, Clone, Serialize)]
209#[serde(rename_all = "camelCase")]
210pub struct UpdateModelParams<'a> {
211    /// The model's id.
212    pub model_id: &'a str,
213    /// Properties and values to change. Empty fields will not be changed.
214    pub properties: UpdateModelProperties<'a>,
215}
216
217#[derive(Debug, Clone, Serialize)]
218#[serde(rename_all = "camelCase")]
219pub struct GetModelsFilter<'a, S: AsRef<str>> {
220    #[serde(serialize_with = "super::super::serialize_option_asref_str_seq")]
221    #[serde(skip_serializing_if = "Option::is_none")]
222    pub owners: Option<&'a [S]>,
223    #[serde(skip_serializing_if = "Option::is_none")]
224    pub tags: Option<&'a [TagProvider<'a>]>,
225    #[serde(serialize_with = "super::super::serialize_option_asref_str_seq")]
226    #[serde(skip_serializing_if = "Option::is_none")]
227    pub ids: Option<&'a [S]>,
228    #[serde(serialize_with = "super::super::serialize_option_asref_str_seq")]
229    #[serde(skip_serializing_if = "Option::is_none")]
230    pub names: Option<&'a [S]>,
231    #[serde(skip_serializing_if = "Option::is_none")]
232    pub search_name: Option<&'a str>,
233}
234
235#[derive(Debug, Clone, Serialize)]
236#[serde(rename_all = "camelCase")]
237pub enum SortDirection {
238    Asc,
239    Desc,
240}
241
242#[derive(Debug, Clone, Serialize)]
243#[serde(rename_all = "camelCase")]
244#[serde(bound = "")]
245pub struct GetModelsParams<'a, S: AsRef<str>> {
246    /// Number of items from the results to skip. Defaults to 0.
247    #[serde(skip_serializing_if = "Option::is_none")]
248    pub offset: Option<u32>,
249    /// Max number of items to return. Defaults to 20.
250    #[serde(skip_serializing_if = "Option::is_none")]
251    pub limit: Option<u32>,
252    /// If specified, determines which items to retrieve.
253    #[serde(skip_serializing_if = "Option::is_none")]
254    pub filter: Option<GetModelsFilter<'a, S>>,
255    /// Specifies a field in the returned items to sort by. Defaults to "createdAt".
256    #[serde(skip_serializing_if = "Option::is_none")]
257    pub sort: Option<&'a str>,
258    #[serde(skip_serializing_if = "Option::is_none")]
259    pub sort_direction: Option<SortDirection>,
260}
261
262#[derive(Debug, Clone, Serialize)]
263#[serde(rename_all = "camelCase")]
264pub struct SetFilesystemSizeParams<'a> {
265    /// The model's id.
266    pub model_id: &'a str,
267    /// The new size to use.
268    pub new_filesystem_size_mebibytes: u32,
269}
270
271#[derive(Debug, Clone, Serialize)]
272#[serde(rename_all = "camelCase")]
273pub struct GetFilesystemUsageParams<'a> {
274    /// The model's id.
275    pub model_id: &'a str,
276}
277
278#[derive(Debug, Clone, Serialize)]
279#[serde(rename_all = "camelCase")]
280pub struct SetImageParams<'a> {
281    /// The model's id.
282    pub model_id: &'a str,
283    /// The domain name to load from, i.e "docker.io" or "registry.decthings.com"
284    pub domain: &'a str,
285    /// The repository to use, i.e "library/ubuntu"
286    pub repository: &'a str,
287    /// The tag to use, to, i.e "latest"
288    pub reference: &'a str,
289}
290
291#[derive(Debug, Clone, Serialize)]
292#[serde(rename_all = "camelCase")]
293pub struct CreateStateMountModel<'a> {
294    /// Id of the other model to mount.
295    pub model_id: &'a str,
296    /// Specifies which state on the other model to use. Defaults to the active state.
297    #[serde(skip_serializing_if = "Option::is_none")]
298    pub state_id: Option<&'a str>,
299    /// If specified, this snapshot on the other model will be used. Cannot be used together with stateId, as the state
300    /// in the snapshot will be used if snapshotId is specified.
301    #[serde(skip_serializing_if = "Option::is_none")]
302    pub snapshot_id: Option<&'a str>,
303}
304
305#[derive(Debug, Clone, Serialize)]
306#[serde(rename_all = "camelCase")]
307pub struct CreateStateParams<'a> {
308    /// The model's id.
309    pub model_id: &'a str,
310    /// Name of the new state.
311    pub name: &'a str,
312    /// Parameters to provide to the createModelState function on the running model.
313    pub params: Vec<DecthingsParameterProvider<'a>>,
314    /// Allows your model to access to files and state of these additional models. Can be useful for merging models
315    /// together.
316    #[serde(skip_serializing_if = "Option::is_none")]
317    pub mount_models: Option<&'a [CreateStateMountModel<'a>]>,
318    /// Which launcher to use for running the operation.
319    pub execution_location: ExecutionLocationProvider<'a>,
320}
321
322#[derive(Debug, Clone, Serialize)]
323#[serde(rename_all = "camelCase")]
324pub struct MountModel<'a> {
325    /// Id of the other model to mount.
326    pub model_id: &'a str,
327    /// If specified, this snapshot on the other model will be used.
328    #[serde(skip_serializing_if = "Option::is_none")]
329    pub snapshot_id: Option<&'a str>,
330}
331
332#[derive(Debug, Clone, Serialize)]
333#[serde(rename_all = "camelCase")]
334pub struct UploadStateParams<'a, S: AsRef<str>, D: AsRef<[u8]>> {
335    /// The model's id.
336    pub model_id: &'a str,
337    /// Name of the new state.
338    pub name: &'a str,
339    /// Data to upload.
340    #[serde(skip_serializing)]
341    pub data: &'a [StateKeyData<'a, D>],
342    /// If provided, these states will be deleted when the new state has been uploaded, in a single atomic operation.
343    /// If either the upload or the delete fails, both the upload and the delete operations are aborted and an error is
344    /// returned.
345    #[serde(serialize_with = "super::super::serialize_option_asref_str_seq")]
346    #[serde(skip_serializing_if = "Option::is_none")]
347    pub delete_states: Option<&'a [S]>,
348    /// Allows your model to access to files of these additional models. Can be useful for merging models together.
349    #[serde(skip_serializing_if = "Option::is_none")]
350    pub mount_models: Option<&'a [MountModel<'a>]>,
351}
352
353#[derive(Debug, Clone, Serialize)]
354#[serde(rename_all = "camelCase")]
355pub struct CancelCreateStateParams<'a> {
356    /// The model's id.
357    pub model_id: &'a str,
358    /// The state's id.
359    pub state_id: &'a str,
360}
361
362#[derive(Debug, Clone, Serialize)]
363#[serde(rename_all = "camelCase")]
364pub struct GetCreatingStatesParams<'a> {
365    /// The model's id.
366    pub model_id: &'a str,
367}
368
369#[derive(Debug, Clone, Serialize)]
370#[serde(rename_all = "camelCase")]
371pub struct WaitForStateToBeCreatedParams<'a> {
372    /// The model's id.
373    pub model_id: &'a str,
374    /// The state's id.
375    pub state_id: &'a str,
376}
377
378#[derive(Debug, Clone, Serialize)]
379#[serde(rename_all = "camelCase")]
380pub struct UpdateModelStateProperties<'a> {
381    #[serde(skip_serializing_if = "Option::is_none")]
382    pub name: Option<&'a str>,
383}
384
385#[derive(Debug, Clone, Serialize)]
386#[serde(rename_all = "camelCase")]
387pub struct UpdateModelStateParams<'a> {
388    /// The model's id.
389    pub model_id: &'a str,
390    /// The state's id.
391    pub state_id: &'a str,
392    /// Properties and values to change. Empty fields will not be changed.
393    pub properties: UpdateModelStateProperties<'a>,
394}
395
396#[derive(Debug, Clone, Serialize)]
397#[serde(rename_all = "camelCase")]
398pub struct SetActiveModelStateParams<'a> {
399    /// The model's id.
400    pub model_id: &'a str,
401    /// The state's id.
402    pub state_id: &'a str,
403}
404
405#[derive(Debug, Clone, Serialize)]
406#[serde(rename_all = "camelCase")]
407pub struct DeleteModelStateParams<'a> {
408    /// The model's id.
409    pub model_id: &'a str,
410    /// The state's id.
411    pub state_id: &'a str,
412}
413
414#[derive(Debug, Clone, Serialize)]
415#[serde(rename_all = "camelCase")]
416pub struct GetModelStateParams<'a, S: AsRef<str>> {
417    /// The model's id.
418    pub model_id: &'a str,
419    /// The state's id. Defaults to the active state.
420    #[serde(skip_serializing_if = "Option::is_none")]
421    pub state_id: Option<&'a str>,
422    /// Which keys to fetch. Defaults to all keys.
423    #[serde(serialize_with = "super::super::serialize_option_asref_str_seq")]
424    #[serde(skip_serializing_if = "Option::is_none")]
425    pub keys: Option<&'a [S]>,
426}
427
428#[derive(Debug, Clone, Serialize)]
429#[serde(rename_all = "camelCase")]
430pub struct GetSnapshotStateParams<'a, S: AsRef<str>> {
431    /// The model's id.
432    pub model_id: &'a str,
433    /// The snapshot's id.
434    pub snapshot_id: &'a str,
435    /// Which keys to fetch. Defaults to all keys.
436    #[serde(serialize_with = "super::super::serialize_option_asref_str_seq")]
437    #[serde(skip_serializing_if = "Option::is_none")]
438    pub keys: Option<&'a [S]>,
439}
440
441#[derive(Debug, Clone, Serialize)]
442#[serde(rename_all = "camelCase")]
443pub struct TrainParams<'a> {
444    /// The model's id.
445    pub model_id: &'a str,
446    /// Which state to use when instantiating the model. Defaults to the active state.
447    #[serde(skip_serializing_if = "Option::is_none")]
448    pub state_id: Option<&'a str>,
449    /// A name to give the new state once it is created.
450    pub new_state_name: &'a str,
451    /// Parameters to provide to the train function on the running model.
452    pub params: Vec<DecthingsParameterProvider<'a>>,
453    /// Which launcher to use for running the operation.
454    pub execution_location: ExecutionLocationProvider<'a>,
455}
456
457#[derive(Debug, Clone, Serialize)]
458#[serde(rename_all = "camelCase")]
459pub struct GetTrainingStatusParams<'a> {
460    /// The model's id.
461    pub model_id: &'a str,
462    /// The training session's id.
463    pub training_session_id: &'a str,
464}
465
466#[derive(Debug, Clone, Serialize)]
467#[serde(rename_all = "camelCase")]
468pub struct TrainingMetricsToFetch<'a> {
469    pub name: &'a str,
470    pub start_index: u32,
471    pub amount: u32,
472}
473
474#[derive(Debug, Clone, Serialize)]
475#[serde(rename_all = "camelCase")]
476pub struct GetTrainingMetricsParams<'a> {
477    /// The model's id.
478    pub model_id: &'a str,
479    /// The training session's id.
480    pub training_session_id: &'a str,
481    /// Which metrics to fetch
482    pub metrics: &'a [TrainingMetricsToFetch<'a>],
483}
484
485#[derive(Debug, Clone, Serialize)]
486#[serde(rename_all = "camelCase")]
487pub struct GetTrainingSysinfoParams<'a> {
488    /// The model's id.
489    pub model_id: &'a str,
490    /// The training session's id.
491    pub training_session_id: &'a str,
492    /// If specified, only data points after this time are included.
493    #[serde(skip_serializing_if = "Option::is_none")]
494    pub from_timestamp: Option<i64>,
495}
496
497#[derive(Debug, Clone, Serialize)]
498#[serde(rename_all = "camelCase")]
499pub struct CancelTrainingSessionParams<'a> {
500    /// The model's id.
501    pub model_id: &'a str,
502    /// The training session's id.
503    pub training_session_id: &'a str,
504}
505
506#[derive(Debug, Clone, Serialize)]
507#[serde(rename_all = "camelCase")]
508pub struct ClearPreviousTrainingSessionParams<'a> {
509    /// The model's id.
510    pub model_id: &'a str,
511    /// The training session's id.
512    pub training_session_id: &'a str,
513}
514
515#[derive(Debug, Clone, Serialize)]
516#[serde(rename_all = "camelCase")]
517pub struct EvaluateParams<'a> {
518    /// The model's id.
519    pub model_id: &'a str,
520    /// Parameters to provide to the train function on the running model.
521    pub params: Vec<DecthingsParameterProvider<'a>>,
522    /// If provided, the snapshot with this id will be evaluated.
523    #[serde(skip_serializing_if = "Option::is_none")]
524    pub snapshot_id: Option<&'a str>,
525}
526
527#[derive(Debug, Clone, Serialize)]
528#[serde(rename_all = "camelCase")]
529pub struct GetEvaluationsParams<'a> {
530    /// The model's id.
531    pub model_id: &'a str,
532}
533
534#[derive(Debug, Clone, Serialize)]
535#[serde(rename_all = "camelCase")]
536pub struct GetFinishedEvaluationResultParams<'a> {
537    /// The model's id.
538    pub model_id: &'a str,
539    /// The evaluation's id.
540    pub evaluation_id: &'a str,
541}
542
543#[derive(Debug, Clone, Serialize)]
544#[serde(rename_all = "camelCase")]
545pub struct CancelEvaluationParams<'a> {
546    /// The model's id.
547    pub model_id: &'a str,
548    /// The evaluation's id.
549    pub evaluation_id: &'a str,
550}
551
552#[derive(Debug, Clone, Serialize)]
553#[serde(rename_all = "camelCase")]
554pub struct PersistentLauncherToUse<'a> {
555    pub persistent_launcher_id: &'a str,
556    pub level: super::response::UsedPersistentLauncherLevel,
557}
558
559#[derive(Debug, Clone, Serialize)]
560#[serde(rename_all = "camelCase")]
561pub struct SetUsedPersistentLaunchersForEvaluateParams<'a> {
562    /// The model's id.
563    pub model_id: &'a str,
564    pub persistent_launchers: &'a [PersistentLauncherToUse<'a>],
565}
566
567#[derive(Debug, Clone, Serialize)]
568#[serde(rename_all = "camelCase")]
569pub struct GetUsedPersistentLaunchersForEvaluateParams<'a> {
570    /// The model's id.
571    pub model_id: &'a str,
572}