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

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

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

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

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

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