1#[ cfg( feature = "enabled" ) ]
7mod private
8{
9 use serde::{ Serialize, Deserialize };
10 use core::hash::{ Hash, Hasher };
11
12 #[ derive( Debug, Clone, Serialize, Deserialize ) ]
14 #[ cfg_attr( feature = "request_caching", derive( Hash ) ) ]
15 pub struct Message
16 {
17 pub role : String,
19 pub content : String,
21 }
22
23 #[ cfg( feature = "vision_support" ) ]
25 #[ derive( Debug, Clone, Serialize, Deserialize, Default, PartialEq ) ]
26 #[ cfg_attr( feature = "request_caching", derive( Hash ) ) ]
27 #[ serde( rename_all = "lowercase" ) ]
28 pub enum MessageRole
29 {
30 #[ default ]
32 User,
33 Assistant,
35 System,
37 #[ cfg( feature = "tool_calling" ) ]
39 Tool,
40 }
41
42 #[ cfg( feature = "vision_support" ) ]
44 #[ derive( Debug, Clone, Serialize, Deserialize, Default ) ]
45 #[ cfg_attr( feature = "request_caching", derive( Hash ) ) ]
46 pub struct ChatMessage
47 {
48 pub role : MessageRole,
50 pub content : String,
52 #[ serde( skip_serializing_if = "Option::is_none" ) ]
54 pub images : Option< Vec< String > >,
55 #[ cfg( feature = "tool_calling" ) ]
57 #[ serde( skip_serializing_if = "Option::is_none" ) ]
58 pub tool_calls : Option< Vec< ToolCall > >,
59 }
60
61 #[ cfg( feature = "tool_calling" ) ]
63 #[ derive( Debug, Clone, Serialize, Deserialize ) ]
64 pub struct ToolDefinition
65 {
66 pub name : String,
68 pub description : String,
70 pub parameters : serde_json::Value,
72 }
73
74 #[ cfg( all( feature = "tool_calling", feature = "request_caching" ) ) ]
75 impl Hash for ToolDefinition
76 {
77 #[ inline ]
78 fn hash< H : Hasher >( &self, state : &mut H )
79 {
80 self.name.hash( state );
81 self.description.hash( state );
82 self.parameters.to_string().hash( state );
83 }
84 }
85
86 #[ cfg( feature = "tool_calling" ) ]
88 #[ derive( Debug, Clone, Serialize, Deserialize ) ]
89 pub struct ToolCall
90 {
91 pub id : String,
93 pub function : serde_json::Value,
95 }
96
97 #[ cfg( all( feature = "tool_calling", feature = "request_caching" ) ) ]
98 impl Hash for ToolCall
99 {
100 #[ inline ]
101 fn hash< H : Hasher >( &self, state : &mut H )
102 {
103 self.id.hash( state );
104 self.function.to_string().hash( state );
105 }
106 }
107
108 #[ cfg( feature = "tool_calling" ) ]
110 #[ derive( Debug, Clone, Serialize, Deserialize ) ]
111 #[ cfg_attr( feature = "request_caching", derive( Hash ) ) ]
112 pub struct ToolMessage
113 {
114 pub role : MessageRole,
116 pub content : String,
118 pub tool_call_id : String,
120 }
121}
122
123#[ cfg( feature = "enabled" ) ]
124crate ::mod_interface!
125{
126 exposed use
127 {
128 Message,
129 };
130
131 #[ cfg( feature = "vision_support" ) ]
132 exposed use
133 {
134 MessageRole,
135 ChatMessage,
136 };
137
138 #[ cfg( feature = "tool_calling" ) ]
139 exposed use
140 {
141 ToolDefinition,
142 ToolCall,
143 ToolMessage,
144 };
145}