Class: Kward::Tools::PluginTool
- Defined in:
- lib/kward/tools/plugin_tool.rb
Overview
Adapts a trusted plugin tool registration to the normal tool interface.
Instance Attribute Summary collapse
-
#plugin_path ⇒ Object
readonly
Returns the value of attribute plugin_path.
Attributes inherited from Base
Instance Method Summary collapse
-
#call(args, conversation, cancellation: nil) ⇒ Object
Executes trusted plugin code with parsed model arguments and scoped context.
-
#initialize(registration:, context_factory:) ⇒ PluginTool
constructor
A new instance of PluginTool.
-
#schema ⇒ Object
Returns the strict JSON schema declared by the plugin.
Constructor Details
#initialize(registration:, context_factory:) ⇒ PluginTool
Returns a new instance of PluginTool.
11 12 13 14 15 16 17 18 |
# File 'lib/kward/tools/plugin_tool.rb', line 11 def initialize(registration:, context_factory:) @description = registration.description @parameters = registration.schema @plugin_path = registration.path @handler = registration.handler @context_factory = context_factory super(registration.name, registration.description) end |
Instance Attribute Details
#plugin_path ⇒ Object (readonly)
Returns the value of attribute plugin_path.
9 10 11 |
# File 'lib/kward/tools/plugin_tool.rb', line 9 def plugin_path @plugin_path end |
Instance Method Details
#call(args, conversation, cancellation: nil) ⇒ Object
Executes trusted plugin code with parsed model arguments and scoped context.
33 34 35 36 37 38 |
# File 'lib/kward/tools/plugin_tool.rb', line 33 def call(args, conversation, cancellation: nil) context = @context_factory.call(conversation, cancellation) result = @handler.call(args, context) cancellation&.raise_if_cancelled! result.to_s end |
#schema ⇒ Object
Returns the strict JSON schema declared by the plugin.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/kward/tools/plugin_tool.rb', line 21 def schema { type: "function", function: { name: name, description: @description, parameters: @parameters } } end |