1mod request;
2mod response;
3
4use crate::{client::StateModification, tensor::OwnedDecthingsTensor};
5
6pub use request::*;
7pub use response::*;
8
9pub struct ModelRpc {
10 rpc: crate::client::DecthingsClientRpc,
11}
12
13impl ModelRpc {
14 pub(crate) fn new(rpc: crate::client::DecthingsClientRpc) -> Self {
15 Self { rpc }
16 }
17
18 pub async fn create_model(
19 &self,
20 params: CreateModelParams<'_, impl AsRef<[u8]>>,
21 ) -> Result<CreateModelResult, crate::client::DecthingsRpcError<CreateModelError>> {
22 let (tx, rx) = tokio::sync::oneshot::channel();
23 match ¶ms.options {
24 CreateModelOptions::BasedOnModelSnapshot {
25 tags: _,
26 model_id: _,
27 snapshot_id: _,
28 initial_state: CreateModelInitialState::Copy,
29 }
30 | CreateModelOptions::Code { .. }
31 | CreateModelOptions::FromExisting { .. } => {
32 self.rpc
33 .raw_method_call::<_, _, &[u8]>(
34 "Model",
35 "createModel",
36 params,
37 &[],
38 crate::client::RpcProtocol::Http,
39 |x| {
40 tx.send(x).ok();
41 StateModification::empty()
42 },
43 )
44 .await;
45 }
46 CreateModelOptions::Upload {
47 tags: _,
48 parameter_definitions: _,
49 format: _,
50 data,
51 } => {
52 self.rpc
53 .raw_method_call::<_, _, &[u8]>(
54 "Model",
55 "createModel",
56 ¶ms,
57 &[data.as_ref()],
58 crate::client::RpcProtocol::Http,
59 |x| {
60 tx.send(x).ok();
61 StateModification::empty()
62 },
63 )
64 .await;
65 }
66 CreateModelOptions::BasedOnModelSnapshot {
67 tags: _,
68 model_id: _,
69 snapshot_id: _,
70 initial_state: CreateModelInitialState::Upload { name: _, data },
71 } => {
72 self.rpc
73 .raw_method_call(
74 "Model",
75 "createModel",
76 ¶ms,
77 data.iter().map(|x| &x.data).collect::<Vec<_>>(),
78 crate::client::RpcProtocol::Http,
79 |x| {
80 tx.send(x).ok();
81 StateModification::empty()
82 },
83 )
84 .await;
85 }
86 CreateModelOptions::BasedOnModelSnapshot {
87 tags: _,
88 model_id: _,
89 snapshot_id: _,
90 initial_state:
91 CreateModelInitialState::Create {
92 name: _,
93 params,
94 launcher_spec: _,
95 },
96 } => {
97 let serialized = crate::client::serialize_parameter_provider_list(params.iter());
98 self.rpc
99 .raw_method_call(
100 "Model",
101 "createModel",
102 params,
103 serialized,
104 crate::client::RpcProtocol::Http,
105 |x| {
106 tx.send(x).ok();
107 StateModification::empty()
108 },
109 )
110 .await;
111 }
112 };
113 rx.await
114 .unwrap()
115 .map_err(crate::client::DecthingsRpcError::Request)
116 .and_then(|x| {
117 let res: super::Response<CreateModelResult, CreateModelError> =
118 serde_json::from_slice(&x.0)?;
119 match res {
120 super::Response::Result(val) => Ok(val),
121 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
122 }
123 })
124 }
125
126 pub async fn wait_for_model_to_be_created(
127 &self,
128 params: WaitForModelToBeCreatedParams<'_>,
129 ) -> Result<
130 WaitForModelToBeCreatedResult,
131 crate::client::DecthingsRpcError<WaitForModelToBeCreatedError>,
132 > {
133 let (tx, rx) = tokio::sync::oneshot::channel();
134 self.rpc
135 .raw_method_call::<_, _, &[u8]>(
136 "Model",
137 "waitForModelToBeCrated",
138 params,
139 &[],
140 crate::client::RpcProtocol::Http,
141 |x| {
142 tx.send(x).ok();
143 StateModification::empty()
144 },
145 )
146 .await;
147 rx.await
148 .unwrap()
149 .map_err(crate::client::DecthingsRpcError::Request)
150 .and_then(|x| {
151 let res: super::Response<
152 WaitForModelToBeCreatedResult,
153 WaitForModelToBeCreatedError,
154 > = serde_json::from_slice(&x.0)?;
155 match res {
156 super::Response::Result(val) => Ok(val),
157 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
158 }
159 })
160 }
161
162 pub async fn delete_model(
163 &self,
164 params: DeleteModelParams<'_>,
165 ) -> Result<DeleteModelResult, crate::client::DecthingsRpcError<DeleteModelError>> {
166 let (tx, rx) = tokio::sync::oneshot::channel();
167 self.rpc
168 .raw_method_call::<_, _, &[u8]>(
169 "Model",
170 "deleteModel",
171 params,
172 &[],
173 crate::client::RpcProtocol::Http,
174 |x| {
175 tx.send(x).ok();
176 StateModification::empty()
177 },
178 )
179 .await;
180 rx.await
181 .unwrap()
182 .map_err(crate::client::DecthingsRpcError::Request)
183 .and_then(|x| {
184 let res: super::Response<DeleteModelResult, DeleteModelError> =
185 serde_json::from_slice(&x.0)?;
186 match res {
187 super::Response::Result(val) => Ok(val),
188 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
189 }
190 })
191 }
192
193 pub async fn snapshot_model(
194 &self,
195 params: SnapshotModelParams<'_>,
196 ) -> Result<SnapshotModelResult, crate::client::DecthingsRpcError<SnapshotModelError>> {
197 let (tx, rx) = tokio::sync::oneshot::channel();
198 self.rpc
199 .raw_method_call::<_, _, &[u8]>(
200 "Model",
201 "snapshotModel",
202 params,
203 &[],
204 crate::client::RpcProtocol::Http,
205 |x| {
206 tx.send(x).ok();
207 StateModification::empty()
208 },
209 )
210 .await;
211 rx.await
212 .unwrap()
213 .map_err(crate::client::DecthingsRpcError::Request)
214 .and_then(|x| {
215 let res: super::Response<SnapshotModelResult, SnapshotModelError> =
216 serde_json::from_slice(&x.0)?;
217 match res {
218 super::Response::Result(val) => Ok(val),
219 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
220 }
221 })
222 }
223
224 pub async fn update_snapshot(
225 &self,
226 params: UpdateSnapshotParams<'_>,
227 ) -> Result<UpdateSnapshotResult, crate::client::DecthingsRpcError<UpdateSnapshotError>> {
228 let (tx, rx) = tokio::sync::oneshot::channel();
229 self.rpc
230 .raw_method_call::<_, _, &[u8]>(
231 "Model",
232 "updateSnapshot",
233 params,
234 &[],
235 crate::client::RpcProtocol::Http,
236 |x| {
237 tx.send(x).ok();
238 StateModification::empty()
239 },
240 )
241 .await;
242 rx.await
243 .unwrap()
244 .map_err(crate::client::DecthingsRpcError::Request)
245 .and_then(|x| {
246 let res: super::Response<UpdateSnapshotResult, UpdateSnapshotError> =
247 serde_json::from_slice(&x.0)?;
248 match res {
249 super::Response::Result(val) => Ok(val),
250 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
251 }
252 })
253 }
254
255 pub async fn delete_snapshot(
256 &self,
257 params: DeleteSnapshotParams<'_>,
258 ) -> Result<DeleteSnapshotResult, crate::client::DecthingsRpcError<DeleteSnapshotError>> {
259 let (tx, rx) = tokio::sync::oneshot::channel();
260 self.rpc
261 .raw_method_call::<_, _, &[u8]>(
262 "Model",
263 "deleteSnapshot",
264 params,
265 &[],
266 crate::client::RpcProtocol::Http,
267 |x| {
268 tx.send(x).ok();
269 StateModification::empty()
270 },
271 )
272 .await;
273 rx.await
274 .unwrap()
275 .map_err(crate::client::DecthingsRpcError::Request)
276 .and_then(|x| {
277 let res: super::Response<DeleteSnapshotResult, DeleteSnapshotError> =
278 serde_json::from_slice(&x.0)?;
279 match res {
280 super::Response::Result(val) => Ok(val),
281 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
282 }
283 })
284 }
285
286 pub async fn update_model(
287 &self,
288 params: UpdateModelParams<'_>,
289 ) -> Result<UpdateModelResult, crate::client::DecthingsRpcError<UpdateModelError>> {
290 let (tx, rx) = tokio::sync::oneshot::channel();
291 self.rpc
292 .raw_method_call::<_, _, &[u8]>(
293 "Model",
294 "updateModel",
295 params,
296 &[],
297 crate::client::RpcProtocol::Http,
298 |x| {
299 tx.send(x).ok();
300 StateModification::empty()
301 },
302 )
303 .await;
304 rx.await
305 .unwrap()
306 .map_err(crate::client::DecthingsRpcError::Request)
307 .and_then(|x| {
308 let res: super::Response<UpdateModelResult, UpdateModelError> =
309 serde_json::from_slice(&x.0)?;
310 match res {
311 super::Response::Result(val) => Ok(val),
312 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
313 }
314 })
315 }
316 pub async fn get_models(
317 &self,
318 params: GetModelsParams<'_, impl AsRef<str>>,
319 ) -> Result<GetModelsResult, crate::client::DecthingsRpcError<GetModelsError>> {
320 let (tx, rx) = tokio::sync::oneshot::channel();
321 self.rpc
322 .raw_method_call::<_, _, &[u8]>(
323 "Model",
324 "getModels",
325 params,
326 &[],
327 crate::client::RpcProtocol::Http,
328 |x| {
329 tx.send(x).ok();
330 StateModification::empty()
331 },
332 )
333 .await;
334 rx.await
335 .unwrap()
336 .map_err(crate::client::DecthingsRpcError::Request)
337 .and_then(|x| {
338 let res: super::Response<GetModelsResult, GetModelsError> =
339 serde_json::from_slice(&x.0)?;
340 match res {
341 super::Response::Result(val) => Ok(val),
342 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
343 }
344 })
345 }
346 pub async fn set_filesystem_size(
347 &self,
348 params: SetFilesystemSizeParams<'_>,
349 ) -> Result<SetFilesystemSizeResult, crate::client::DecthingsRpcError<SetFilesystemSizeError>>
350 {
351 let (tx, rx) = tokio::sync::oneshot::channel();
352 self.rpc
353 .raw_method_call::<_, _, &[u8]>(
354 "Model",
355 "setFilesystemSize",
356 params,
357 &[],
358 crate::client::RpcProtocol::Http,
359 |x| {
360 tx.send(x).ok();
361 StateModification::empty()
362 },
363 )
364 .await;
365 rx.await
366 .unwrap()
367 .map_err(crate::client::DecthingsRpcError::Request)
368 .and_then(|x| {
369 let res: super::Response<SetFilesystemSizeResult, SetFilesystemSizeError> =
370 serde_json::from_slice(&x.0)?;
371 match res {
372 super::Response::Result(val) => Ok(val),
373 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
374 }
375 })
376 }
377 pub async fn get_filesystem_usage(
378 &self,
379 params: GetFilesystemUsageParams<'_>,
380 ) -> Result<GetFilesystemUsageResult, crate::client::DecthingsRpcError<GetFilesystemUsageError>>
381 {
382 let (tx, rx) = tokio::sync::oneshot::channel();
383 self.rpc
384 .raw_method_call::<_, _, &[u8]>(
385 "Model",
386 "getFilesystemUsage",
387 params,
388 &[],
389 crate::client::RpcProtocol::Http,
390 |x| {
391 tx.send(x).ok();
392 StateModification::empty()
393 },
394 )
395 .await;
396 rx.await
397 .unwrap()
398 .map_err(crate::client::DecthingsRpcError::Request)
399 .and_then(|x| {
400 let res: super::Response<GetFilesystemUsageResult, GetFilesystemUsageError> =
401 serde_json::from_slice(&x.0)?;
402 match res {
403 super::Response::Result(val) => Ok(val),
404 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
405 }
406 })
407 }
408 pub async fn create_state(
409 &self,
410 params: CreateStateParams<'_>,
411 ) -> Result<CreateStateResult, crate::client::DecthingsRpcError<CreateStateError>> {
412 let (tx, rx) = tokio::sync::oneshot::channel();
413 let serialized = crate::client::serialize_parameter_provider_list(params.params.iter());
414 self.rpc
415 .raw_method_call(
416 "Model",
417 "createState",
418 params,
419 serialized,
420 crate::client::RpcProtocol::Http,
421 |x| {
422 tx.send(x).ok();
423 StateModification::empty()
424 },
425 )
426 .await;
427 rx.await
428 .unwrap()
429 .map_err(crate::client::DecthingsRpcError::Request)
430 .and_then(|x| {
431 let res: super::Response<CreateStateResult, CreateStateError> =
432 serde_json::from_slice(&x.0)?;
433 match res {
434 super::Response::Result(val) => Ok(val),
435 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
436 }
437 })
438 }
439
440 pub async fn upload_state(
441 &self,
442 params: UploadStateParams<'_, impl AsRef<str>, impl AsRef<[u8]>>,
443 ) -> Result<UploadStateResult, crate::client::DecthingsRpcError<UploadStateError>> {
444 let (tx, rx) = tokio::sync::oneshot::channel();
445 let data = params.data.iter().map(|x| &x.data).collect::<Vec<_>>();
446 self.rpc
447 .raw_method_call(
448 "Model",
449 "uploadState",
450 params,
451 data,
452 crate::client::RpcProtocol::Http,
453 |x| {
454 tx.send(x).ok();
455 StateModification::empty()
456 },
457 )
458 .await;
459 rx.await
460 .unwrap()
461 .map_err(crate::client::DecthingsRpcError::Request)
462 .and_then(|x| {
463 let res: super::Response<UploadStateResult, UploadStateError> =
464 serde_json::from_slice(&x.0)?;
465 match res {
466 super::Response::Result(val) => Ok(val),
467 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
468 }
469 })
470 }
471
472 pub async fn cancel_create_state(
473 &self,
474 params: CancelCreateStateParams<'_>,
475 ) -> Result<CancelCreateStateResult, crate::client::DecthingsRpcError<CancelCreateStateError>>
476 {
477 let (tx, rx) = tokio::sync::oneshot::channel();
478 self.rpc
479 .raw_method_call::<_, _, &[u8]>(
480 "Model",
481 "cancelCreateState",
482 params,
483 &[],
484 crate::client::RpcProtocol::Http,
485 |x| {
486 tx.send(x).ok();
487 StateModification::empty()
488 },
489 )
490 .await;
491 rx.await
492 .unwrap()
493 .map_err(crate::client::DecthingsRpcError::Request)
494 .and_then(|x| {
495 let res: super::Response<CancelCreateStateResult, CancelCreateStateError> =
496 serde_json::from_slice(&x.0)?;
497 match res {
498 super::Response::Result(val) => Ok(val),
499 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
500 }
501 })
502 }
503
504 pub async fn get_creating_states(
505 &self,
506 params: GetCreatingStatesParams<'_>,
507 ) -> Result<GetCreatingStatesResult, crate::client::DecthingsRpcError<GetCreatingStatesError>>
508 {
509 let (tx, rx) = tokio::sync::oneshot::channel();
510 self.rpc
511 .raw_method_call::<_, _, &[u8]>(
512 "Model",
513 "getCreatingStates",
514 params,
515 &[],
516 crate::client::RpcProtocol::Http,
517 |x| {
518 tx.send(x).ok();
519 StateModification::empty()
520 },
521 )
522 .await;
523 rx.await
524 .unwrap()
525 .map_err(crate::client::DecthingsRpcError::Request)
526 .and_then(|x| {
527 let res: super::Response<GetCreatingStatesResult, GetCreatingStatesError> =
528 serde_json::from_slice(&x.0)?;
529 match res {
530 super::Response::Result(val) => Ok(val),
531 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
532 }
533 })
534 }
535
536 pub async fn wait_for_state_to_be_created(
537 &self,
538 params: WaitForStateToBeCreatedParams<'_>,
539 ) -> Result<
540 WaitForStateToBeCreatedResult,
541 crate::client::DecthingsRpcError<WaitForStateToBeCreatedError>,
542 > {
543 let (tx, rx) = tokio::sync::oneshot::channel();
544 self.rpc
545 .raw_method_call::<_, _, &[u8]>(
546 "Model",
547 "waitForStateToBeCreated",
548 params,
549 &[],
550 crate::client::RpcProtocol::Http,
551 |x| {
552 tx.send(x).ok();
553 StateModification::empty()
554 },
555 )
556 .await;
557 rx.await
558 .unwrap()
559 .map_err(crate::client::DecthingsRpcError::Request)
560 .and_then(|x| {
561 let res: super::Response<
562 WaitForStateToBeCreatedResult,
563 WaitForStateToBeCreatedError,
564 > = serde_json::from_slice(&x.0)?;
565 match res {
566 super::Response::Result(val) => Ok(val),
567 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
568 }
569 })
570 }
571
572 pub async fn update_model_state(
573 &self,
574 params: UpdateModelStateParams<'_>,
575 ) -> Result<UpdateModelStateResult, crate::client::DecthingsRpcError<UpdateModelStateError>>
576 {
577 let (tx, rx) = tokio::sync::oneshot::channel();
578 self.rpc
579 .raw_method_call::<_, _, &[u8]>(
580 "Model",
581 "updateModelState",
582 params,
583 &[],
584 crate::client::RpcProtocol::Http,
585 |x| {
586 tx.send(x).ok();
587 StateModification::empty()
588 },
589 )
590 .await;
591 rx.await
592 .unwrap()
593 .map_err(crate::client::DecthingsRpcError::Request)
594 .and_then(|x| {
595 let res: super::Response<UpdateModelStateResult, UpdateModelStateError> =
596 serde_json::from_slice(&x.0)?;
597 match res {
598 super::Response::Result(val) => Ok(val),
599 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
600 }
601 })
602 }
603
604 pub async fn set_active_model_state(
605 &self,
606 params: SetActiveModelStateParams<'_>,
607 ) -> Result<SetActiveModelStateResult, crate::client::DecthingsRpcError<SetActiveModelStateError>>
608 {
609 let (tx, rx) = tokio::sync::oneshot::channel();
610 self.rpc
611 .raw_method_call::<_, _, &[u8]>(
612 "Model",
613 "setActiveModelState",
614 params,
615 &[],
616 crate::client::RpcProtocol::Http,
617 |x| {
618 tx.send(x).ok();
619 StateModification::empty()
620 },
621 )
622 .await;
623 rx.await
624 .unwrap()
625 .map_err(crate::client::DecthingsRpcError::Request)
626 .and_then(|x| {
627 let res: super::Response<SetActiveModelStateResult, SetActiveModelStateError> =
628 serde_json::from_slice(&x.0)?;
629 match res {
630 super::Response::Result(val) => Ok(val),
631 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
632 }
633 })
634 }
635
636 pub async fn delete_model_state(
637 &self,
638 params: DeleteModelStateParams<'_>,
639 ) -> Result<DeleteModelStateResult, crate::client::DecthingsRpcError<DeleteModelStateError>>
640 {
641 let (tx, rx) = tokio::sync::oneshot::channel();
642 self.rpc
643 .raw_method_call::<_, _, &[u8]>(
644 "Model",
645 "deleteModelState",
646 params,
647 &[],
648 crate::client::RpcProtocol::Http,
649 |x| {
650 tx.send(x).ok();
651 StateModification::empty()
652 },
653 )
654 .await;
655 rx.await
656 .unwrap()
657 .map_err(crate::client::DecthingsRpcError::Request)
658 .and_then(|x| {
659 let res: super::Response<DeleteModelStateResult, DeleteModelStateError> =
660 serde_json::from_slice(&x.0)?;
661 match res {
662 super::Response::Result(val) => Ok(val),
663 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
664 }
665 })
666 }
667
668 pub async fn get_model_state(
669 &self,
670 params: GetModelStateParams<'_, impl AsRef<str>>,
671 ) -> Result<GetModelStateResult, crate::client::DecthingsRpcError<GetModelStateError>> {
672 let (tx, rx) = tokio::sync::oneshot::channel();
673 self.rpc
674 .raw_method_call::<_, _, &[u8]>(
675 "Model",
676 "getModelState",
677 params,
678 &[],
679 crate::client::RpcProtocol::Http,
680 |x| {
681 tx.send(x).ok();
682 StateModification::empty()
683 },
684 )
685 .await;
686 rx.await
687 .unwrap()
688 .map_err(crate::client::DecthingsRpcError::Request)
689 .and_then(|x| {
690 let res: super::Response<GetModelStateResult, GetModelStateError> =
691 serde_json::from_slice(&x.0)?;
692 match res {
693 super::Response::Result(val) => Ok(GetModelStateResult {
694 data: val
695 .data
696 .into_iter()
697 .zip(x.1)
698 .map(|(key, data)| super::StateKeyData { key: key.key, data })
699 .collect(),
700 }),
701 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
702 }
703 })
704 }
705
706 pub async fn get_snapshot_state(
707 &self,
708 params: GetSnapshotStateParams<'_, impl AsRef<str>>,
709 ) -> Result<GetSnapshotStateResult, crate::client::DecthingsRpcError<GetSnapshotStateError>>
710 {
711 let (tx, rx) = tokio::sync::oneshot::channel();
712 self.rpc
713 .raw_method_call::<_, _, &[u8]>(
714 "Model",
715 "getSnapshotState",
716 params,
717 &[],
718 crate::client::RpcProtocol::Http,
719 |x| {
720 tx.send(x).ok();
721 StateModification::empty()
722 },
723 )
724 .await;
725 rx.await
726 .unwrap()
727 .map_err(crate::client::DecthingsRpcError::Request)
728 .and_then(|x| {
729 let res: super::Response<GetSnapshotStateResult, GetSnapshotStateError> =
730 serde_json::from_slice(&x.0)?;
731 match res {
732 super::Response::Result(val) => Ok(GetSnapshotStateResult {
733 data: val
734 .data
735 .into_iter()
736 .zip(x.1)
737 .map(|(key, data)| super::StateKeyData { key: key.key, data })
738 .collect(),
739 }),
740 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
741 }
742 })
743 }
744
745 pub async fn train(
746 &self,
747 params: TrainParams<'_>,
748 ) -> Result<TrainResult, crate::client::DecthingsRpcError<TrainError>> {
749 let (tx, rx) = tokio::sync::oneshot::channel();
750 let serialized = crate::client::serialize_parameter_provider_list(params.params.iter());
751 self.rpc
752 .raw_method_call(
753 "Model",
754 "train",
755 params,
756 serialized,
757 crate::client::RpcProtocol::Http,
758 |x| {
759 tx.send(x).ok();
760 StateModification::empty()
761 },
762 )
763 .await;
764 rx.await
765 .unwrap()
766 .map_err(crate::client::DecthingsRpcError::Request)
767 .and_then(|x| {
768 let res: super::Response<TrainResult, TrainError> = serde_json::from_slice(&x.0)?;
769 match res {
770 super::Response::Result(val) => Ok(val),
771 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
772 }
773 })
774 }
775
776 pub async fn get_training_status(
777 &self,
778 params: GetTrainingStatusParams<'_>,
779 ) -> Result<GetTrainingStatusResult, crate::client::DecthingsRpcError<GetTrainingStatusError>>
780 {
781 let (tx, rx) = tokio::sync::oneshot::channel();
782 self.rpc
783 .raw_method_call::<_, _, &[u8]>(
784 "Model",
785 "getTrainingStatus",
786 params,
787 &[],
788 crate::client::RpcProtocol::Http,
789 |x| {
790 tx.send(x).ok();
791 StateModification::empty()
792 },
793 )
794 .await;
795 rx.await
796 .unwrap()
797 .map_err(crate::client::DecthingsRpcError::Request)
798 .and_then(|x| {
799 let res: super::Response<GetTrainingStatusResult, GetTrainingStatusError> =
800 serde_json::from_slice(&x.0)?;
801 match res {
802 super::Response::Result(val) => Ok(val),
803 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
804 }
805 })
806 }
807
808 pub async fn get_training_metrics(
809 &self,
810 params: GetTrainingMetricsParams<'_>,
811 ) -> Result<GetTrainingMetricsResult, crate::client::DecthingsRpcError<GetTrainingMetricsError>>
812 {
813 let (tx, rx) = tokio::sync::oneshot::channel();
814 self.rpc
815 .raw_method_call::<_, _, &[u8]>(
816 "Model",
817 "getTrainingMetrics",
818 params,
819 &[],
820 crate::client::RpcProtocol::Http,
821 |x| {
822 tx.send(x).ok();
823 StateModification::empty()
824 },
825 )
826 .await;
827 rx.await
828 .unwrap()
829 .map_err(crate::client::DecthingsRpcError::Request)
830 .and_then(|x| {
831 let res: super::Response<GetTrainingMetricsResult, GetTrainingMetricsError> =
832 serde_json::from_slice(&x.0)?;
833 match res {
834 super::Response::Result(mut val) => {
835 if val.metrics.iter().map(|x| x.entries.len()).sum::<usize>() != x.1.len() {
836 return Err(crate::client::DecthingsClientError::InvalidMessage.into());
837 }
838 for (entry, data) in val
839 .metrics
840 .iter_mut()
841 .flat_map(|x| x.entries.iter_mut())
842 .zip(x.1)
843 {
844 entry.data = OwnedDecthingsTensor::from_bytes(data)
845 .map_err(|_| crate::client::DecthingsClientError::InvalidMessage)?;
846 }
847 Ok(val)
848 }
849 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
850 }
851 })
852 }
853
854 pub async fn cancel_training_session(
855 &self,
856 params: CancelTrainingSessionParams<'_>,
857 ) -> Result<
858 CancelTrainingSessionResult,
859 crate::client::DecthingsRpcError<CancelTrainingSessionError>,
860 > {
861 let (tx, rx) = tokio::sync::oneshot::channel();
862 self.rpc
863 .raw_method_call::<_, _, &[u8]>(
864 "Model",
865 "cancelTrainingSession",
866 params,
867 &[],
868 crate::client::RpcProtocol::Http,
869 |x| {
870 tx.send(x).ok();
871 StateModification::empty()
872 },
873 )
874 .await;
875 rx.await
876 .unwrap()
877 .map_err(crate::client::DecthingsRpcError::Request)
878 .and_then(|x| {
879 let res: super::Response<CancelTrainingSessionResult, CancelTrainingSessionError> =
880 serde_json::from_slice(&x.0)?;
881 match res {
882 super::Response::Result(val) => Ok(val),
883 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
884 }
885 })
886 }
887
888 pub async fn clear_previous_training_session(
889 &self,
890 params: ClearPreviousTrainingSessionParams<'_>,
891 ) -> Result<
892 ClearPreviousTrainingSessionResult,
893 crate::client::DecthingsRpcError<ClearPreviousTrainingSessionError>,
894 > {
895 let (tx, rx) = tokio::sync::oneshot::channel();
896 self.rpc
897 .raw_method_call::<_, _, &[u8]>(
898 "Model",
899 "clearPreviousTrainingSession",
900 params,
901 &[],
902 crate::client::RpcProtocol::Http,
903 |x| {
904 tx.send(x).ok();
905 StateModification::empty()
906 },
907 )
908 .await;
909 rx.await
910 .unwrap()
911 .map_err(crate::client::DecthingsRpcError::Request)
912 .and_then(|x| {
913 let res: super::Response<
914 ClearPreviousTrainingSessionResult,
915 ClearPreviousTrainingSessionError,
916 > = serde_json::from_slice(&x.0)?;
917 match res {
918 super::Response::Result(val) => Ok(val),
919 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
920 }
921 })
922 }
923
924 pub async fn evaluate<'a>(
925 &self,
926 params: EvaluateParams<'a>,
927 ) -> Result<EvaluateResult, crate::client::DecthingsRpcError<EvaluateError>> {
928 let (tx, rx) = tokio::sync::oneshot::channel();
929 let serialized = crate::client::serialize_parameter_provider_list(params.params.iter());
930 self.rpc
931 .raw_method_call(
932 "Model",
933 "evaluate",
934 params,
935 serialized,
936 crate::client::RpcProtocol::Http,
937 |x| {
938 tx.send(x).ok();
939 StateModification::empty()
940 },
941 )
942 .await;
943 rx.await
944 .unwrap()
945 .map_err(crate::client::DecthingsRpcError::Request)
946 .and_then(|x| {
947 let res: super::Response<EvaluateResult, EvaluateError> =
948 serde_json::from_slice(&x.0)?;
949 match res {
950 super::Response::Result(EvaluateResult::Success {
951 total_duration,
952 durations,
953 executed_on_launcher,
954 mut output,
955 }) => {
956 if output.len() != x.1.len() {
957 return Err(crate::client::DecthingsClientError::InvalidMessage.into());
958 }
959 for (entry, data) in output.iter_mut().zip(x.1) {
960 entry.data = super::many_decthings_tensors_from_bytes(data)
961 .map_err(|_| crate::client::DecthingsClientError::InvalidMessage)?;
962 }
963 Ok(EvaluateResult::Success {
964 total_duration,
965 durations,
966 executed_on_launcher,
967 output,
968 })
969 }
970 super::Response::Result(val) => Ok(val),
971 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
972 }
973 })
974 }
975
976 pub async fn get_evaluations(
977 &self,
978 params: GetEvaluationsParams<'_>,
979 ) -> Result<GetEvaluationsResult, crate::client::DecthingsRpcError<GetEvaluationsError>> {
980 let (tx, rx) = tokio::sync::oneshot::channel();
981 self.rpc
982 .raw_method_call::<_, _, &[u8]>(
983 "Model",
984 "getEvaluations",
985 params,
986 &[],
987 crate::client::RpcProtocol::Http,
988 |x| {
989 tx.send(x).ok();
990 StateModification::empty()
991 },
992 )
993 .await;
994 rx.await
995 .unwrap()
996 .map_err(crate::client::DecthingsRpcError::Request)
997 .and_then(|x| {
998 let res: super::Response<GetEvaluationsResult, GetEvaluationsError> =
999 serde_json::from_slice(&x.0)?;
1000 match res {
1001 super::Response::Result(val) => Ok(val),
1002 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
1003 }
1004 })
1005 }
1006
1007 pub async fn get_finished_evaluation_result(
1008 &self,
1009 params: GetFinishedEvaluationResultParams<'_>,
1010 ) -> Result<
1011 GetFinishedEvaluationResultResult,
1012 crate::client::DecthingsRpcError<GetFinishedEvaluationResultError>,
1013 > {
1014 let (tx, rx) = tokio::sync::oneshot::channel();
1015 self.rpc
1016 .raw_method_call::<_, _, &[u8]>(
1017 "Model",
1018 "getFinishedEvaluationResult",
1019 params,
1020 &[],
1021 crate::client::RpcProtocol::Http,
1022 |x| {
1023 tx.send(x).ok();
1024 StateModification::empty()
1025 },
1026 )
1027 .await;
1028 rx.await
1029 .unwrap()
1030 .map_err(crate::client::DecthingsRpcError::Request)
1031 .and_then(|x| {
1032 let res: super::Response<
1033 GetFinishedEvaluationResultResult,
1034 GetFinishedEvaluationResultError,
1035 > = serde_json::from_slice(&x.0)?;
1036 match res {
1037 super::Response::Result(GetFinishedEvaluationResultResult::Success {
1038 total_duration,
1039 durations,
1040 executed_on_launcher,
1041 mut output,
1042 }) => {
1043 if output.len() != x.1.len() {
1044 return Err(crate::client::DecthingsClientError::InvalidMessage.into());
1045 }
1046 for (entry, data) in output.iter_mut().zip(x.1) {
1047 entry.data = super::many_decthings_tensors_from_bytes(data)
1048 .map_err(|_| crate::client::DecthingsClientError::InvalidMessage)?;
1049 }
1050 Ok::<
1051 GetFinishedEvaluationResultResult,
1052 crate::client::DecthingsRpcError<GetFinishedEvaluationResultError>,
1053 >(GetFinishedEvaluationResultResult::Success {
1054 total_duration,
1055 durations,
1056 executed_on_launcher,
1057 output,
1058 })
1059 }
1060 super::Response::Result(val) => Ok(val),
1061 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
1062 }
1063 })
1064 }
1065
1066 pub async fn cancel_evaluation(
1067 &self,
1068 params: CancelEvaluationParams<'_>,
1069 ) -> Result<CancelEvaluationResult, crate::client::DecthingsRpcError<CancelEvaluationError>>
1070 {
1071 let (tx, rx) = tokio::sync::oneshot::channel();
1072 self.rpc
1073 .raw_method_call::<_, _, &[u8]>(
1074 "Model",
1075 "cancelEvaluation",
1076 params,
1077 &[],
1078 crate::client::RpcProtocol::Http,
1079 |x| {
1080 tx.send(x).ok();
1081 StateModification::empty()
1082 },
1083 )
1084 .await;
1085 rx.await
1086 .unwrap()
1087 .map_err(crate::client::DecthingsRpcError::Request)
1088 .and_then(|x| {
1089 let res: super::Response<CancelEvaluationResult, CancelEvaluationError> =
1090 serde_json::from_slice(&x.0)?;
1091 match res {
1092 super::Response::Result(val) => Ok(val),
1093 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
1094 }
1095 })
1096 }
1097
1098 pub async fn set_used_persistent_launchers_for_evaluate(
1099 &self,
1100 params: SetUsedPersistentLaunchersForEvaluateParams<'_>,
1101 ) -> Result<
1102 SetUsedPersistentLaunchersForEvaluateResult,
1103 crate::client::DecthingsRpcError<SetUsedPersistentLaunchersForEvaluateError>,
1104 > {
1105 let (tx, rx) = tokio::sync::oneshot::channel();
1106 self.rpc
1107 .raw_method_call::<_, _, &[u8]>(
1108 "Model",
1109 "setUsedPersistentLaunchersForEvaluate",
1110 params,
1111 &[],
1112 crate::client::RpcProtocol::Http,
1113 |x| {
1114 tx.send(x).ok();
1115 StateModification::empty()
1116 },
1117 )
1118 .await;
1119 rx.await
1120 .unwrap()
1121 .map_err(crate::client::DecthingsRpcError::Request)
1122 .and_then(|x| {
1123 let res: super::Response<
1124 SetUsedPersistentLaunchersForEvaluateResult,
1125 SetUsedPersistentLaunchersForEvaluateError,
1126 > = serde_json::from_slice(&x.0)?;
1127 match res {
1128 super::Response::Result(val) => Ok(val),
1129 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
1130 }
1131 })
1132 }
1133
1134 pub async fn get_used_persistent_launchers_for_evaluate(
1135 &self,
1136 params: GetUsedPersistentLaunchersForEvaluateParams<'_>,
1137 ) -> Result<
1138 GetUsedPersistentLaunchersForEvaluateResult,
1139 crate::client::DecthingsRpcError<GetUsedPersistentLaunchersForEvaluateError>,
1140 > {
1141 let (tx, rx) = tokio::sync::oneshot::channel();
1142 self.rpc
1143 .raw_method_call::<_, _, &[u8]>(
1144 "Model",
1145 "getUsedPersistentLaunchersForEvaluate",
1146 params,
1147 &[],
1148 crate::client::RpcProtocol::Http,
1149 |x| {
1150 tx.send(x).ok();
1151 StateModification::empty()
1152 },
1153 )
1154 .await;
1155 rx.await
1156 .unwrap()
1157 .map_err(crate::client::DecthingsRpcError::Request)
1158 .and_then(|x| {
1159 let res: super::Response<
1160 GetUsedPersistentLaunchersForEvaluateResult,
1161 GetUsedPersistentLaunchersForEvaluateError,
1162 > = serde_json::from_slice(&x.0)?;
1163 match res {
1164 super::Response::Result(val) => Ok(val),
1165 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
1166 }
1167 })
1168 }
1169}