Class: Vapi::Chat

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, org_id:, created_at:, updated_at:, assistant_id: OMIT, assistant: OMIT, assistant_overrides: OMIT, name: OMIT, session_id: OMIT, input: OMIT, stream: OMIT, previous_chat_id: OMIT, messages: OMIT, output: OMIT, costs: OMIT, cost: OMIT, additional_properties: nil) ⇒ Vapi::Chat

Parameters:

  • assistant_id (String) (defaults to: OMIT)

    This is the assistant that will be used for the chat. To use an existing assistant, use ‘assistantId` instead.

  • assistant (Vapi::CreateAssistantDto) (defaults to: OMIT)

    This is the assistant that will be used for the chat. To use an existing assistant, use ‘assistantId` instead.

  • assistant_overrides (Vapi::AssistantOverrides) (defaults to: OMIT)

    These are the variable values that will be used to replace template variables in the assistant messages. Only variable substitution is supported in chat contexts - other assistant properties cannot be overridden.

  • name (String) (defaults to: OMIT)

    This is the name of the chat. This is just for your own reference.

  • session_id (String) (defaults to: OMIT)

    This is the ID of the session that will be used for the chat. Mutually exclusive with previousChatId.

  • input (Vapi::ChatInput) (defaults to: OMIT)

    This is the input text for the chat. Can be a string or an array of chat messages.

  • stream (Boolean) (defaults to: OMIT)

    This is a flag that determines whether the response should be streamed. When true, the response will be sent as chunks of text.

  • previous_chat_id (String) (defaults to: OMIT)

    This is the ID of the chat that will be used as context for the new chat. The messages from the previous chat will be used as context. Mutually exclusive with sessionId.

  • id (String)

    This is the unique identifier for the chat.

  • org_id (String)

    This is the unique identifier for the org that this chat belongs to.

  • messages (Array<Vapi::ChatMessagesItem>) (defaults to: OMIT)

    This is an array of messages used as context for the chat. Used to provide message history for multi-turn conversations.

  • output (Array<Vapi::ChatOutputItem>) (defaults to: OMIT)

    This is the output messages generated by the system in response to the input.

  • created_at (DateTime)

    This is the ISO 8601 date-time string of when the chat was created.

  • updated_at (DateTime)

    This is the ISO 8601 date-time string of when the chat was last updated.

  • costs (Array<Vapi::ChatCostsItem>) (defaults to: OMIT)

    These are the costs of individual components of the chat in USD.

  • cost (Float) (defaults to: OMIT)

    This is the cost of the chat in USD.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/vapi_server_sdk/types/chat.rb', line 95

def initialize(id:, org_id:, created_at:, updated_at:, assistant_id: OMIT, assistant: OMIT, assistant_overrides: OMIT, name: OMIT, session_id: OMIT,
               input: OMIT, stream: OMIT, previous_chat_id: OMIT, messages: OMIT, output: OMIT, costs: OMIT, cost: OMIT, additional_properties: nil)
  @assistant_id = assistant_id if assistant_id != OMIT
  @assistant = assistant if assistant != OMIT
  @assistant_overrides = assistant_overrides if assistant_overrides != OMIT
  @name = name if name != OMIT
  @session_id = session_id if session_id != OMIT
  @input = input if input != OMIT
  @stream = stream if stream != OMIT
  @previous_chat_id = previous_chat_id if previous_chat_id != OMIT
  @id = id
  @org_id = org_id
  @messages = messages if messages != OMIT
  @output = output if output != OMIT
  @created_at = created_at
  @updated_at = updated_at
  @costs = costs if costs != OMIT
  @cost = cost if cost != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "assistantId": assistant_id,
    "assistant": assistant,
    "assistantOverrides": assistant_overrides,
    "name": name,
    "sessionId": session_id,
    "input": input,
    "stream": stream,
    "previousChatId": previous_chat_id,
    "id": id,
    "orgId": org_id,
    "messages": messages,
    "output": output,
    "createdAt": created_at,
    "updatedAt": updated_at,
    "costs": costs,
    "cost": cost
  }.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



59
60
61
# File 'lib/vapi_server_sdk/types/chat.rb', line 59

def additional_properties
  @additional_properties
end

#assistantVapi::CreateAssistantDto (readonly)

Returns This is the assistant that will be used for the chat. To use an existing assistant, use ‘assistantId` instead.

Returns:

  • (Vapi::CreateAssistantDto)

    This is the assistant that will be used for the chat. To use an existing assistant, use ‘assistantId` instead.



20
21
22
# File 'lib/vapi_server_sdk/types/chat.rb', line 20

def assistant
  @assistant
end

#assistant_idString (readonly)

