mcp_host/content/
prompt.rs1use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct PromptMessage {
10 pub role: PromptRole,
12
13 pub content: PromptContent,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(rename_all = "lowercase")]
20pub enum PromptRole {
21 User,
23
24 Assistant,
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(tag = "type", rename_all = "camelCase")]
31pub enum PromptContent {
32 #[serde(rename = "text")]
34 Text { text: String },
35
36 #[serde(rename = "image")]
38 Image {
39 data: String,
40 #[serde(rename = "mimeType")]
41 mime_type: String,
42 },
43
44 #[serde(rename = "resource")]
46 Resource {
47 uri: String,
48 #[serde(skip_serializing_if = "Option::is_none", rename = "mimeType")]
49 mime_type: Option<String>,
50 #[serde(skip_serializing_if = "Option::is_none")]
51 text: Option<String>,
52 },
53}
54
55impl PromptMessage {
56 pub fn user(text: impl Into<String>) -> Self {
58 Self {
59 role: PromptRole::User,
60 content: PromptContent::Text { text: text.into() },
61 }
62 }
63
64 pub fn assistant(text: impl Into<String>) -> Self {
66 Self {
67 role: PromptRole::Assistant,
68 content: PromptContent::Text { text: text.into() },
69 }
70 }
71
72 pub fn user_image(data: impl Into<String>, mime_type: impl Into<String>) -> Self {
74 Self {
75 role: PromptRole::User,
76 content: PromptContent::Image {
77 data: data.into(),
78 mime_type: mime_type.into(),
79 },
80 }
81 }
82
83 pub fn assistant_image(data: impl Into<String>, mime_type: impl Into<String>) -> Self {
85 Self {
86 role: PromptRole::Assistant,
87 content: PromptContent::Image {
88 data: data.into(),
89 mime_type: mime_type.into(),
90 },
91 }
92 }
93}