@@ -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,16 @@ 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!( " {}: {}" , operation_name, length) ,
107
+ Err ( _) => tracing:: info!( " {}: unknown" , operation_name) ,
108
+ }
102
109
Ok ( Operation {
103
- tool : Tool :: new ( operation_name , description , schema ) ,
110
+ tool,
104
111
source_text : source_text. to_string ( ) ,
112
+ character_count : character_count. unwrap_or_default ( ) ,
105
113
} )
106
114
}
107
115
@@ -225,6 +233,15 @@ impl Operation {
225
233
226
234
lines. join ( "\n " )
227
235
}
236
+
237
+ pub fn tool_character_length ( & self ) -> usize {
238
+ self . character_count
239
+ }
240
+ }
241
+
242
+ fn tool_character_length ( tool : & Tool ) -> Result < usize , serde_json:: Error > {
243
+ let tool_schema_string = serde_json:: to_string_pretty ( & serde_json:: json!( tool. input_schema) ) ?;
244
+ Ok ( tool. name . len ( ) + tool. description . len ( ) + tool_schema_string. len ( ) )
228
245
}
229
246
230
247
fn get_json_schema (
0 commit comments