use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Role {
System,
Human,
Ai,
Tool,
}
impl std::fmt::Display for Role {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Role::System => write!(f, "system"),
Role::Human => write!(f, "human"),
Role::Ai => write!(f, "ai"),
Role::Tool => write!(f, "tool"),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Message {
pub role: Role,
pub content: String,
}
impl Message {
pub fn new(role: Role, content: impl Into<String>) -> Self {
Self {
role,
content: content.into(),
}
}
pub fn system(content: impl Into<String>) -> Self {
Self::new(Role::System, content)
}
pub fn human(content: impl Into<String>) -> Self {
Self::new(Role::Human, content)
}
pub fn ai(content: impl Into<String>) -> Self {
Self::new(Role::Ai, content)
}
}