Class: AiClient::Function

Inherits:
Object
  • Object
show all
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

Class Method Details

.call(**params) ⇒ Object

Calls the function with the provided parameters.

Parameters:

  • params (Hash)

    Named parameters required by the function.

Raises:

  • (NotImplementedError)

    if not implemented in the subclass.



21
22
23
# File 'lib/ai_client/function.rb', line 21

def call(**params)
  raise NotImplementedError, "You must implement the call method"
end

.detailsHash

Provides the details about the function including its metadata.

Returns:

  • (Hash)

    Metadata containing details about the function.

Raises:

  • (NotImplementedError)

    if not implemented in the subclass.



30
31
32
# File 'lib/ai_client/function.rb', line 30

def details
  raise NotImplementedError, "You must implement the details method"
end

.disablevoid

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

.functionsArray<Symbol>

Returns a list of enabled functions.

Returns:

  • (Array<Symbol>)

    Sorted list of function names.



64
65
66
# File 'lib/ai_client/function.rb', line 64

def functions
  registry.keys.sort
end

.known_bySymbol

Returns the name under which the function is known.

Returns:

  • (Symbol)

    The symbol representation of the function’s name.



83
84
85
# File 'lib/ai_client/function.rb', line 83

def known_by
  details[:name]
end

.registerObject 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

.registryHash

Returns the registry of currently registered functions. This method is private to limit access to the registry’s state.

Returns:

  • (Hash)

    The registry of registered functions.



74
75
76
# File 'lib/ai_client/function.rb', line 74

def registry
  @@registry
end