Class: Vapi::ToolMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/vapi_server_sdk/types/tool_message.rb

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role:, content:, tool_call_id:, name: OMIT, additional_properties: nil) ⇒ Vapi::ToolMessage

Parameters:

  • role (String)

    This is the role of the message author

  • content (String)

    This is the content of the tool message

  • tool_call_id (String)

    This is the ID of the tool call this message is responding to

  • name (String) (defaults to: OMIT)

    This is an optional name for the participant

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



30
31
32
33
34
35
36
37
38
39
# File 'lib/vapi_server_sdk/types/tool_message.rb', line 30

def initialize(role:, content:, tool_call_id:, name: OMIT, additional_properties: nil)
  @role = role
  @content = content
  @tool_call_id = tool_call_id
  @name = name if name != OMIT
  @additional_properties = additional_properties
  @_field_set = { "role": role, "content": content, "tool_call_id": tool_call_id, "name": name }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



17
18
19
# File 'lib/vapi_server_sdk/types/tool_message.rb', line 17

def additional_properties
  @additional_properties
end

#contentString (readonly)

Returns This is the content of the tool message.

Returns:

  • (String)

    This is the content of the tool message



11
12
13
# File 'lib/vapi_server_sdk/types/tool_message.rb', line 11

def content
  @content
end

#nameString (readonly)

Returns This is an optional name for the participant.

Returns:

  • (String)

    This is an optional name for the participant



15
16
17
# File 'lib/vapi_server_sdk/types/tool_message.rb', line 15

def name
  @name
end

#roleString (readonly)

Returns This is the role of the message author.

Returns:

  • (String)

    This is the role of the message author



9
10
11
# File 'lib/vapi_server_sdk/types/tool_message.rb', line 9

def role
  @role
end

#tool_call_idString (readonly)

Returns This is the ID of the tool call this message is responding to.

Returns:

  • (String)

    This is the ID of the tool call this message is responding to



13
14
15
# File 'lib/vapi_server_sdk/types/tool_message.rb', line 13

def tool_call_id
  @tool_call_id
end

Class Method Details

.from_json(json_object:) ⇒ Vapi::ToolMessage

Deserialize a JSON object to an instance of ToolMessage

Parameters:

  • json_object (String)

Returns:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vapi_server_sdk/types/tool_message.rb', line 45

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  role = parsed_json["role"]
  content = parsed_json["content"]
  tool_call_id = parsed_json["tool_call_id"]
  name = parsed_json["name"]
  new(
    role: role,
    content: content,
    tool_call_id: tool_call_id,
    name: name,
    additional_properties: struct
  )
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)


74
75
76
77
78
79
# File 'lib/vapi_server_sdk/types/tool_message.rb', line 74

def self.validate_raw(obj:)
  obj.role.is_a?(String) != false || raise("Passed value for field obj.role is not the expected type, validation failed.")
  obj.content.is_a?(String) != false || raise("Passed value for field obj.content is not the expected type, validation failed.")
  obj.tool_call_id.is_a?(String) != false || raise("Passed value for field obj.tool_call_id is not the expected type, validation failed.")
  obj.name&.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of ToolMessage to a JSON object

Returns:

  • (String)


64
65
66
# File 'lib/vapi_server_sdk/types/tool_message.rb', line 64

def to_json(*_args)
  @_field_set&.to_json
end