role.rs

 1use serde::{Deserialize, Serialize};
 2use std::fmt::{self, Display};
 3
 4#[derive(Clone, Copy, Serialize, Deserialize, Debug, Eq, PartialEq, Hash)]
 5#[serde(rename_all = "lowercase")]
 6pub enum Role {
 7    User,
 8    Assistant,
 9    System,
10}
11
12impl Role {
13    pub fn cycle(self) -> Role {
14        match self {
15            Role::User => Role::Assistant,
16            Role::Assistant => Role::System,
17            Role::System => Role::User,
18        }
19    }
20}
21
22impl Display for Role {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
24        match self {
25            Role::User => write!(f, "user"),
26            Role::Assistant => write!(f, "assistant"),
27            Role::System => write!(f, "system"),
28        }
29    }
30}