Class: OmniAI::Tool::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/omniai/tool/property.rb

Overview

Usage:

property = OmniAI::Tool::Property.new(type: ‘string’, description: ‘The nth number to calculate.’)

Defined Under Namespace

Modules: Type

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, description: nil, enum: nil) ⇒ OmniAI::Tool::Property

Parameters:

  • description (String) (defaults to: nil)
  • enum (Array<String>) (defaults to: nil)


56
57
58
59
60
# File 'lib/omniai/tool/property.rb', line 56

def initialize(type:, description: nil, enum: nil)
  @type = type
  @description = description
  @enum = enum
end

Instance Attribute Details

#descriptionString? (readonly)

Returns:

  • (String, nil)


20
21
22
# File 'lib/omniai/tool/property.rb', line 20

def description
  @description
end

#enumArray<String>? (readonly)

Returns:

  • (Array<String>, nil)


23
24
25
# File 'lib/omniai/tool/property.rb', line 23

def enum
  @enum
end

#typeString (readonly)

Returns:

  • (String)


17
18
19
# File 'lib/omniai/tool/property.rb', line 17

def type
  @type
end

Class Method Details

.boolean(description: nil, enum: nil) ⇒ OmniAI::Tool::Property

Parameters:

  • description (String) (defaults to: nil)
  • enum (Array<String>) (defaults to: nil)

Returns:



28
29
30
# File 'lib/omniai/tool/property.rb', line 28

def self.boolean(description: nil, enum: nil)
  new(type: Type::BOOLEAN, description:, enum:)
end

.integer(description: nil, enum: nil) ⇒ OmniAI::Tool::Property

Parameters:

  • description (String) (defaults to: nil)
  • enum (Array<String>) (defaults to: nil)

Returns:



35
36
37
# File 'lib/omniai/tool/property.rb', line 35

def self.integer(description: nil, enum: nil)
  new(type: Type::INTEGER, description:, enum:)
end

.number(description: nil, enum: nil) ⇒ OmniAI::Tool::Property

Parameters:

  • description (String) (defaults to: nil)
  • enum (Array<String>) (defaults to: nil)

Returns:



49
50
51
# File 'lib/omniai/tool/property.rb', line 49

def self.number(description: nil, enum: nil)
  new(type: Type::NUMBER, description:, enum:)
end

.string(description: nil, enum: nil) ⇒ OmniAI::Tool::Property

Parameters:

  • description (String) (defaults to: nil)
  • enum (Array<String>) (defaults to: nil)

Returns:



42
43
44
# File 'lib/omniai/tool/property.rb', line 42

def self.string(description: nil, enum: nil)
  new(type: Type::STRING, description:, enum:)
end

Instance Method Details

#parse(value) ⇒ String, ...

Returns:

  • (String, Integer, Float, Boolean, Object)


80
81
82
83
84
85
86
87
# File 'lib/omniai/tool/property.rb', line 80

def parse(value)
  case @type
  when Type::INTEGER then Integer(value)
  when Type::STRING then String(value)
  when Type::NUMBER then Float(value)
  else value
  end
end

#serializeHash

Examples:

property.serialize
# {
#   type: 'string',
#   description: 'The unit (e.g. "fahrenheit" or "celsius").'
#   enum: %w[fahrenheit celsius]
# }

Returns:

  • (Hash)


71
72
73
74
75
76
77
# File 'lib/omniai/tool/property.rb', line 71

def serialize
  {
    type: @type,
    description: @description,
    enum: @enum,
  }.compact
end