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

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum Content {
    Text(String),
    Array(Vec<String>),
}

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

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

impl From<String> for Content {
    fn from(value: String) -> Self {
        Self::Text(value)
    }
}

impl From<Vec<&str>> for Content {
    fn from(value: Vec<&str>) -> Self {
        Self::Array(value.iter().map(|v| v.to_string()).collect())
    }
}

impl From<Vec<String>> for Content {
    fn from(array: Vec<String>) -> Self {
        Self::Array(array)
    }
}