async_llm/types/
prediction_content.rs1use serde::{Deserialize, Serialize};
2
3#[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#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
15#[serde(untagged)]
16#[serde(rename_all = "snake_case")]
17pub enum PredictionContentContent {
18 Text(String),
20 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}