Returns This is the assistant that will be used for the chat. To use an existing assistant, use ‘assistantId` instead.

Returns:

  • (String)

    This is the assistant that will be used for the chat. To use an existing assistant, use ‘assistantId` instead.



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

def assistant_id
  @assistant_id
end

#assistant_overridesVapi::AssistantOverrides (readonly)

Returns These are the variable values that will be used to replace template variables in the assistant messages. Only variable substitution is supported in chat contexts - other assistant properties cannot be overridden.

Returns:

  • (Vapi::AssistantOverrides)

    These are the variable values that will be used to replace template variables in the assistant messages. Only variable substitution is supported in chat contexts - other assistant properties cannot be overridden.



25
26
27
# File 'lib/vapi_server_sdk/types/chat.rb', line 25

def assistant_overrides
  @assistant_overrides
end

#costFloat (readonly)

Returns This is the cost of the chat in USD.

Returns:

  • (Float)

    This is the cost of the chat in USD.



57
58
59
# File 'lib/vapi_server_sdk/types/chat.rb', line 57

def cost
  @cost
end

#costsArray<Vapi::ChatCostsItem> (readonly)

Returns These are the costs of individual components of the chat in USD.

Returns:

  • (Array<Vapi::ChatCostsItem>)

    These are the costs of individual components of the chat in USD.



55
56
57
# File 'lib/vapi_server_sdk/types/chat.rb', line 55

def costs
  @costs
end

#created_atDateTime (readonly)

Returns This is the ISO 8601 date-time string of when the chat was created.

Returns:

  • (DateTime)

    This is the ISO 8601 date-time string of when the chat was created.



51
52
53
# File 'lib/vapi_server_sdk/types/chat.rb', line 51

def created_at
  @created_at
end

#idString (readonly)

Returns This is the unique identifier for the chat.

Returns:

  • (String)

    This is the unique identifier for the chat.



42
43
44
# File 'lib/vapi_server_sdk/types/chat.rb', line 42

def id
  @id
end

#inputVapi::ChatInput (readonly)

Returns This is the input text for the chat. Can be a string or an array of chat messages.

Returns:

  • (Vapi::ChatInput)

    This is the input text for the chat. Can be a string or an array of chat messages.



33
34
35
# File 'lib/vapi_server_sdk/types/chat.rb', line 33

def input
  @input
end

#messagesArray<Vapi::ChatMessagesItem> (readonly)

Returns This is an array of messages used as context for the chat. Used to provide message history for multi-turn conversations.

Returns:

  • (Array<Vapi::ChatMessagesItem>)

    This is an array of messages used as context for the chat. Used to provide message history for multi-turn conversations.



47
48
49
# File 'lib/vapi_server_sdk/types/chat.rb', line 47

def messages
  @messages
end

#nameString (readonly)

Returns This is the name of the chat. This is just for your own reference.

Returns:

  • (String)

    This is the name of the chat. This is just for your own reference.



27
28
29
# File 'lib/vapi_server_sdk/types/chat.rb', line 27

def name
  @name
end

#org_idString (readonly)

Returns This is the unique identifier for the org that this chat belongs to.

Returns:

  • (String)

    This is the unique identifier for the org that this chat belongs to.



44
45
46
# File 'lib/vapi_server_sdk/types/chat.rb', line 44

def org_id
  @org_id
end

#outputArray<Vapi::ChatOutputItem> (readonly)

Returns This is the output messages generated by the system in response to the input.

Returns:

  • (Array<Vapi::ChatOutputItem>)

    This is the output messages generated by the system in response to the input.



49
50
51
# File 'lib/vapi_server_sdk/types/chat.rb', line 49

def output
  @output
end

#previous_chat_idString (readonly)

Returns This is the ID of the chat that will be used as context for the new chat. The messages from the previous chat will be used as context. Mutually exclusive with sessionId.

Returns:

  • (String)

    This is the ID of the chat that will be used as context for the new chat. The messages from the previous chat will be used as context. Mutually exclusive with sessionId.



40
41
42
# File 'lib/vapi_server_sdk/types/chat.rb', line 40

def previous_chat_id
  @previous_chat_id
end

#session_idString (readonly)

Returns This is the ID of the session that will be used for the chat. Mutually exclusive with previousChatId.

Returns:

  • (String)

    This is the ID of the session that will be used for the chat. Mutually exclusive with previousChatId.



30
31
32
# File 'lib/vapi_server_sdk/types/chat.rb', line 30

def session_id
  @session_id
end

#streamBoolean (readonly)

Returns This is a flag that determines whether the response should be streamed. When true, the response will be sent as chunks of text.

Returns:

  • (Boolean)

    This is a flag that determines whether the response should be streamed. When true, the response will be sent as chunks of text.



