Class: Baml::BamlStream
- Inherits:
-
Object
- Object
- Baml::BamlStream
- Extended by:
- T::Generic, T::Sig
- Includes:
- Enumerable
- Defined in:
- lib/stream.rb
Constant Summary collapse
- PartialType =
type_member
- FinalType =
type_member
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #get_final_response ⇒ Object
-
#initialize(ffi_stream:, ctx_manager:) ⇒ BamlStream
constructor
A new instance of BamlStream.
Constructor Details
#initialize(ffi_stream:, ctx_manager:) ⇒ BamlStream
Returns a new instance of BamlStream.
45 46 47 48 49 50 51 52 53 |
# File 'lib/stream.rb', line 45 def initialize( ffi_stream:, ctx_manager: ) @ffi_stream = ffi_stream @ctx_manager = ctx_manager @final_response = nil end |
Instance Method Details
#each(&block) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/stream.rb', line 63 def each(&block) # Implementing this and include-ing Enumerable allows users to treat this as a Ruby # collection: https://ruby-doc.org/3.1.6/Enumerable.html#module-Enumerable-label-Usage if @final_response == nil @final_response = @ffi_stream.done(@ctx_manager) do |event| block.call event.parsed_using_types(Baml::Types, Baml::PartialTypes, true) end end self end |