Class: Vellum::WorkflowOutput

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(member:, discriminant:) ⇒ WorkflowOutput

Parameters:

  • member (Object)
  • discriminant (String)


23
24
25
26
27
28
# File 'lib/vellum_ai/types/workflow_output.rb', line 23

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

Instance Attribute Details

#discriminantObject (readonly)

Returns the value of attribute discriminant.



16
17
18
# File 'lib/vellum_ai/types/workflow_output.rb', line 16

def discriminant
  @discriminant
end

#memberObject (readonly)

Returns the value of attribute member.



16
17
18
# File 'lib/vellum_ai/types/workflow_output.rb', line 16

def member
  @member
end

Class Method Details

.array(member:) ⇒ WorkflowOutput

Parameters:

Returns:



159
160
161
# File 'lib/vellum_ai/types/workflow_output.rb', line 159

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

.chat_history(member:) ⇒ WorkflowOutput

Parameters:

Returns:



147
148
149
# File 'lib/vellum_ai/types/workflow_output.rb', line 147

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

.error(member:) ⇒ WorkflowOutput

Parameters:

Returns:



165
166
167
# File 'lib/vellum_ai/types/workflow_output.rb', line 165

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

.from_json(json_object:) ⇒ WorkflowOutput

Deserialize a JSON object to an instance of WorkflowOutput

Parameters:

  • json_object (JSON)

Returns:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vellum_ai/types/workflow_output.rb', line 34

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  member = case struct.type
           when "STRING"
             WorkflowOutputString.from_json(json_object: json_object)
           when "NUMBER"
             WorkflowOutputNumber.from_json(json_object: json_object)
           when "JSON"
             WorkflowOutputJson.from_json(json_object: json_object)
           when "CHAT_HISTORY"
             WorkflowOutputChatHistory.from_json(json_object: json_object)
           when "SEARCH_RESULTS"
             WorkflowOutputSearchResults.from_json(json_object: json_object)
           when "ARRAY"
             WorkflowOutputArray.from_json(json_object: json_object)
           when "ERROR"
             WorkflowOutputError.from_json(json_object: json_object)
           when "FUNCTION_CALL"
             WorkflowOutputFunctionCall.from_json(json_object: json_object)
           when "IMAGE"
             WorkflowOutputImage.from_json(json_object: json_object)
           else
             WorkflowOutputString.from_json(json_object: json_object)
           end
  new(member: member, discriminant: struct.type)
end

.function_call(member:) ⇒ WorkflowOutput

Parameters:

Returns:



171
172
173
# File 'lib/vellum_ai/types/workflow_output.rb', line 171

def self.function_call(member:)
  new(member: member, discriminant: "FUNCTION_CALL")
end

.image(member:) ⇒ WorkflowOutput

Parameters:

Returns:



177
178
179
# File 'lib/vellum_ai/types/workflow_output.rb', line 177

def self.image(member:)
  new(member: member, discriminant: "IMAGE")
end

.json(member:) ⇒ WorkflowOutput

Parameters:

Returns:



141
142
143
# File 'lib/vellum_ai/types/workflow_output.rb', line 141

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

.number(member:) ⇒ WorkflowOutput

Parameters:

Returns:



135
136
137
# File 'lib/vellum_ai/types/workflow_output.rb', line 135

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

.search_results(member:) ⇒ WorkflowOutput

Parameters:

Returns:



153
154
155
# File 'lib/vellum_ai/types/workflow_output.rb', line 153

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

.string(member:) ⇒ WorkflowOutput

Parameters:

Returns:



129
130
131
# File 'lib/vellum_ai/types/workflow_output.rb', line 129

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)


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/vellum_ai/types/workflow_output.rb', line 94

def self.validate_raw(obj:)
  case obj.type
  when "STRING"
    WorkflowOutputString.validate_raw(obj: obj)
  when "NUMBER"
    WorkflowOutputNumber.validate_raw(obj: obj)
  when "JSON"
    WorkflowOutputJson.validate_raw(obj: obj)
  when "CHAT_HISTORY"
    WorkflowOutputChatHistory.validate_raw(obj: obj)
  when "SEARCH_RESULTS"
    WorkflowOutputSearchResults.validate_raw(obj: obj)
  when "ARRAY"
    WorkflowOutputArray.validate_raw(obj: obj)
  when "ERROR"
    WorkflowOutputError.validate_raw(obj: obj)
  when "FUNCTION_CALL"
    WorkflowOutputFunctionCall.validate_raw(obj: obj)
  when "IMAGE"
    WorkflowOutputImage.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)


123
124
125
# File 'lib/vellum_ai/types/workflow_output.rb', line 123

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

#kind_of?Object



19
# File 'lib/vellum_ai/types/workflow_output.rb', line 19

alias kind_of? is_a?

#to_json(*_args) ⇒ JSON

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

Returns:

  • (JSON)


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/vellum_ai/types/workflow_output.rb', line 64

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 "ARRAY"
    { **@member.to_json, type: @discriminant }.to_json
  when "ERROR"
    { **@member.to_json, type: @discriminant }.to_json
  when "FUNCTION_CALL"
    { **@member.to_json, type: @discriminant }.to_json
  when "IMAGE"
    { **@member.to_json, type: @discriminant }.to_json
  else
    { "type": @discriminant, value: @member }.to_json
  end
  @member.to_json
end