@@ -24,6 +24,7 @@ use crate::tree_shake::TreeShaker;
24
24
pub struct Operation {
25
25
tool : Tool ,
26
26
source_text : String ,
27
+ character_count : usize ,
27
28
}
28
29
impl AsRef < Tool > for Operation {
29
30
fn as_ref ( & self ) -> & Tool {
@@ -99,9 +100,23 @@ impl Operation {
99
100
) ) ;
100
101
} ;
101
102
103
+ let tool = Tool :: new ( operation_name. clone ( ) , description, schema) ;
104
+ let character_count = tool_character_length ( & tool) ;
105
+ match character_count {
106
+ Ok ( length) => tracing:: info!(
107
+ "Tool {} loaded with a character count of {}" ,
108
+ operation_name,
109
+ length
110
+ ) ,
111
+ Err ( _) => tracing:: info!(
112
+ "Tool {} loaded with an unknown character count" ,
113
+ operation_name
114
+ ) ,
115
+ }
102
116
Ok ( Operation {
103
- tool : Tool :: new ( operation_name , description , schema ) ,
117
+ tool,
104
118
source_text : source_text. to_string ( ) ,
119
+ character_count : character_count. unwrap_or_default ( ) ,
105
120
} )
106
121
}
107
122
@@ -225,6 +240,15 @@ impl Operation {
225
240
226
241
lines. join ( "\n " )
227
242
}
243
+
244
+ pub fn tool_character_length ( & self ) -> usize {
245
+ self . character_count
246
+ }
247
+ }
248
+
249
+ fn tool_character_length ( tool : & Tool ) -> Result < usize , serde_json:: Error > {
250
+ let tool_schema_string = serde_json:: to_string_pretty ( & serde_json:: json!( tool. input_schema) ) ?;
251
+ Ok ( tool. name . len ( ) + tool. description . len ( ) + tool_schema_string. len ( ) )
228
252
}
229
253
230
254
fn get_json_schema (
0 commit comments