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
83
use serde::{Deserialize, Serialize};

use super::GenerateModel;

#[derive(Serialize, Default, Debug)]
pub struct SummarizeRequest<'input> {
    /// Text to summarize
    pub text: &'input str,
    /// 'One of `paragraph`, `bullets` or `auto`, defaults to `auto`.
    /// Indicates the style in which the summary will be delivered - in a free form
    /// paragraph or in bullet points.'
    #[serde(skip_serializing_if = "Option::is_none")]
    pub format: Option<SummarizeFormat>,
    /// One of `short`, `medium`, `long` or `auto` defaults to `auto`. Indicates the approximate length of the summary.'
    #[serde(skip_serializing_if = "Option::is_none")]
    pub length: Option<SummarizeLength>,
    /// One of `low`, `medium`, `high` or `auto`, defaults to `auto`. Controls how close to the original text the summary is.
    /// `high` extractiveness summaries will lean towards reusing sentences verbatim, while `low` extractiveness
    /// summaries will tend to paraphrase more.'
    #[serde(skip_serializing_if = "Option::is_none")]
    pub extractiveness: Option<SummarizeExtractiveness>,
    /// Ranges from 0 to 5. Controls the randomness of the output. Lower values tend to generate more “predictable” output,
    /// while higher values tend to generate more “creative” output. The sweet spot is typically between 0 and 1.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub temperature: Option<f64>,
    /// A free-form instruction for modifying how the summaries get generated. Should complete the sentence "Generate a summary _".
    /// Eg. "focusing on the next steps" or "written by Yoda"
    #[serde(skip_serializing_if = "Option::is_none")]
    pub additional_command: Option<String>,
    /// Denotes the summarization model to be used. Defaults to the best performing model
    #[serde(skip_serializing_if = "Option::is_none")]
    pub model: Option<GenerateModel>,
}

#[derive(strum_macros::Display, Serialize, Debug)]
pub enum SummarizeLength {
    #[strum(serialize = "short")]
    #[serde(rename = "short")]
    Short,
    #[strum(serialize = "medium")]
    #[serde(rename = "medium")]
    Medium,
    #[strum(serialize = "long")]
    #[serde(rename = "long")]
    Long,
    #[strum(serialize = "auto")]
    #[serde(rename = "auto")]
    Auto,
}

#[derive(strum_macros::Display, Serialize, Debug)]
pub enum SummarizeFormat {
    #[strum(serialize = "paragraph")]
    #[serde(rename = "paragraph")]
    Paragraph,
    #[strum(serialize = "bullets")]
    #[serde(rename = "bullets")]
    Bullets,
    #[strum(serialize = "auto")]
    #[serde(rename = "auto")]
    Auto,
}

#[derive(strum_macros::Display, Serialize, Debug)]
pub enum SummarizeExtractiveness {
    #[strum(serialize = "low")]
    #[serde(rename = "low")]
    Low,
    #[strum(serialize = "medium")]
    #[serde(rename = "medium")]
    Medium,
    #[strum(serialize = "high")]
    #[serde(rename = "high")]
    High,
    #[strum(serialize = "auto")]
    #[serde(rename = "auto")]
    Auto,
}

#[derive(Deserialize, Debug)]
pub(crate) struct SummarizeResponse {
    pub summary: String,
}