Class: Vapi::StructuredDataPlan

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(messages: OMIT, enabled: OMIT, schema: OMIT, timeout_seconds: OMIT, additional_properties: nil) ⇒ Vapi::StructuredDataPlan

Parameters:

  • messages (Array<Hash{String => Object}>) (defaults to: OMIT)

    These are the messages used to generate the structured data. @default: “‘ [ { “role”: “system”, “content”: “You are an expert data extractor. You will be given a transcript of a call. Extract structured data per the JSON Schema. DO NOT return anything except the structured data.\n\nJson Schema:\n{schema}\n\nOnly respond with the JSON.” }, { “role”: “user”, “content”: “Here is the transcript:\n\n{transcript}\n\n” } ]“` You can customize by providing any messages you want. Here are the template variables available:

    • {transcript}: the transcript of the call from call.artifact.transcript-

    {systemPrompt}: the system prompt of the call from ‘assistant.model.messages[type=system].content`- {schema}: the schema of the structured data from structuredDataPlan.schema

  • enabled (Boolean) (defaults to: OMIT)

    This determines whether structured data is generated and stored in call.analysis.structuredData. Defaults to false. Usage:

    • If you want to extract structured data, set this to true and provide a

    schema. @default false

  • schema (Vapi::JsonSchema) (defaults to: OMIT)

    This is the schema of the structured data. The output is stored in call.analysis.structuredData. Complete guide on JSON Schema can be found [here](ajv.js.org/json-schema.html#json-data-type).

  • timeout_seconds (Float) (defaults to: OMIT)

    This is how long the request is tried before giving up. When request times out, call.analysis.structuredData will be empty. Usage:

    • To guarantee the structured data is generated, set this value high. Note, this

    will delay the end of call report in cases where model is slow to respond. @default 5 seconds

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 97

def initialize(messages: OMIT, enabled: OMIT, schema: OMIT, timeout_seconds: OMIT, additional_properties: nil)
  @messages = messages if messages != OMIT
  @enabled = enabled if enabled != OMIT
  @schema = schema if schema != OMIT
  @timeout_seconds = timeout_seconds if timeout_seconds != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "messages": messages,
    "enabled": enabled,
    "schema": schema,
    "timeoutSeconds": timeout_seconds
  }.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



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

def additional_properties
  @additional_properties
end

#enabledBoolean (readonly)

Returns This determines whether structured data is generated and stored in call.analysis.structuredData. Defaults to false. Usage:

  • If you want to extract structured data, set this to true and provide a

schema. @default false.

Returns:

  • (Boolean)

    This determines whether structured data is generated and stored in call.analysis.structuredData. Defaults to false. Usage:

    • If you want to extract structured data, set this to true and provide a

    schema. @default false



37
38
39
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 37

def enabled
  @enabled
end

#messagesArray<Hash{String => Object}> (readonly)

Returns These are the messages used to generate the structured data. @default: “‘ [ { “role”: “system”, “content”: “You are an expert data extractor. You will be given a transcript of a call. Extract structured data per the JSON Schema. DO NOT return anything except the structured data.\n\nJson Schema:\n{schema}\n\nOnly respond with the JSON.” }, { “role”: “user”, “content”: “Here is the transcript:\n\n{transcript}\n\n” } ]“` You can customize by providing any messages you want. Here are the template variables available:

  • {transcript}: the transcript of the call from call.artifact.transcript-

{systemPrompt}: the system prompt of the call from ‘assistant.model.messages[type=system].content`- {schema}: the schema of the structured data from structuredDataPlan.schema.

Returns:

  • (Array<Hash{String => Object}>)

    These are the messages used to generate the structured data. @default: “‘ [ { “role”: “system”, “content”: “You are an expert data extractor. You will be given a transcript of a call. Extract structured data per the JSON Schema. DO NOT return anything except the structured data.\n\nJson Schema:\n{schema}\n\nOnly respond with the JSON.” }, { “role”: “user”, “content”: “Here is the transcript:\n\n{transcript}\n\n” } ]“` You can customize by providing any messages you want. Here are the template variables available:

    • {transcript}: the transcript of the call from call.artifact.transcript-

    {systemPrompt}: the system prompt of the call from ‘assistant.model.messages[type=system].content`- {schema}: the schema of the structured data from structuredDataPlan.schema



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

def messages
  @messages
end

#schemaVapi::JsonSchema (readonly)

Returns This is the schema of the structured data. The output is stored in call.analysis.structuredData. Complete guide on JSON Schema can be found [here](ajv.js.org/json-schema.html#json-data-type).

Returns:



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

def schema
  @schema
end

#timeout_secondsFloat (readonly)

Returns This is how long the request is tried before giving up. When request times out, call.analysis.structuredData will be empty. Usage:

  • To guarantee the structured data is generated, set this value high. Note, this

will delay the end of call report in cases where model is slow to respond. @default 5 seconds.

Returns:

  • (Float)

    This is how long the request is tried before giving up. When request times out, call.analysis.structuredData will be empty. Usage:

    • To guarantee the structured data is generated, set this value high. Note, this

    will delay the end of call report in cases where model is slow to respond. @default 5 seconds



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

def timeout_seconds
  @timeout_seconds
end

Class Method Details

.from_json(json_object:) ⇒ Vapi::StructuredDataPlan

Deserialize a JSON object to an instance of StructuredDataPlan

Parameters:

  • json_object (String)

Returns:



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 117

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  messages = parsed_json["messages"]
  enabled = parsed_json["enabled"]
  if parsed_json["schema"].nil?
    schema = nil
  else
    schema = parsed_json["schema"].to_json
    schema = Vapi::JsonSchema.from_json(json_object: schema)
  end
  timeout_seconds = parsed_json["timeoutSeconds"]
  new(
    messages: messages,
    enabled: enabled,
    schema: schema,
    timeout_seconds: timeout_seconds,
    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)


151
152
153
154
155
156
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 151

def self.validate_raw(obj:)
  obj.messages&.is_a?(Array) != false || raise("Passed value for field obj.messages is not the expected type, validation failed.")
  obj.enabled&.is_a?(Boolean) != false || raise("Passed value for field obj.enabled is not the expected type, validation failed.")
  obj.schema.nil? || Vapi::JsonSchema.validate_raw(obj: obj.schema)
  obj.timeout_seconds&.is_a?(Float) != false || raise("Passed value for field obj.timeout_seconds is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of StructuredDataPlan to a JSON object

Returns:

  • (String)


141
142
143
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 141

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