Skip to content

v0.3.0 - streaming

Latest
Compare
Choose a tag to compare
@drnic drnic released this 25 Apr 09:13
· 9 commits to develop since this release

In this release we add some options for receiving streaming chunks from Groq API, rather than blocking until the entire response is ready. This is lovely when your end user is waiting patiently for feedback.

There is nice simple option to pass a block to chat() and receive each chunk as simple text:

@client.chat("Write a long poem about patience") do |content|
  print content
end

Or you can use an object with a call(content) method:

class MessageBits
  def initialize(emoji)
    print "#{emoji} "
    @bits = []
  end

  def call(content)
    if content.nil?
      puts
    else
      print(content)
      @bits << content
    end
  end

  def to_s
    @bits.join("")
  end

  def to_assistant_message
    Assistant(to_s)
  end
end

bits = MessageBits.new("🍕")
@client.chat("Write a long poem about pizza", stream: bits)

In both modes, you can pass an optional 2nd argument to receive the original chunk returned from the Groq API.