hehe_core/message/
role.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
4#[serde(rename_all = "lowercase")]
5pub enum Role {
6 System,
7 User,
8 Assistant,
9 Tool,
10}
11
12impl Role {
13 pub fn as_str(&self) -> &'static str {
14 match self {
15 Role::System => "system",
16 Role::User => "user",
17 Role::Assistant => "assistant",
18 Role::Tool => "tool",
19 }
20 }
21
22 pub fn is_system(&self) -> bool {
23 matches!(self, Role::System)
24 }
25
26 pub fn is_user(&self) -> bool {
27 matches!(self, Role::User)
28 }
29
30 pub fn is_assistant(&self) -> bool {
31 matches!(self, Role::Assistant)
32 }
33
34 pub fn is_tool(&self) -> bool {
35 matches!(self, Role::Tool)
36 }
37}
38
39impl std::fmt::Display for Role {
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41 write!(f, "{}", self.as_str())
42 }
43}