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.nnJson Schema:\n{schema}nnOnly respond with the JSON.” }, { “role”: “user”, “content”: “Here is the transcript:nn{transcript}nn” } ]` 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.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



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 79

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



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

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



28
29
30
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 28

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.nnJson Schema:\n{schema}nnOnly respond with the JSON.” }, { “role”: “user”, “content”: “Here is the transcript:nn{transcript}nn” } ]` 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.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.nnJson Schema:\n{schema}nnOnly respond with the JSON.” }, { “role”: “user”, “content”: “Here is the transcript:nn{transcript}nn” } ]` 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.content`- {schema}: the schema of the structured data from `structuredDataPlan.schema`



21
22
23
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 21

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:



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

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



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

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:



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 99

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)


133
134
135
136
137
138
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 133

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)


123
124
125
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 123

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