Class: Vellum::StreamingExecutePromptEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/vellum_ai/types/streaming_execute_prompt_event.rb

Overview

The data returned for each delta during the prompt execution stream.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output:, output_index:, execution_id:, meta: nil, raw: nil, additional_properties: nil) ⇒ StreamingExecutePromptEvent

Parameters:

  • output (PromptOutput)
  • output_index (Integer)
  • execution_id (String)
  • meta (StreamingPromptExecutionMeta) (defaults to: nil)
  • raw (Hash{String => String}) (defaults to: nil)

    The subset of the raw response from the model that the request opted into with ‘expand_raw`.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vellum_ai/types/streaming_execute_prompt_event.rb', line 19

def initialize(output:, output_index:, execution_id:, meta: nil, raw: nil, additional_properties: nil)
  # @type [PromptOutput]
  @output = output
  # @type [Integer]
  @output_index = output_index
  # @type [String]
  @execution_id = execution_id
  # @type [StreamingPromptExecutionMeta]
  @meta = meta
  # @type [Hash{String => String}] The subset of the raw response from the model that the request opted into with `expand_raw`.
  @raw = raw
  # @type [OpenStruct] Additional properties unmapped to the current class definition
  @additional_properties = additional_properties
end

Instance Attribute Details

#additional_propertiesObject (readonly)

Returns the value of attribute additional_properties.



10
11
12
# File 'lib/vellum_ai/types/streaming_execute_prompt_event.rb', line 10

def additional_properties
  @additional_properties
end

#execution_idObject (readonly)

Returns the value of attribute execution_id.



10
11
12
# File 'lib/vellum_ai/types/streaming_execute_prompt_event.rb', line 10

def execution_id
  @execution_id
end

#metaObject (readonly)

Returns the value of attribute meta.



10
11
12
# File 'lib/vellum_ai/types/streaming_execute_prompt_event.rb', line 10

def meta
  @meta
end

#outputObject (readonly)

Returns the value of attribute output.



10
11
12
# File 'lib/vellum_ai/types/streaming_execute_prompt_event.rb', line 10

def output
  @output
end

#output_indexObject (readonly)

Returns the value of attribute output_index.



10
11
12
# File 'lib/vellum_ai/types/streaming_execute_prompt_event.rb', line 10

def output_index
  @output_index
end

#rawObject (readonly)

Returns the value of attribute raw.



10
11
12
# File 'lib/vellum_ai/types/streaming_execute_prompt_event.rb', line 10

def raw
  @raw
end

Class Method Details

.from_json(json_object:) ⇒ StreamingExecutePromptEvent

Deserialize a JSON object to an instance of StreamingExecutePromptEvent

Parameters:

  • json_object (JSON)

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/vellum_ai/types/streaming_execute_prompt_event.rb', line 38

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  if parsed_json["output"].nil?
    output = nil
  else
    output = parsed_json["output"].to_json
    output = PromptOutput.from_json(json_object: output)
  end
  output_index = struct.output_index
  execution_id = struct.execution_id
  if parsed_json["meta"].nil?
    meta = nil
  else
    meta = parsed_json["meta"].to_json
    meta = StreamingPromptExecutionMeta.from_json(json_object: meta)
  end
  raw = struct.raw
  new(output: output, output_index: output_index, execution_id: execution_id, meta: meta, raw: raw,
      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)


77
78
79
80
81
82
83
# File 'lib/vellum_ai/types/streaming_execute_prompt_event.rb', line 77

def self.validate_raw(obj:)
  PromptOutput.validate_raw(obj: obj.output)
  obj.output_index.is_a?(Integer) != false || raise("Passed value for field obj.output_index is not the expected type, validation failed.")
  obj.execution_id.is_a?(String) != false || raise("Passed value for field obj.execution_id is not the expected type, validation failed.")
  obj.meta.nil? || StreamingPromptExecutionMeta.validate_raw(obj: obj.meta)
  obj.raw&.is_a?(Hash) != false || raise("Passed value for field obj.raw is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of StreamingExecutePromptEvent to a JSON object

Returns:

  • (JSON)


63
64
65
66
67
68
69
70
71
# File 'lib/vellum_ai/types/streaming_execute_prompt_event.rb', line 63

def to_json(*_args)
  {
    "output": @output,
    "output_index": @output_index,
    "execution_id": @execution_id,
    "meta": @meta,
    "raw": @raw
  }.to_json
end