36
37
38
# File 'lib/vapi_server_sdk/types/chat.rb', line 36

def stream
  @stream
end

#updated_atDateTime (readonly)

Returns This is the ISO 8601 date-time string of when the chat was last updated.

Returns:

  • (DateTime)

    This is the ISO 8601 date-time string of when the chat was last updated.



53
54
55
# File 'lib/vapi_server_sdk/types/chat.rb', line 53

def updated_at
  @updated_at
end

Class Method Details

.from_json(json_object:) ⇒ Vapi::Chat

Deserialize a JSON object to an instance of Chat

Parameters:

  • json_object (String)

Returns:



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/vapi_server_sdk/types/chat.rb', line 140

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  assistant_id = parsed_json["assistantId"]
  if parsed_json["assistant"].nil?
    assistant = nil
  else
    assistant = parsed_json["assistant"].to_json
    assistant = Vapi::CreateAssistantDto.from_json(json_object: assistant)
  end
  if parsed_json["assistantOverrides"].nil?
    assistant_overrides = nil
  else
    assistant_overrides = parsed_json["assistantOverrides"].to_json
    assistant_overrides = Vapi::AssistantOverrides.from_json(json_object: assistant_overrides)
  end
  name = parsed_json["name"]
  session_id = parsed_json["sessionId"]
  if parsed_json["input"].nil?
    input = nil
  else
    input = parsed_json["input"].to_json
    input = Vapi::ChatInput.from_json(json_object: input)
  end
  stream = parsed_json["stream"]
  previous_chat_id = parsed_json["previousChatId"]
  id = parsed_json["id"]
  org_id = parsed_json["orgId"]
  messages = parsed_json["messages"]&.map do |item|
    item = item.to_json
    Vapi::ChatMessagesItem.from_json(json_object: item)
  end
  output = parsed_json["output"]&.map do |item|
    item = item.to_json
    Vapi::ChatOutputItem.from_json(json_object: item)
  end
  created_at = (DateTime.parse(parsed_json["createdAt"]) unless parsed_json["createdAt"].nil?)
  updated_at = (DateTime.parse(parsed_json["updatedAt"]) unless parsed_json["updatedAt"].nil?)
  costs = parsed_json["costs"]&.map do |item|
    item = item.to_json
    Vapi::ChatCostsItem.from_json(json_object: item)
  end
  cost = parsed_json["cost"]
  new(
    assistant_id: assistant_id,
    assistant: assistant,
    assistant_overrides: assistant_overrides,
    name: name,
    session_id: session_id,
    input: input,
    stream: stream,
    previous_chat_id: previous_chat_id,
    id: id,
    org_id: org_id,
    messages: messages,
    output: output,
    created_at: created_at,
    updated_at: updated_at,
    costs: costs,
    cost: cost,
    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)


217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/vapi_server_sdk/types/chat.rb', line 217

def self.validate_raw(obj:)
  obj.assistant_id&.is_a?(String) != false || raise("Passed value for field obj.assistant_id is not the expected type, validation failed.")
  obj.assistant.nil? || Vapi::CreateAssistantDto.validate_raw(obj: obj.assistant)
  obj.assistant_overrides.nil? || Vapi::AssistantOverrides.validate_raw(obj: obj.assistant_overrides)
  obj.name&.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
  obj.session_id&.is_a?(String) != false || raise("Passed value for field obj.session_id is not the expected type, validation failed.")
  obj.input.nil? || Vapi::ChatInput.validate_raw(obj: obj.input)
  obj.stream&.is_a?(Boolean) != false || raise("Passed value for field obj.stream is not the expected type, validation failed.")
  obj.previous_chat_id&.is_a?(String) != false || raise("Passed value for field obj.previous_chat_id is not the expected type, validation failed.")
  obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
  obj.org_id.is_a?(String) != false || raise("Passed value for field obj.org_id is not the expected type, validation failed.")
  obj.messages&.is_a?(Array) != false || raise("Passed value for field obj.messages is not the expected type, validation failed.")
  obj.output&.is_a?(Array) != false || raise("Passed value for field obj.output is not the expected type, validation failed.")
  obj.created_at.is_a?(DateTime) != false || raise("Passed value for field obj.created_at is not the expected type, validation failed.")
  obj.updated_at.is_a?(DateTime) != false || raise("Passed value for field obj.updated_at is not the expected type, validation failed.")
  obj.costs&.is_a?(Array) != false || raise("Passed value for field obj.costs is not the expected type, validation failed.")
  obj.cost&.is_a?(Float) != false || raise("Passed value for field obj.cost is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of Chat to a JSON object

Returns:

  • (String)


207
208
209
# File 'lib/vapi_server_sdk/types/chat.rb', line 207

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