1use alloc::string::String;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
7pub struct PromptDefinition {
8 pub name: String,
10 #[serde(default, skip_serializing_if = "String::is_empty")]
12 pub description: String,
13 #[serde(default, skip_serializing_if = "alloc::vec::Vec::is_empty")]
15 pub arguments: alloc::vec::Vec<PromptArgumentDefinition>,
16}
17
18#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
20pub struct PromptArgumentDefinition {
21 pub name: String,
23 #[serde(default, skip_serializing_if = "String::is_empty")]
25 pub description: String,
26 #[serde(default)]
28 pub required: bool,
29}
30
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
33#[serde(rename_all = "lowercase")]
34pub enum PromptRole {
35 User,
37 Assistant,
39 System,
41}
42
43impl PromptRole {
44 #[must_use]
46 pub const fn as_str(self) -> &'static str {
47 match self {
48 Self::User => "user",
49 Self::Assistant => "assistant",
50 Self::System => "system",
51 }
52 }
53}
54
55impl core::fmt::Display for PromptRole {
56 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
57 f.write_str(self.as_str())
58 }
59}
60
61#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
63pub struct PromptOutputMessage {
64 pub role: PromptRole,
66 pub content: String,
68}
69
70impl PromptOutputMessage {
71 pub fn user(content: impl Into<String>) -> Self {
73 Self {
74 role: PromptRole::User,
75 content: content.into(),
76 }
77 }
78
79 pub fn assistant(content: impl Into<String>) -> Self {
81 Self {
82 role: PromptRole::Assistant,
83 content: content.into(),
84 }
85 }
86
87 pub fn system(content: impl Into<String>) -> Self {
89 Self {
90 role: PromptRole::System,
91 content: content.into(),
92 }
93 }
94}
95
96#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
98pub struct PromptOutput {
99 pub messages: alloc::vec::Vec<PromptOutputMessage>,
101}
102
103impl PromptOutput {
104 pub fn user(content: impl Into<String>) -> Self {
106 Self {
107 messages: alloc::vec![PromptOutputMessage::user(content)],
108 }
109 }
110
111 pub fn assistant(content: impl Into<String>) -> Self {
113 Self {
114 messages: alloc::vec![PromptOutputMessage::assistant(content)],
115 }
116 }
117
118 pub fn system(content: impl Into<String>) -> Self {
120 Self {
121 messages: alloc::vec![PromptOutputMessage::system(content)],
122 }
123 }
124}
125
126impl From<String> for PromptOutput {
127 fn from(content: String) -> Self {
128 Self::user(content)
129 }
130}
131
132impl From<&str> for PromptOutput {
133 fn from(content: &str) -> Self {
134 Self::user(content)
135 }
136}