async_llm/types/
assistant_content.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
4#[serde(untagged)]
5pub enum AssistantContent {
6 Text(String),
7 Array(Vec<AssistantContentPart>),
8}
9
10#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
11#[serde(tag = "type")]
12#[serde(rename_all = "snake_case")]
13pub enum AssistantContentPart {
14 Text(String),
15 Refusal { refusal: String },
16}
17
18impl Default for AssistantContent {
19 fn default() -> Self {
20 Self::Text("".into())
21 }
22}
23
24impl From<&str> for AssistantContent {
25 fn from(value: &str) -> Self {
26 Self::Text(value.into())
27 }
28}
29
30impl From<Vec<&str>> for AssistantContent {
31 fn from(value: Vec<&str>) -> Self {
32 Self::Array(
33 value
34 .into_iter()
35 .map(|v| AssistantContentPart::Text(v.to_string()))
36 .collect(),
37 )
38 }
39}