1#[derive(Debug, Clone, PartialEq)]
2pub enum Role {
3 System,
4 User,
5 Assistant,
6}
7
8#[derive(Debug, Clone, PartialEq)]
10pub enum ImageSource {
11 Base64 {
13 media_type: String,
14 data: String,
15 },
16 Url(String),
18}
19
20#[derive(Debug, Clone, PartialEq)]
22pub struct ToolUse {
23 pub id: String,
25 pub name: String,
27 pub input: String,
29}
30
31#[derive(Debug, Clone, PartialEq)]
33pub struct ToolResult {
34 pub tool_use_id: String,
36 pub content: String,
38 pub is_error: bool,
40}
41
42#[derive(Debug, Clone, PartialEq)]
44pub enum Content {
45 Text(String),
47 Image(ImageSource),
49 ToolUse(ToolUse),
51 ToolResult(ToolResult),
53}
54
55#[derive(Debug, Clone, PartialEq)]
56pub struct Message {
57 pub role: Role,
58 pub content: Vec<Content>,
59}
60
61impl Message {
62 pub fn new(role: Role, text: impl Into<String>) -> Self {
63 Self {
64 role,
65 content: vec![Content::Text(text.into())],
66 }
67 }
68
69 pub fn with_content(role: Role, content: Vec<Content>) -> Self {
71 Self { role, content }
72 }
73
74 pub fn system(text: impl Into<String>) -> Self {
75 Self::new(Role::System, text)
76 }
77
78 pub fn user(text: impl Into<String>) -> Self {
79 Self::new(Role::User, text)
80 }
81
82 pub fn assistant(text: impl Into<String>) -> Self {
83 Self::new(Role::Assistant, text)
84 }
85
86 pub fn tool_result(tool_use_id: impl Into<String>, content: impl Into<String>, is_error: bool) -> Self {
88 Self {
89 role: Role::User,
90 content: vec![Content::ToolResult(ToolResult {
91 tool_use_id: tool_use_id.into(),
92 content: content.into(),
93 is_error,
94 })],
95 }
96 }
97}
98
99#[derive(Debug, Clone, PartialEq)]
101pub struct Tool {
102 pub name: String,
104 pub description: String,
106 pub input_schema: String,
108}
109
110impl Tool {
111 pub fn new(
112 name: impl Into<String>,
113 description: impl Into<String>,
114 input_schema: impl Into<String>,
115 ) -> Self {
116 Self {
117 name: name.into(),
118 description: description.into(),
119 input_schema: input_schema.into(),
120 }
121 }
122}
123
124#[derive(Debug, Clone, PartialEq)]
126pub enum ToolChoice {
127 Auto,
129 Any,
131 Tool(String),
133 None,
135}
136
137impl Default for ToolChoice {
138 fn default() -> Self {
139 Self::Auto
140 }
141}
142
143#[derive(Debug, Clone, PartialEq, Default)]
145pub struct Metadata {
146 pub user_id: Option<String>,
148}
149
150#[derive(Debug, Clone, Default)]
151pub struct MessageOptions {
152 pub temperature: Option<f32>,
154 pub max_tokens: Option<u32>,
156 pub model: Option<String>,
158 pub tools: Option<Vec<Tool>>,
160 pub tool_choice: Option<ToolChoice>,
162 pub stop_sequences: Option<Vec<String>>,
164 pub top_p: Option<f32>,
166 pub top_k: Option<u32>,
168 pub metadata: Option<Metadata>,
170}
171
172#[derive(Debug, Clone, PartialEq)]
178pub enum StreamEvent {
179 MessageStart {
181 message_id: String,
182 model: String,
183 },
184 ContentBlockStart {
186 index: usize,
187 block_type: ContentBlockType,
188 },
189 TextDelta {
191 index: usize,
192 text: String,
193 },
194 InputJsonDelta {
196 index: usize,
197 json: String,
198 },
199 ContentBlockStop {
201 index: usize,
202 },
203 MessageDelta {
205 stop_reason: Option<String>,
206 usage: Option<Usage>,
207 },
208 MessageStop,
210 Ping,
212}
213
214#[derive(Debug, Clone, PartialEq)]
216pub enum ContentBlockType {
217 Text,
218 ToolUse { id: String, name: String },
219}
220
221#[derive(Debug, Clone, PartialEq, Default)]
223pub struct Usage {
224 pub input_tokens: u32,
226 pub output_tokens: u32,
228}