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
use serde_json::json;
pub use crate::api::{API, IndexResults, IndexResultsBatch};
/// Labels definition
pub struct Labels {
api: API
}
/// Labels implementation
impl Labels {
/// Creates a Labels instance.
///
pub fn new() -> Labels {
Labels {
api: API::new()
}
}
/// Creates a Labels instance.
///
/// # Arguments
/// * `url` - API url
pub fn with_url(url: &str) -> Labels {
Labels {
api: API::with_url(url)
}
}
/// Creates a Labels instance.
///
/// # Arguments
/// * `url` - API url
/// * `token` - API token
pub fn with_url_token(url: &str, token: &str) -> Labels {
Labels {
api: API::with_url_token(url, token)
}
}
/// Applies a zero shot classifier to text using a list of labels. Returns a list of
/// {id: value, score: value} sorted by highest score, where id is the index in labels.
///
/// # Arguments
/// * `text` - input text
/// * `labels` - list of labels
pub async fn label(&self, text: &str, labels: &Vec<&str>) -> IndexResults {
// Post parameters
let params = json!({"text": text, "labels": labels});
// Execute API call
Ok(self.api.post("label", ¶ms).await?.json().await?)
}
/// Applies a zero shot classifier to list of text using a list of labels. Returns a list of
/// {id: value, score: value} sorted by highest score, where id is the index in labels per
/// text element.
///
/// # Arguments
/// * `texts` - list of texts
/// * `labels` - list of labels
pub async fn batchlabel(&self, texts: &Vec<&str>, labels: &Vec<&str>) -> IndexResultsBatch {
// Post parameters
let params = json!({"texts": texts, "labels": labels});
// Execute API call
Ok(self.api.post("batchlabel", ¶ms).await?.json().await?)
}
}