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
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 = 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.
51 52 53 |
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 51 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.
37 38 39 |
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 37 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.\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 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).
42 43 44 |
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 42 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.
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
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) = 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.
151 152 153 154 155 156 |
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 151 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
141 142 143 |
# File 'lib/vapi_server_sdk/types/structured_data_plan.rb', line 141 def to_json(*_args) @_field_set&.to_json end |