Class: SmartAgent::Tool
- Inherits:
-
Object
- Object
- SmartAgent::Tool
- Defined in:
- lib/smart_agent/tool.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#tool_proc ⇒ Object
Returns the value of attribute tool_proc.
Class Method Summary collapse
Instance Method Summary collapse
- #call(params) ⇒ Object
-
#initialize(name) ⇒ Tool
constructor
A new instance of Tool.
- #to_json ⇒ Object
Constructor Details
#initialize(name) ⇒ Tool
Returns a new instance of Tool.
5 6 7 8 9 |
# File 'lib/smart_agent/tool.rb', line 5 def initialize(name) SmartAgent.logger.info "Create tool's name is #{name}" @name = name @context = ToolContext.new(self) end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
3 4 5 |
# File 'lib/smart_agent/tool.rb', line 3 def context @context end |
#tool_proc ⇒ Object
Returns the value of attribute tool_proc.
3 4 5 |
# File 'lib/smart_agent/tool.rb', line 3 def tool_proc @tool_proc end |
Class Method Details
.define(name, &block) ⇒ Object
44 45 46 47 48 |
# File 'lib/smart_agent/tool.rb', line 44 def define(name, &block) tool = Tool.new(name) tools[name] = tool tool.context.instance_eval(&block) end |
.find_tool(name) ⇒ Object
50 51 52 |
# File 'lib/smart_agent/tool.rb', line 50 def find_tool(name) tools[name] end |
.tools ⇒ Object
40 41 42 |
# File 'lib/smart_agent/tool.rb', line 40 def tools @tools ||= {} end |
Instance Method Details
#call(params) ⇒ Object
11 12 13 14 |
# File 'lib/smart_agent/tool.rb', line 11 def call(params) @context.input_params = params @context.instance_eval(&@context.proc) end |
#to_json ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/smart_agent/tool.rb', line 16 def to_json params = @context.params properties = params.each_with_object({}) do |(name, details), hash| hash[name] = { type: details[:type], description: details[:description], } end return { type: "function", function: { name: @name, description: @context.description, parameters: { type: "object", properties: properties, required: params.keys, }, }, } end |