Class: Rager::Result
Instance Attribute Summary collapse
-
#attempt ⇒ Object
readonly
Returns the value of attribute attempt.
-
#context_id ⇒ Object
readonly
Returns the value of attribute context_id.
-
#context_name ⇒ Object
readonly
Returns the value of attribute context_name.
-
#context_tags ⇒ Object
readonly
Returns the value of attribute context_tags.
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#input_ids ⇒ Object
readonly
Returns the value of attribute input_ids.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#transform ⇒ Object
readonly
Returns the value of attribute transform.
Instance Method Summary collapse
-
#initialize(id:, context_id:, operation:, input:, output:, options:, start_time:, end_time:, attempt: 0, errors: [], input_ids: [], name: nil, tags: [], context_name: nil, context_tags: [], transform: nil) ⇒ Result
constructor
A new instance of Result.
- #let(&block) ⇒ Object
- #log ⇒ Object
- #stream ⇒ Object
- #stream? ⇒ Boolean
- #success? ⇒ Boolean
- #to_h ⇒ Object
- #to_json ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(id:, context_id:, operation:, input:, output:, options:, start_time:, end_time:, attempt: 0, errors: [], input_ids: [], name: nil, tags: [], context_name: nil, context_tags: [], transform: nil) ⇒ Result
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rager/result.rb', line 82 def initialize(id:, context_id:, operation:, input:, output:, options:, start_time:, end_time:, attempt: 0, errors: [], input_ids: [], name: nil, tags: [], context_name: nil, context_tags: [], transform: nil) @id = id @context_id = context_id @operation = operation @input = input @output = output = @start_time = start_time @end_time = end_time @attempt = attempt @errors = T.let(errors, T::Array[String]) @input_ids = T.let(input_ids, T::Array[String]) @name = name = @context_name = context_name = T.let(, T::Array[String]) @transform = transform @stream = T.let(nil, T.nilable(Rager::Types::Stream)) @buffer = T.let([], Rager::Types::Buffer) @consumed = T.let(false, T::Boolean) end |
Instance Attribute Details
#attempt ⇒ Object (readonly)
Returns the value of attribute attempt.
39 40 41 |
# File 'lib/rager/result.rb', line 39 def attempt @attempt end |
#context_id ⇒ Object (readonly)
Returns the value of attribute context_id.
18 19 20 |
# File 'lib/rager/result.rb', line 18 def context_id @context_id end |
#context_name ⇒ Object (readonly)
Returns the value of attribute context_name.
54 55 56 |
# File 'lib/rager/result.rb', line 54 def context_name @context_name end |
#context_tags ⇒ Object (readonly)
Returns the value of attribute context_tags.
57 58 59 |
# File 'lib/rager/result.rb', line 57 def end |
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
36 37 38 |
# File 'lib/rager/result.rb', line 36 def end_time @end_time end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
42 43 44 |
# File 'lib/rager/result.rb', line 42 def errors @errors end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
15 16 17 |
# File 'lib/rager/result.rb', line 15 def id @id end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
24 25 26 |
# File 'lib/rager/result.rb', line 24 def input @input end |
#input_ids ⇒ Object (readonly)
Returns the value of attribute input_ids.
45 46 47 |
# File 'lib/rager/result.rb', line 45 def input_ids @input_ids end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
48 49 50 |
# File 'lib/rager/result.rb', line 48 def name @name end |
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
21 22 23 |
# File 'lib/rager/result.rb', line 21 def operation @operation end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
30 31 32 |
# File 'lib/rager/result.rb', line 30 def end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
27 28 29 |
# File 'lib/rager/result.rb', line 27 def output @output end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
33 34 35 |
# File 'lib/rager/result.rb', line 33 def start_time @start_time end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
51 52 53 |
# File 'lib/rager/result.rb', line 51 def end |
#transform ⇒ Object (readonly)
Returns the value of attribute transform.
60 61 62 |
# File 'lib/rager/result.rb', line 60 def transform @transform end |
Instance Method Details
#let(&block) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/rager/result.rb', line 159 def let(&block) transform = yield(value) Result.new( id: @id, context_id: @context_id, operation: @operation, input: @input, output: @output, options: , start_time: @start_time, end_time: @end_time, attempt: @attempt, errors: @errors, input_ids: @input_ids, name: @name, tags: , context_name: @context_name, context_tags: , transform: transform ) end |
#log ⇒ Object
212 213 214 215 216 217 218 |
# File 'lib/rager/result.rb', line 212 def log Rager::Utils::Http.log_remote( "results", to_json, !success? ) end |
#stream ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/rager/result.rb', line 116 def stream return T.must(@output) unless stream? return @buffer.each if @consumed @stream = Enumerator.new do |yielder| T.cast(@output, Rager::Types::Stream) .each { || @buffer << yielder << } @consumed = true @end_time = Time.now.to_i log end @stream end |
#stream? ⇒ Boolean
111 112 113 |
# File 'lib/rager/result.rb', line 111 def stream? @output.is_a?(Enumerator) end |
#success? ⇒ Boolean
106 107 108 |
# File 'lib/rager/result.rb', line 106 def success? @errors.empty? end |
#to_h ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/rager/result.rb', line 183 def to_h { version: "1", data: { id: @id, context_id: @context_id, operation: @operation.serialize, input: @input, output: display_output, options: .serialize_safe, start_time: @start_time, end_time: @end_time, attempt: @attempt, errors: @errors, input_ids: @input_ids, name: @name, tags: , context_name: @context_name, context_tags: } } end |
#to_json ⇒ Object
207 208 209 |
# File 'lib/rager/result.rb', line 207 def to_json to_h.to_json end |
#value ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/rager/result.rb', line 137 def value return @transform if @transform return T.cast(@output, Rager::Types::NonStreamOutput) unless stream? T.cast(stream, Rager::Types::Stream).each { |_| } unless @consumed @buffer .group_by(&:index) .transform_values { |deltas| deltas.map(&:content).join } .sort .map(&:last) .then { |parts| (parts.length == 1) ? parts.first : parts } end |