Class: Vellum::FunctionCall

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(member:, discriminant:) ⇒ FunctionCall

Parameters:

  • member (Object)
  • discriminant (String)


16
17
18
19
20
21
# File 'lib/vellum_ai/types/function_call.rb', line 16

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

Instance Attribute Details

#discriminantObject (readonly)

Returns the value of attribute discriminant.



9
10
11
# File 'lib/vellum_ai/types/function_call.rb', line 9

def discriminant
  @discriminant
end

#memberObject (readonly)

Returns the value of attribute member.



9
10
11
# File 'lib/vellum_ai/types/function_call.rb', line 9

def member
  @member
end

Class Method Details

.from_json(json_object:) ⇒ FunctionCall

Deserialize a JSON object to an instance of FunctionCall

Parameters:

  • json_object (JSON)

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/vellum_ai/types/function_call.rb', line 27

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  member = case struct.state
           when "FULFILLED"
             FulfilledFunctionCall.from_json(json_object: json_object)
           when "REJECTED"
             RejectedFunctionCall.from_json(json_object: json_object)
           else
             FulfilledFunctionCall.from_json(json_object: json_object)
           end
  new(member: member, discriminant: struct.state)
end

.fulfilled(member:) ⇒ FunctionCall

Parameters:

Returns:



80
81
82
# File 'lib/vellum_ai/types/function_call.rb', line 80

def self.fulfilled(member:)
  new(member: member, discriminant: "FULFILLED")
end

.rejected(member:) ⇒ FunctionCall

Parameters:

Returns:



86
87
88
# File 'lib/vellum_ai/types/function_call.rb', line 86

def self.rejected(member:)
  new(member: member, discriminant: "REJECTED")
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)


59
60
61
62
63
64
65
66
67
68
# File 'lib/vellum_ai/types/function_call.rb', line 59

def self.validate_raw(obj:)
  case obj.state
  when "FULFILLED"
    FulfilledFunctionCall.validate_raw(obj: obj)
  when "REJECTED"
    RejectedFunctionCall.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)


74
75
76
# File 'lib/vellum_ai/types/function_call.rb', line 74

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

#kind_of?Object



12
# File 'lib/vellum_ai/types/function_call.rb', line 12

alias kind_of? is_a?

#to_json(*_args) ⇒ JSON

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

Returns:

  • (JSON)


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/vellum_ai/types/function_call.rb', line 43

def to_json(*_args)
  case @discriminant
  when "FULFILLED"
    { **@member.to_json, state: @discriminant }.to_json
  when "REJECTED"
    { **@member.to_json, state: @discriminant }.to_json
  else
    { "state": @discriminant, value: @member }.to_json
  end
  @member.to_json
end