Class: Vellum::PromptOutput

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(member:, discriminant:) ⇒ PromptOutput

Parameters:

  • member (Object)
  • discriminant (String)


18
19
20
21
22
23
# File 'lib/vellum_ai/types/prompt_output.rb', line 18

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

Instance Attribute Details

#discriminantObject (readonly)

Returns the value of attribute discriminant.



11
12
13
# File 'lib/vellum_ai/types/prompt_output.rb', line 11

def discriminant
  @discriminant
end

#memberObject (readonly)

Returns the value of attribute member.



11
12
13
# File 'lib/vellum_ai/types/prompt_output.rb', line 11

def member
  @member
end

Class Method Details

.error(member:) ⇒ PromptOutput

Parameters:

Returns:



106
107
108
# File 'lib/vellum_ai/types/prompt_output.rb', line 106

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

.from_json(json_object:) ⇒ PromptOutput

Deserialize a JSON object to an instance of PromptOutput

Parameters:

  • json_object (JSON)

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vellum_ai/types/prompt_output.rb', line 29

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  member = case struct.type
           when "STRING"
             StringVariableValue.from_json(json_object: json_object)
           when "JSON"
             JsonVariableValue.from_json(json_object: json_object)
           when "ERROR"
             ErrorVariableValue.from_json(json_object: json_object)
           when "FUNCTION_CALL"
             FunctionCallVariableValue.from_json(json_object: json_object)
           else
             StringVariableValue.from_json(json_object: json_object)
           end
  new(member: member, discriminant: struct.type)
end

.function_call(member:) ⇒ PromptOutput

Parameters:

Returns:



112
113
114
# File 'lib/vellum_ai/types/prompt_output.rb', line 112

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

.json(member:) ⇒ PromptOutput

Parameters:

Returns:



100
101
102
# File 'lib/vellum_ai/types/prompt_output.rb', line 100

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

.string(member:) ⇒ PromptOutput

Parameters:

Returns:



94
95
96
# File 'lib/vellum_ai/types/prompt_output.rb', line 94

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)


69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/vellum_ai/types/prompt_output.rb', line 69

def self.validate_raw(obj:)
  case obj.type
  when "STRING"
    StringVariableValue.validate_raw(obj: obj)
  when "JSON"
    JsonVariableValue.validate_raw(obj: obj)
  when "ERROR"
    ErrorVariableValue.validate_raw(obj: obj)
  when "FUNCTION_CALL"
    FunctionCallVariableValue.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)


88
89
90
# File 'lib/vellum_ai/types/prompt_output.rb', line 88

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

#kind_of?Object



14
# File 'lib/vellum_ai/types/prompt_output.rb', line 14

alias kind_of? is_a?

#to_json(*_args) ⇒ JSON

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

Returns:

  • (JSON)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/vellum_ai/types/prompt_output.rb', line 49

def to_json(*_args)
  case @discriminant
  when "STRING"
    { **@member.to_json, type: @discriminant }.to_json
  when "JSON"
    { **@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
  else
    { "type": @discriminant, value: @member }.to_json
  end
  @member.to_json
end