Skip to content

Commit 40acd18

Browse files
committed
remove self in Tool trait
1 parent a630743 commit 40acd18

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

async-openai/src/tools.rs

+11-16
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,29 @@ pub trait Tool: Send + Sync {
2828
type Error: ToString + Send + Sync;
2929

3030
/// Returns the name of the tool.
31-
fn name(&self) -> String {
31+
fn name() -> String {
3232
Self::Args::schema_name()
3333
}
3434

3535
/// Returns an optional description of the tool.
36-
fn description(&self) -> Option<String> {
36+
fn description() -> Option<String> {
3737
None
3838
}
3939

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-
4540
/// 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> {
4742
None
4843
}
4944

5045
/// Creates a ChatCompletionTool definition for the tool.
51-
fn definition(&self) -> ChatCompletionTool {
46+
fn definition() -> ChatCompletionTool {
5247
ChatCompletionTool {
5348
r#type: ChatCompletionToolType::Function,
5449
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(),
5954
},
6055
}
6156
}
@@ -85,7 +80,7 @@ trait ToolDyn: Send + Sync {
8580
// Implementation of ToolDyn for any type that implements Tool
8681
impl<T: Tool> ToolDyn for T {
8782
fn definition(&self) -> ChatCompletionTool {
88-
T::definition(self)
83+
T::definition()
8984
}
9085

9186
fn call(
@@ -129,8 +124,8 @@ impl ToolManager {
129124
}
130125

131126
/// 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));
134129
}
135130

136131
/// Removes a tool from the manager.

examples/tool-call-stream/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ impl Tool for WeatherTool {
146146
type Output = WeatherResponse;
147147
type Error = String;
148148

149-
fn name(&self) -> String {
149+
fn name() -> String {
150150
"get_current_weather".to_string()
151151
}
152152

153-
fn description(&self) -> Option<String> {
153+
fn description() -> Option<String> {
154154
Some("Get the current weather in a given location".to_string())
155155
}
156156

examples/tool-call/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ impl Tool for WeatherTool {
116116
type Output = WeatherResponse;
117117
type Error = String;
118118

119-
fn name(&self) -> String {
119+
fn name() -> String {
120120
"get_current_weather".to_string()
121121
}
122122

123-
fn description(&self) -> Option<String> {
123+
fn description() -> Option<String> {
124124
Some("Get the current weather in a given location".to_string())
125125
}
126126

0 commit comments

Comments
 (0)