Refactor types into separate files
This commit is contained in:
41
src/types/common.rs
Normal file
41
src/types/common.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Content {
|
||||
pub role: String,
|
||||
pub parts: Option<Vec<Part>>,
|
||||
}
|
||||
|
||||
impl Content {
|
||||
pub fn get_text(&self) -> Option<String> {
|
||||
self.parts.as_ref().map(|parts| {
|
||||
parts
|
||||
.iter()
|
||||
.filter_map(|part| match part {
|
||||
Part::Text(text) => Some(text.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<String>()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum Part {
|
||||
Text(String),
|
||||
InlineData {
|
||||
mime_type: String,
|
||||
data: String,
|
||||
},
|
||||
FileData {
|
||||
mime_type: String,
|
||||
file_uri: String,
|
||||
},
|
||||
FunctionCall {
|
||||
name: String,
|
||||
args: HashMap<String, String>,
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user