Class: Helicone::Tool
- Inherits:
-
Object
- Object
- Helicone::Tool
- Defined in:
- lib/helicone/tool.rb
Class Attribute Summary collapse
-
.tool_description ⇒ Object
readonly
Returns the value of attribute tool_description.
-
.tool_parameters ⇒ Object
readonly
Returns the value of attribute tool_parameters.
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Class Method Summary collapse
-
.description(text) ⇒ void
Set the tool description.
-
.function_name ⇒ String
Generate the function name from class name.
- .inherited(subclass) ⇒ Object
-
.parameters(schema) ⇒ void
Set the tool parameters schema.
-
.to_openai_tool ⇒ Hash
Generate OpenAI tool definition.
-
.tool_name(custom_name = nil) ⇒ String
Get or set a custom tool name.
Instance Method Summary collapse
-
#execute(**args) ⇒ Hash
Execute the tool with the given arguments.
-
#function_name ⇒ String
Delegate to class method for instances.
-
#initialize(context = nil) ⇒ Tool
constructor
Initialize a tool instance.
-
#to_openai_tool ⇒ Hash
Delegate to class method for instances.
Constructor Details
#initialize(context = nil) ⇒ Tool
Initialize a tool instance
90 91 92 |
# File 'lib/helicone/tool.rb', line 90 def initialize(context = nil) @context = context end |
Class Attribute Details
.tool_description ⇒ Object (readonly)
Returns the value of attribute tool_description.
6 7 8 |
# File 'lib/helicone/tool.rb', line 6 def tool_description @tool_description end |
.tool_parameters ⇒ Object (readonly)
Returns the value of attribute tool_parameters.
6 7 8 |
# File 'lib/helicone/tool.rb', line 6 def tool_parameters @tool_parameters end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
85 86 87 |
# File 'lib/helicone/tool.rb', line 85 def context @context end |
Class Method Details
.description(text) ⇒ void
This method returns an undefined value.
Set the tool description
19 20 21 |
# File 'lib/helicone/tool.rb', line 19 def description(text) @tool_description = text.strip end |
.function_name ⇒ String
Generate the function name from class name
46 47 48 |
# File 'lib/helicone/tool.rb', line 46 def function_name @tool_name || derive_function_name end |
.inherited(subclass) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/helicone/tool.rb', line 8 def inherited(subclass) super # Ensure subclasses get their own class instance variables subclass.instance_variable_set(:@tool_description, nil) subclass.instance_variable_set(:@tool_parameters, nil) end |
.parameters(schema) ⇒ void
This method returns an undefined value.
Set the tool parameters schema
27 28 29 |
# File 'lib/helicone/tool.rb', line 27 def parameters(schema) @tool_parameters = schema end |
.to_openai_tool ⇒ Hash
Generate OpenAI tool definition
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/helicone/tool.rb', line 53 def to_openai_tool { type: "function", function: { name: function_name, description: tool_description, parameters: tool_parameters || { type: "object", properties: {}, required: [] } } } end |
.tool_name(custom_name = nil) ⇒ String
Get or set a custom tool name
35 36 37 38 39 40 41 |
# File 'lib/helicone/tool.rb', line 35 def tool_name(custom_name = nil) if custom_name @tool_name = custom_name else @tool_name || derive_function_name end end |
Instance Method Details
#execute(**args) ⇒ Hash
Execute the tool with the given arguments
98 99 100 |
# File 'lib/helicone/tool.rb', line 98 def execute(**args) raise NotImplementedError, "Subclasses must implement #execute" end |
#function_name ⇒ String
Delegate to class method for instances
112 113 114 |
# File 'lib/helicone/tool.rb', line 112 def function_name self.class.function_name end |
#to_openai_tool ⇒ Hash
Delegate to class method for instances
105 106 107 |
# File 'lib/helicone/tool.rb', line 105 def to_openai_tool self.class.to_openai_tool end |