Class: AiClient::Function
- Inherits:
-
Object
- Object
- AiClient::Function
- Defined in:
- lib/ai_client/function.rb
Overview
The Function class serves as a base class for creating functions that can be registered and managed within the AiClient.
Subclasses must implement the ‘call` and `details` methods to define their specific behavior and properties.
Constant Summary collapse
- @@registry =
key is known by name (from details) and value is the AiClient::Tool
{}
Class Method Summary collapse
-
.call(**params) ⇒ Object
Calls the function with the provided parameters.
-
.details ⇒ Hash
Provides the details about the function including its metadata.
-
.disable ⇒ void
Disables the function by removing its name from the registry.
-
.functions ⇒ Array<Symbol>
Returns a list of enabled functions.
-
.known_by ⇒ Symbol
Returns the name under which the function is known.
-
.register ⇒ Object
(also: enable)
Registers a tool with the specified properties and parameters.
-
.registry ⇒ Hash
Returns the registry of currently registered functions.
Class Method Details
.call(**params) ⇒ Object
Calls the function with the provided parameters.
21 22 23 |
# File 'lib/ai_client/function.rb', line 21 def call(**params) raise NotImplementedError, "You must implement the call method" end |
.details ⇒ Hash
Provides the details about the function including its metadata.
30 31 32 |
# File 'lib/ai_client/function.rb', line 30 def details raise NotImplementedError, "You must implement the details method" end |
.disable ⇒ void
This method returns an undefined value.
Disables the function by removing its name from the registry.
55 56 57 |
# File 'lib/ai_client/function.rb', line 55 def disable registry.delete(known_by) end |
.functions ⇒ Array<Symbol>
Returns a list of enabled functions.
64 65 66 |
# File 'lib/ai_client/function.rb', line 64 def functions registry.keys.sort end |
.known_by ⇒ Symbol
Returns the name under which the function is known.
83 84 85 |
# File 'lib/ai_client/function.rb', line 83 def known_by details[:name] end |
.register ⇒ Object Also known as: enable
Registers a tool with the specified properties and parameters.
This method creates an instance of AiClient::Tool with the function class and its details and adds it to the registry.
40 41 42 43 44 45 46 47 |
# File 'lib/ai_client/function.rb', line 40 def register this_tool = AiClient::Tool.new( self, # This is the sub-class **details ) registry[known_by] = this_tool end |
.registry ⇒ Hash
Returns the registry of currently registered functions. This method is private to limit access to the registry’s state.
74 75 76 |
# File 'lib/ai_client/function.rb', line 74 def registry @@registry end |