Class: Vellum::NodeInputVariableCompiledValue

Inherits:
Object
  • Object
show all
Defined in:
lib/vellum_ai/types/node_input_variable_compiled_value.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(member:, discriminant:) ⇒ NodeInputVariableCompiledValue

Parameters:

  • member (Object)
  • discriminant (String)


21
22
23
24
25
26
# File 'lib/vellum_ai/types/node_input_variable_compiled_value.rb', line 21

def initialize(member:, discriminant:)
  # @type [Object]
  @member = member
  # @type [String]
  @discriminant = discriminant
end

Instance Attribute Details

#discriminantObject (readonly)

Returns the value of attribute discriminant.



14
15
16
# File 'lib/vellum_ai/types/node_input_variable_compiled_value.rb', line 14

def discriminant
  @discriminant
end

#memberObject (readonly)

Returns the value of attribute member.



14
15
16
# File 'lib/vellum_ai/types/node_input_variable_compiled_value.rb', line 14

def member
  @member
end

Class Method Details

.array(member:) ⇒ NodeInputVariableCompiledValue



151
152
153
# File 'lib/vellum_ai/types/node_input_variable_compiled_value.rb', line 151

def self.array(member:)
  new(member: member, discriminant: "ARRAY")
end

.chat_history(member:) ⇒ NodeInputVariableCompiledValue



133
134
135
# File 'lib/vellum_ai/types/node_input_variable_compiled_value.rb', line 133

def self.chat_history(member:)
  new(member: member, discriminant: "CHAT_HISTORY")
end

.error(member:) ⇒ NodeInputVariableCompiledValue



145
146
147
# File 'lib/vellum_ai/types/node_input_variable_compiled_value.rb', line 145

def self.error(member:)
  new(member: member, discriminant: "ERROR")
end

.from_json(json_object:) ⇒ NodeInputVariableCompiledValue

Deserialize a JSON object to an instance of NodeInputVariableCompiledValue

Parameters:

  • json_object (JSON)

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/vellum_ai/types/node_input_variable_compiled_value.rb', line 32

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  member = case struct.type
           when "STRING"
             NodeInputCompiledStringValue.from_json(json_object: json_object)
           when "NUMBER"
             NodeInputCompiledNumberValue.from_json(json_object: json_object)
           when "JSON"
             NodeInputCompiledJsonValue.from_json(json_object: json_object)
           when "CHAT_HISTORY"
             NodeInputCompiledChatHistoryValue.from_json(json_object: json_object)
           when "SEARCH_RESULTS"
             NodeInputCompiledSearchResultsValue.from_json(json_object: json_object)
           when "ERROR"
             NodeInputCompiledErrorValue.from_json(json_object: json_object)
           when "ARRAY"
             NodeInputCompiledArrayValue.from_json(json_object: json_object)
           else
             NodeInputCompiledStringValue.from_json(json_object: json_object)
           end
  new(member: member, discriminant: struct.type)
end

.json(member:) ⇒ NodeInputVariableCompiledValue



127
128
129
# File 'lib/vellum_ai/types/node_input_variable_compiled_value.rb', line 127

def self.json(member:)
  new(member: member, discriminant: "JSON")
end

.number(member:) ⇒ NodeInputVariableCompiledValue



121
122
123
# File 'lib/vellum_ai/types/node_input_variable_compiled_value.rb', line 121

def self.number(member:)
  new(member: member, discriminant: "NUMBER")
end

.search_results(member:) ⇒ NodeInputVariableCompiledValue



139
140
141
# File 'lib/vellum_ai/types/node_input_variable_compiled_value.rb', line 139

def self.search_results(member:)
  new(member: member, discriminant: "SEARCH_RESULTS")
end

.string(member:) ⇒ NodeInputVariableCompiledValue



115
116
117
# File 'lib/vellum_ai/types/node_input_variable_compiled_value.rb', line 115

def self.string(member:)
  new(member: member, discriminant: "STRING")
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.

Parameters:

  • obj (Object)

Returns:

  • (Void)


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/vellum_ai/types/node_input_variable_compiled_value.rb', line 84

def self.validate_raw(obj:)
  case obj.type
  when "STRING"
    NodeInputCompiledStringValue.validate_raw(obj: obj)
  when "NUMBER"
    NodeInputCompiledNumberValue.validate_raw(obj: obj)
  when "JSON"
    NodeInputCompiledJsonValue.validate_raw(obj: obj)
  when "CHAT_HISTORY"
    NodeInputCompiledChatHistoryValue.validate_raw(obj: obj)
  when "SEARCH_RESULTS"
    NodeInputCompiledSearchResultsValue.validate_raw(obj: obj)
  when "ERROR"
    NodeInputCompiledErrorValue.validate_raw(obj: obj)
  when "ARRAY"
    NodeInputCompiledArrayValue.validate_raw(obj: obj)
  else
    raise("Passed value matched no type within the union, validation failed.")
  end
end

Instance Method Details

#is_a?(obj) ⇒ Boolean

For Union Types, is_a? functionality is delegated to the wrapped member.

Parameters:

  • obj (Object)

Returns:

  • (Boolean)


109
110
111
# File 'lib/vellum_ai/types/node_input_variable_compiled_value.rb', line 109

def is_a?(obj)
  @member.is_a?(obj)
end

#kind_of?Object



17
# File 'lib/vellum_ai/types/node_input_variable_compiled_value.rb', line 17

alias kind_of? is_a?

#to_json(*_args) ⇒ JSON

For Union Types, to_json functionality is delegated to the wrapped member.

Returns:

  • (JSON)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/vellum_ai/types/node_input_variable_compiled_value.rb', line 58

def to_json(*_args)
  case @discriminant
  when "STRING"
    { **@member.to_json, type: @discriminant }.to_json
  when "NUMBER"
    { **@member.to_json, type: @discriminant }.to_json
  when "JSON"
    { **@member.to_json, type: @discriminant }.to_json
  when "CHAT_HISTORY"
    { **@member.to_json, type: @discriminant }.to_json
  when "SEARCH_RESULTS"
    { **@member.to_json, type: @discriminant }.to_json
  when "ERROR"
    { **@member.to_json, type: @discriminant }.to_json
  when "ARRAY"
    { **@member.to_json, type: @discriminant }.to_json
  else
    { "type": @discriminant, value: @member }.to_json
  end
  @member.to_json
end