aleph_alpha_client/
detokenization.rs1use crate::Task;
2use serde::{Deserialize, Serialize};
3
4pub struct TaskDetokenization<'a> {
6 pub token_ids: &'a [u32],
8}
9
10#[derive(Serialize, Debug)]
12struct BodyDetokenization<'a> {
13 pub model: &'a str,
15 pub token_ids: &'a [u32],
17}
18
19#[derive(Deserialize, Debug, PartialEq, Eq)]
20pub struct ResponseDetokenization {
21 pub result: String,
22}
23
24#[derive(Debug, PartialEq, Eq)]
25pub struct DetokenizationOutput {
26 pub result: String,
27}
28
29impl From<ResponseDetokenization> for DetokenizationOutput {
30 fn from(response: ResponseDetokenization) -> Self {
31 Self {
32 result: response.result,
33 }
34 }
35}
36
37impl Task for TaskDetokenization<'_> {
38 type Output = DetokenizationOutput;
39 type ResponseBody = ResponseDetokenization;
40
41 fn build_request(
42 &self,
43 client: &reqwest::Client,
44 base: &str,
45 model: &str,
46 ) -> reqwest::RequestBuilder {
47 let body = BodyDetokenization {
48 model,
49 token_ids: self.token_ids,
50 };
51 client.post(format!("{base}/detokenize")).json(&body)
52 }
53
54 fn body_to_output(&self, response: Self::ResponseBody) -> Self::Output {
55 DetokenizationOutput::from(response)
56 }
57}