@@ -28,34 +28,29 @@ pub trait Tool: Send + Sync {
28
28
type Error : ToString + Send + Sync ;
29
29
30
30
/// Returns the name of the tool.
31
- fn name ( & self ) -> String {
31
+ fn name ( ) -> String {
32
32
Self :: Args :: schema_name ( )
33
33
}
34
34
35
35
/// Returns an optional description of the tool.
36
- fn description ( & self ) -> Option < String > {
36
+ fn description ( ) -> Option < String > {
37
37
None
38
38
}
39
39
40
- /// Returns the JSON schema for the tool's parameters.
41
- fn parameters ( & self ) -> serde_json:: Value {
42
- json ! ( schema_for!( Self :: Args ) )
43
- }
44
-
45
40
/// Returns an optional boolean indicating whether the tool should be strict about the arguments.
46
- fn strict ( & self ) -> Option < bool > {
41
+ fn strict ( ) -> Option < bool > {
47
42
None
48
43
}
49
44
50
45
/// Creates a ChatCompletionTool definition for the tool.
51
- fn definition ( & self ) -> ChatCompletionTool {
46
+ fn definition ( ) -> ChatCompletionTool {
52
47
ChatCompletionTool {
53
48
r#type : ChatCompletionToolType :: Function ,
54
49
function : FunctionObject {
55
- name : self . name ( ) ,
56
- description : self . description ( ) ,
57
- parameters : Some ( self . parameters ( ) ) ,
58
- strict : self . strict ( ) ,
50
+ name : Self :: name ( ) ,
51
+ description : Self :: description ( ) ,
52
+ parameters : Some ( json ! ( schema_for! ( Self :: Args ) ) ) ,
53
+ strict : Self :: strict ( ) ,
59
54
} ,
60
55
}
61
56
}
@@ -85,7 +80,7 @@ trait ToolDyn: Send + Sync {
85
80
// Implementation of ToolDyn for any type that implements Tool
86
81
impl < T : Tool > ToolDyn for T {
87
82
fn definition ( & self ) -> ChatCompletionTool {
88
- T :: definition ( self )
83
+ T :: definition ( )
89
84
}
90
85
91
86
fn call (
@@ -129,8 +124,8 @@ impl ToolManager {
129
124
}
130
125
131
126
/// Adds a new tool to the manager.
132
- pub fn add_tool ( & mut self , tool : impl Tool + ' static ) {
133
- self . tools . insert ( tool . name ( ) , Arc :: new ( tool) ) ;
127
+ pub fn add_tool < T : Tool + ' static > ( & mut self , tool : T ) {
128
+ self . tools . insert ( T :: name ( ) , Arc :: new ( tool) ) ;
134
129
}
135
130
136
131
/// Removes a tool from the manager.
0 commit comments