Module: Whoosh::Streaming::Helpers

Included in:
App, Endpoint
Defined in:
lib/whoosh/streaming/helpers.rb

Instance Method Summary collapse

Instance Method Details

#stream(type, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/whoosh/streaming/helpers.rb', line 6

def stream(type, &block)
  case type
  when :sse
    body = StreamBody.new do |out|
      sse = SSE.new(out)
      block.call(sse)
    end
    [200, SSE.headers, body]
  else
    raise ArgumentError, "Unknown stream type: #{type}"
  end
end

#stream_llm(&block) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/whoosh/streaming/helpers.rb', line 19

def stream_llm(&block)
  body = StreamBody.new do |out|
    llm_stream = LlmStream.new(out)
    block.call(llm_stream)
    llm_stream.finish
  end
  [200, LlmStream.headers, body]
end