Class: Vapi::StructuredDataPlan
- Inherits:
-
Object
- Object
- Vapi::StructuredDataPlan
- Defined in:
- lib/vapi_server_sdk/types/structured_data_plan.rb
Constant Summary collapse
- OMIT =
Object.new
Instance Attribute Summary collapse
-
#additional_properties ⇒ OpenStruct
readonly
Additional properties unmapped to the current class definition.
-
#enabled ⇒ Boolean
readonly
This determines whether structured data is generated and stored in ‘call.analysis.structuredData`.
-
#messages ⇒ Array<Hash{String => Object}>
readonly
These are the messages used to generate the structured data.
-
#schema ⇒ Vapi::JsonSchema
readonly
This is the schema of the structured data.
-
#timeout_seconds ⇒ Float
readonly
This is how long the request is tried before giving up.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Vapi::StructuredDataPlan
Deserialize a JSON object to an instance of StructuredDataPlan.
-
.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.
Instance Method Summary collapse
- #initialize(messages: OMIT, enabled: OMIT, schema: OMIT, timeout_seconds: OMIT, additional_properties: nil) ⇒ Vapi::StructuredDataPlan constructor
-
#to_json(*_args) ⇒ String
Serialize an instance of StructuredDataPlan to a JSON object.
Constructor Details
#initialize(messages: OMIT, enabled: OMIT, schema: OMIT, timeout_seconds: OMIT, additional_properties: nil) ⇒ Vapi::StructuredDataPlan
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 = if != 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": , "enabled": enabled, "schema": schema, "timeoutSeconds": timeout_seconds }.reject do |_k, v| v == OMIT end end |
Instance Attribute Details
#additional_properties ⇒ OpenStruct (readonly)
Returns 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 |
#enabled ⇒ Boolean (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.
28 29 30 |
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 28 def enabled @enabled end |
#messages ⇒ Array<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`.
21 22 23 |
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 21 def @messages end |
#schema ⇒ Vapi::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).
33 34 35 |
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 33 def schema @schema end |
#timeout_seconds ⇒ Float (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.
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
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) = 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: , 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.
133 134 135 136 137 138 |
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 133 def self.validate_raw(obj:) obj.&.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
123 124 125 |
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 123 def to_json(*_args) @_field_set&.to_json end |