Module: OxAiWorkers::ToolDefinition

Included in:
Iterator, OxAiWorkers::Tool::Database, OxAiWorkers::Tool::Eval, OxAiWorkers::Tool::FileSystem
Defined in:
lib/oxaiworkers/tool_definition.rb

Defined Under Namespace

Classes: FunctionSchemas, ParameterBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#white_listObject

Returns the value of attribute white_list.



41
42
43
# File 'lib/oxaiworkers/tool_definition.rb', line 41

def white_list
  @white_list
end

Instance Method Details

#define_function(method_name, description:) { ... } ⇒ Object

Defines a function for the tool

Parameters:

  • method_name (Symbol)

    Name of the method to define

  • description (String)

    Description of the function

Yields:

  • Block that defines the parameters for the function



56
57
58
59
60
# File 'lib/oxaiworkers/tool_definition.rb', line 56

def define_function(method_name, description:, &)
  return unless @white_list.nil? || @white_list == method_name || @white_list.include?(method_name)

  function_schemas.add_function(method_name:, description:, &)
end

#full_function_name(fun) ⇒ String

Returns the full function name for the given function.

Parameters:

  • fun (Symbol)

    The function name.

Returns:

  • (String)

    The full function name, which is the tool name concatenated with the function name.



83
84
85
# File 'lib/oxaiworkers/tool_definition.rb', line 83

def full_function_name(fun)
  function_schemas.function_name(fun)
end

#function_schemasFunctionSchemas

Returns the FunctionSchemas instance for this tool

Returns:



65
66
67
# File 'lib/oxaiworkers/tool_definition.rb', line 65

def function_schemas
  @function_schemas ||= FunctionSchemas.new(tool_name)
end

#init_white_list_with(only) ⇒ Array

Initializes the white list with the given ‘only` parameter.

Parameters:

  • only (Object, Array)

    The object or array to initialize the white list with.

Returns:

  • (Array)

    The initialized white list.



47
48
49
# File 'lib/oxaiworkers/tool_definition.rb', line 47

def init_white_list_with(only)
  @white_list = only.is_a?(Array) || only.nil? ? only : [only]
end

#tool_nameString

Returns the snake_case version of the class name as the tool’s name

Returns:

  • (String)

    The snake_case version of the class name



72
73
74
75
76
77
# File 'lib/oxaiworkers/tool_definition.rb', line 72

def tool_name
  @tool_name ||= (respond_to?(:name) ? name : self.class.name)
                 .gsub('::', '_')
                 .gsub(/(?<=[A-Z])(?=[A-Z][a-z])|(?<=[a-z\d])(?=[A-Z])/, '_')
                 .downcase
end