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
-
#white_list ⇒ Object
Returns the value of attribute white_list.
Instance Method Summary collapse
-
#define_function(method_name, description:) { ... } ⇒ Object
Defines a function for the tool.
-
#full_function_name(fun) ⇒ String
Returns the full function name for the given function.
-
#function_schemas ⇒ FunctionSchemas
Returns the FunctionSchemas instance for this tool.
-
#init_white_list_with(only) ⇒ Array
Initializes the white list with the given ‘only` parameter.
-
#tool_name ⇒ String
Returns the snake_case version of the class name as the tool’s name.
Instance Attribute Details
#white_list ⇒ Object
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
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.
83 84 85 |
# File 'lib/oxaiworkers/tool_definition.rb', line 83 def full_function_name(fun) function_schemas.function_name(fun) end |
#function_schemas ⇒ FunctionSchemas
Returns the FunctionSchemas instance for this tool
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.
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_name ⇒ String
Returns the snake_case version of the class name as the tool’s 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 |