Skip to content

Commit

Permalink
fix codegen once more
Browse files Browse the repository at this point in the history
  • Loading branch information
sxlijin committed Jun 7, 2024
1 parent 1c48192 commit 1bfabbe
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl LanguageFeatures for RubyLanguageFeatures {
#
# Welcome to Baml! To use this generated code, please run the following:
#
# $ bundle add baml sorbet-runtime sorbet-coerce sorbet-struct-comparable
# $ bundle add baml sorbet-runtime sorbet-struct-comparable
#
###############################################################################
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# typed: false
require "baml"
require "sorbet-coerce"
require "sorbet-runtime"

require_relative "inlined"
Expand Down Expand Up @@ -102,8 +101,6 @@ module Baml
)
Baml::BamlStream[{{fn.partial_return_type}}, {{fn.return_type}}].new(
ffi_stream: raw,
partial_coerce: TypeCoerce[{{fn.partial_return_type}}],
final_coerce: TypeCoerce[{{fn.return_type}}],
ctx_manager: @ctx_manager
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Baml
module Inlined
FILE_MAP = {
{% for (path, contents) in file_map %}
"{{ path }}" => {{ contents }},
{{ path }} => {{ contents }},
{%- endfor %}
}
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# typed: false
require "sorbet-struct-comparable"
require "sorbet-runtime"
require "sorbet-struct-comparable"

require_relative "types"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# typed: false
require "sorbet-struct-comparable"
require "sorbet-runtime"
require "sorbet-struct-comparable"

module Baml
{# Baml::Types is reserved for generated types. #}
Expand Down
2 changes: 1 addition & 1 deletion engine/language_client_ruby/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
baml (0.1.8)
baml (0.1.9)

GEM
remote: https://rubygems.org/
Expand Down
2 changes: 1 addition & 1 deletion engine/language_client_ruby/baml.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |spec|
spec.name = "baml"
spec.version = "0.1.9"
spec.version = "0.1.10"
spec.authors = ["BoundaryML"]
spec.email = ["[email protected]"]

Expand Down
9 changes: 3 additions & 6 deletions engine/language_client_ruby/lib/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@ class BamlStream

def initialize(
ffi_stream:,
partial_coerce:,
final_coerce:,
ctx_manager:
)
@ffi_stream = ffi_stream
@partial_coerce = partial_coerce
@final_coerce = final_coerce
@ctx_manager = ctx_manager

@final_response = nil
Expand All @@ -45,12 +41,13 @@ def initialize(
#
# @yieldparam [PartialType] event the parsed partial response
# @return [BamlStream] self
sig { params(block: T.proc.params(event: PartialType).void).returns(BamlStream)}
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 @partial_coerce.new.from(event.parsed_using_types(Baml::PartialTypes))
block.call event.parsed_using_types(Baml::PartialTypes)
end
end

Expand All @@ -67,7 +64,7 @@ def get_final_response
@final_response = @ffi_stream.done(@ctx_manager)
end

@final_coerce.new.from(@final_response.parsed_using_types(Baml::Types))
@final_response.parsed_using_types(Baml::Types)
end
end
end
3 changes: 1 addition & 2 deletions integ-tests/ruby/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
source "https://rubygems.org"

gem "rake", "~> 13.0"
gem "sorbet-coerce"
gem "sorbet-runtime"
gem "sorbet-struct-comparable"

group :test do
gem "minitest-reporters"
end
end
2 changes: 1 addition & 1 deletion integ-tests/ruby/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require "rake/testtask"
task :generate do
sh "ruby", \
"-I../../engine/language_client_ruby/lib", \
"../../engine/language_client_ruby/bin/baml-cli.rb", \
"../../engine/language_client_ruby/exe/baml-cli", \
"generate", "--from", "../baml_src"
end

Expand Down
Loading

0 comments on commit 1bfabbe

Please sign in to comment.