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
use serde_json::json;
pub use crate::api::{API, Strings, StringsBatch};
/// Summary definition
pub struct Summary {
api: API
}
/// Summary implementation
impl Summary {
/// Creates a Summary instance.
///
pub fn new() -> Summary {
Summary {
api: API::new()
}
}
/// Creates a Summary instance.
///
/// # Arguments
/// * `url` - API url
pub fn with_url(url: &str) -> Summary {
Summary {
api: API::with_url(url)
}
}
/// Creates a Summary instance.
///
/// # Arguments
/// * `url` - API url
/// * `token` - API token
pub fn with_url_token(url: &str, token: &str) -> Summary {
Summary {
api: API::with_url_token(url, token)
}
}
/// Runs a summarization model against a block of text.
///
/// # Arguments
/// * `text` text to summarize
/// * `minlength` minimum length for summary
/// * `maxlength` maximum length for summary
pub async fn summary(&self, text: &str, minlength: Option<i32>, maxlength: Option<i32>) -> Strings {
// Query parameters
let mut params = vec![("text", text)];
let minl = minlength.unwrap_or(-1).to_string();
let maxl = maxlength.unwrap_or(-1).to_string();
if minl != "-1" {
params.push(("minlength", &minl));
}
if maxl != "-1" {
params.push(("maxlength", &maxl));
}
// Execute API call
Ok(self.api.get("summary", ¶ms).await?.json().await?)
}
/// Runs a summarization model against a block of text.
///
/// # Arguments
/// * `texts` list of text to summarize
/// * `minlength` minimum length for summary
/// * `maxlength` maximum length for summary
pub async fn batchsummary(&self, texts: &Vec<&str>, minlength: Option<i32>, maxlength: Option<i32>) -> StringsBatch {
// Post parameters
let params = json!({
"text": texts,
"minlength": minlength,
"maxlength": maxlength
});
// Execute API call
Ok(self.api.post("batchsummary", ¶ms).await?.json().await?)
}
}