Class: OmniAI::Anthropic::Chat::Response::Stream

Inherits:
Chat::Response::Stream
  • Object
show all
Defined in:
lib/omniai/anthropic/chat/response/stream.rb

Overview

A stream given when streaming.

Defined Under Namespace

Modules: Type Classes: Builder

Instance Method Summary collapse

Instance Method Details

#stream! {|OmniAI::Chat::Chunk| ... } ⇒ Object

Yields:

  • (OmniAI::Chat::Chunk)


81
82
83
84
85
86
87
88
89
# File 'lib/omniai/anthropic/chat/response/stream.rb', line 81

def stream!(&block)
  builder = Builder.new

  @response.body.each do |chunk|
    @parser.feed(chunk) do |type, data|
      process(type:, data: JSON.parse(data), builder:, &block)
    end
  end
end