Class: OmniAI::Chat::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/omniai/chat/stream.rb

Overview

Used when streaming to process chunks of data.

Instance Method Summary collapse

Constructor Details

#initialize(body:, logger: nil, context: nil) ⇒ Stream

Returns a new instance of Stream.

Parameters:

  • logger (OmniAI::Client) (defaults to: nil)
  • body (HTTP::Response::Body)
  • context (Context, nil) (defaults to: nil)


10
11
12
13
14
# File 'lib/omniai/chat/stream.rb', line 10

def initialize(body:, logger: nil, context: nil)
  @body = body
  @logger = logger
  @context = context
end

Instance Method Details

#stream! {|payload| ... } ⇒ Object

Yields:

  • (payload)

Yield Parameters:



18
19
20
21
22
23
24
# File 'lib/omniai/chat/stream.rb', line 18

def stream!(&)
  @body.each do |chunk|
    parser.feed(chunk) do |type, data, id|
      process!(type, data, id, &)
    end
  end
end