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.
43 44 45 46 47 48 49 50 51 |
# File 'lib/stream.rb', line 43 def initialize( ffi_stream:, ctx_manager: ) @ffi_stream = ffi_stream @ctx_manager = ctx_manager @final_response = nil end |
Instance Method Details
#each(&block) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/stream.rb', line 61 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 |
#get_final_response ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/stream.rb', line 78 def get_final_response if @final_response == nil @final_response = @ffi_stream.done(@ctx_manager) end @final_response.parsed_using_types(Baml::Types, Baml::PartialTypes, false) end |