async_llm/types/
prediction_content.rs

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

/// Static predicted output content, such as the content of a text file that is being regenerated.
/// The type of the predicted content you want to provide. This type is currently always content.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
#[serde(content = "content")]
pub enum PredictionContent {
    Content(PredictionContentContent),
}

/// The content that should be matched when generating a model response. If generated tokens would match this content, the entire model response can be returned much more quickly.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
#[serde(rename_all = "snake_case")]
pub enum PredictionContentContent {
    /// The content used for a Predicted Output. This is often the text of a file you are regenerating with minor changes.
    Text(String),
    /// An array of content parts with a defined type. Supported options differ based on the model being used to generate the response. Can contain text inputs.
    Array(Vec<PredictionContentPart>),
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
pub enum PredictionContentPart {
    Text { text: String },
}

impl Default for PredictionContent {
    fn default() -> Self {
        Self::Content("".into())
    }
}

impl From<&str> for PredictionContent {
    fn from(value: &str) -> Self {
        Self::Content(value.into())
    }
}
impl From<&str> for PredictionContentContent {
    fn from(value: &str) -> Self {
        Self::Text(value.into())
    }
}

impl From<Vec<&str>> for PredictionContent {
    fn from(value: Vec<&str>) -> Self {
        Self::Content(value.into())
    }
}

impl From<Vec<&str>> for PredictionContentContent {
    fn from(value: Vec<&str>) -> Self {
        Self::Array(
            value
                .into_iter()
                .map(|v| PredictionContentPart::Text {
                    text: v.to_string(),
                })
                .collect(),
        )
    }
}