Class: Riffer::Tracing::StreamRecorder
- Inherits:
-
Object
- Object
- Riffer::Tracing::StreamRecorder
- Defined in:
- lib/riffer/tracing/stream_recorder.rb,
sig/generated/riffer/tracing/stream_recorder.rbs
Overview
Wraps a stream yielder to observe terminal events for span stamping while forwarding every event downstream untouched.
Instance Attribute Summary collapse
-
#content ⇒ String?
readonly
: String?.
-
#finish_reason ⇒ Symbol?
readonly
: Symbol?.
-
#raw_finish_reason ⇒ String?
readonly
: String?.
-
#time_to_first_chunk ⇒ Float?
readonly
: Float?.
-
#token_usage ⇒ Riffer::Providers::TokenUsage?
readonly
Returns the value of attribute token_usage.
-
#tool_calls ⇒ Array[Riffer::Messages::Assistant::ToolCall]
readonly
: Array.
Instance Method Summary collapse
-
#<<(event) ⇒ self
-- : (Riffer::StreamEvents::Base) -> self.
-
#initialize(yielder, clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) }) ⇒ StreamRecorder
constructor
-- : (Enumerator::Yielder, ?clock: ^() -> Float) -> void.
-
#record(event) ⇒ void
-- : (Riffer::StreamEvents::Base) -> void.
Constructor Details
#initialize(yielder, clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) }) ⇒ StreamRecorder
-- : (Enumerator::Yielder, ?clock: ^() -> Float) -> void
25 26 27 28 29 30 |
# File 'lib/riffer/tracing/stream_recorder.rb', line 25 def initialize(yielder, clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) }) @yielder = yielder @clock = clock @started_at = clock.call @tool_calls = [] #: Array[Riffer::Messages::Assistant::ToolCall] end |
Instance Attribute Details
#content ⇒ String? (readonly)
: String?
19 20 21 |
# File 'lib/riffer/tracing/stream_recorder.rb', line 19 def content @content end |
#finish_reason ⇒ Symbol? (readonly)
: Symbol?
15 16 17 |
# File 'lib/riffer/tracing/stream_recorder.rb', line 15 def finish_reason @finish_reason end |
#raw_finish_reason ⇒ String? (readonly)
: String?
17 18 19 |
# File 'lib/riffer/tracing/stream_recorder.rb', line 17 def raw_finish_reason @raw_finish_reason end |
#time_to_first_chunk ⇒ Float? (readonly)
: Float?
13 14 15 |
# File 'lib/riffer/tracing/stream_recorder.rb', line 13 def time_to_first_chunk @time_to_first_chunk end |
#token_usage ⇒ Riffer::Providers::TokenUsage? (readonly)
Returns the value of attribute token_usage.
11 12 13 |
# File 'lib/riffer/tracing/stream_recorder.rb', line 11 def token_usage @token_usage end |
#tool_calls ⇒ Array[Riffer::Messages::Assistant::ToolCall] (readonly)
: Array
21 22 23 |
# File 'lib/riffer/tracing/stream_recorder.rb', line 21 def tool_calls @tool_calls end |
Instance Method Details
#<<(event) ⇒ self
-- : (Riffer::StreamEvents::Base) -> self
34 35 36 37 38 39 |
# File 'lib/riffer/tracing/stream_recorder.rb', line 34 def <<(event) @time_to_first_chunk ||= @clock.call - @started_at record(event) @yielder << event self end |
#record(event) ⇒ void
This method returns an undefined value.
-- : (Riffer::StreamEvents::Base) -> void
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/riffer/tracing/stream_recorder.rb', line 45 def record(event) case event when Riffer::StreamEvents::TextDone @content = event.content when Riffer::StreamEvents::ToolCallDone @tool_calls << Riffer::Messages::Assistant::ToolCall.new(call_id: event.call_id, name: event.name, arguments: event.arguments) when Riffer::StreamEvents::TokenUsageDone @token_usage = event.token_usage when Riffer::StreamEvents::FinishReasonDone @finish_reason = event.finish_reason @raw_finish_reason = event.raw_finish_reason end end |