async_llm/types/
prediction_content.rs

1use serde::{Deserialize, Serialize};
2
3/// Static predicted output content, such as the content of a text file that is being regenerated.
4/// The type of the predicted content you want to provide. This type is currently always content.
5#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
6#[serde(tag = "type")]
7#[serde(rename_all = "snake_case")]
8#[serde(content = "content")]
9pub enum PredictionContent {
10    Content(PredictionContentContent),
11}
12
13/// 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.
14#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
15#[serde(untagged)]
16#[serde(rename_all = "snake_case")]
17pub enum PredictionContentContent {
18    /// The content used for a Predicted Output. This is often the text of a file you are regenerating with minor changes.
19    Text(String),
20    /// 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.
21    Array(Vec<PredictionContentPart>),
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
25#[serde(tag = "type")]
26#[serde(rename_all = "snake_case")]
27pub enum PredictionContentPart {
28    Text { text: String },
29}
30
31impl Default for PredictionContent {
32    fn default() -> Self {
33        Self::Content("".into())
34    }
35}
36
37impl From<&str> for PredictionContent {
38    fn from(value: &str) -> Self {
39        Self::Content(value.into())
40    }
41}
42impl From<&str> for PredictionContentContent {
43    fn from(value: &str) -> Self {
44        Self::Text(value.into())
45    }
46}
47
48impl From<Vec<&str>> for PredictionContent {
49    fn from(value: Vec<&str>) -> Self {
50        Self::Content(value.into())
51    }
52}
53
54impl From<Vec<&str>> for PredictionContentContent {
55    fn from(value: Vec<&str>) -> Self {
56        Self::Array(
57            value
58                .into_iter()
59                .map(|v| PredictionContentPart::Text {
60                    text: v.to_string(),
61                })
62                .collect(),
63        )
64    }
65}