use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Role {
System,
User,
Assistant,
Tool,
}
impl Role {
pub fn as_str(&self) -> &'static str {
match self {
Role::System => "system",
Role::User => "user",
Role::Assistant => "assistant",
Role::Tool => "tool",
}
}
pub fn is_system(&self) -> bool {
matches!(self, Role::System)
}
pub fn is_user(&self) -> bool {
matches!(self, Role::User)
}
pub fn is_assistant(&self) -> bool {
matches!(self, Role::Assistant)
}
pub fn is_tool(&self) -> bool {
matches!(self, Role::Tool)
}
}
impl std::fmt::Display for Role {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_str())
}
}