baml-cc 0.208.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/baml.rb ADDED
@@ -0,0 +1,63 @@
1
+ begin
2
+ ruby_version = /(\d+\.\d+)/.match(RUBY_VERSION)
3
+ require_relative "baml/#{ruby_version}/ruby_ffi"
4
+ rescue LoadError
5
+ require_relative "baml/ruby_ffi"
6
+ end
7
+ # require_relative "baml/ruby_ffi"
8
+ require_relative "stream"
9
+ require_relative "struct"
10
+ require_relative "checked"
11
+
12
+ module Baml
13
+ ClientRegistry = Baml::Ffi::ClientRegistry
14
+ Image = Baml::Ffi::Image
15
+ Audio = Baml::Ffi::Audio
16
+ Collector = Baml::Ffi::Collector
17
+
18
+ # Reexport Checked types.
19
+ Checked = Baml::Checks::Checked
20
+ Check = Baml::Checks::Check
21
+
22
+
23
+ # Dynamically + idempotently define Baml::TypeConverter
24
+ # NB: this does not respect raise_coercion_error = false
25
+ def self.convert_to(type)
26
+ if !Baml.const_defined?(:TypeConverter)
27
+ Baml.const_set(:TypeConverter, Class.new(TypeCoerce::Converter) do
28
+ def initialize(type)
29
+ super(type)
30
+ end
31
+
32
+ def _convert(value, type, raise_coercion_error, coerce_empty_to_nil)
33
+ # make string handling more strict
34
+ if type == String
35
+ if value.is_a?(String)
36
+ return value
37
+ end
38
+
39
+ raise TypeCoerce::CoercionError.new(value, type)
40
+ end
41
+
42
+ # add unions
43
+ if type.is_a?(T::Types::Union)
44
+ type.types.each do |t|
45
+ # require raise_coercion_error on the recursive union call,
46
+ # so that we can suppress the error if it fails
47
+ converted = _convert(value, t, true, coerce_empty_to_nil)
48
+ return converted
49
+ rescue
50
+ # do nothing - try every instance of the union
51
+ end
52
+
53
+ raise TypeCoerce::CoercionError.new(value, type)
54
+ end
55
+
56
+ super(value, type, raise_coercion_error, coerce_empty_to_nil)
57
+ end
58
+ end)
59
+ end
60
+
61
+ Baml.const_get(:TypeConverter).new(type)
62
+ end
63
+ end
data/lib/checked.rb ADDED
@@ -0,0 +1,36 @@
1
+ require "sorbet-runtime"
2
+
3
+ module Baml
4
+ module Checks
5
+
6
+ class Check < T::Struct
7
+ extend T::Sig
8
+
9
+ const :name, String
10
+ const :expr, String
11
+ const :status, String
12
+
13
+
14
+ def initialize(props)
15
+ super(name: props[:name], expr: props[:expr], status: props[:status])
16
+ end
17
+ end
18
+
19
+ class Checked < T::Struct
20
+ extend T::Sig
21
+
22
+ extend T::Generic
23
+
24
+ Value = type_member
25
+
26
+ const :value, Value
27
+ const :checks, T::Hash[Symbol, Check]
28
+
29
+ def initialize(props)
30
+ super(value: props[:value], checks: props[:checks])
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
data/lib/stream.rb ADDED
@@ -0,0 +1,87 @@
1
+ require "sorbet-runtime"
2
+
3
+ module Baml
4
+ # class BamlStream
5
+ # include Enumerable
6
+
7
+ # def initialize(raw_stream:)
8
+ # @raw_stream = raw_stream
9
+ # end
10
+
11
+ # def each(&block)
12
+ # @raw_stream.each do |raw_msg|
13
+ # yield Message.from(raw_msg)
14
+ # end
15
+ # end
16
+ # end
17
+
18
+ class StreamState < T::Struct
19
+ extend T::Sig
20
+
21
+ extend T::Generic
22
+
23
+ Value = type_member
24
+
25
+ const :value, Value
26
+ const :state, Symbol
27
+
28
+ def initialize(props)
29
+ super(value: props[:value], state: props[:state])
30
+ end
31
+
32
+ end
33
+
34
+ class BamlStream
35
+ extend T::Sig
36
+ extend T::Generic
37
+
38
+ include Enumerable
39
+
40
+ PartialType = type_member
41
+ FinalType = type_member
42
+
43
+ def initialize(
44
+ ffi_stream:,
45
+ ctx_manager:
46
+ )
47
+ @ffi_stream = ffi_stream
48
+ @ctx_manager = ctx_manager
49
+
50
+ @final_response = nil
51
+ end
52
+
53
+ # Calls the given block once for each event in the stream, where event is a parsed
54
+ # partial response. Returns `self` to enable chaining `.get_final_response`.
55
+ #
56
+ # Must be called with a block.
57
+ #
58
+ # @yieldparam [PartialType] event the parsed partial response
59
+ # @return [BamlStream] self
60
+ sig { params(block: T.proc.params(event: PartialType).void).returns(BamlStream)}
61
+ def each(&block)
62
+ # Implementing this and include-ing Enumerable allows users to treat this as a Ruby
63
+ # collection: https://ruby-doc.org/3.1.6/Enumerable.html#module-Enumerable-label-Usage
64
+ if @final_response == nil
65
+ @final_response = @ffi_stream.done(@ctx_manager) do |event|
66
+ block.call event.parsed_using_types(Baml::Types, Baml::PartialTypes, true)
67
+ end
68
+ end
69
+
70
+ self
71
+ end
72
+
73
+
74
+ # Gets the final response from the stream.
75
+ #
76
+ # @return [FinalType] the parsed final response
77
+ sig {returns(FinalType)}
78
+ def get_final_response
79
+ if @final_response == nil
80
+ @final_response = @ffi_stream.done(@ctx_manager)
81
+ end
82
+
83
+ @final_response.parsed_using_types(Baml::Types, Baml::PartialTypes, false)
84
+ end
85
+ end
86
+
87
+ end
data/lib/struct.rb ADDED
@@ -0,0 +1,66 @@
1
+ # This file should NOT be imported from baml.rb; we don't want
2
+ # to introduce a hard dependency on Sorbet for the baml gem.
3
+ require "ostruct"
4
+ #require "pp"
5
+
6
+ module Baml
7
+ module Sorbet
8
+ # Provides dynamic properties on statically defined classes
9
+ module Struct
10
+ # Needed to allow accessing dynamic types
11
+ def method_missing(symbol)
12
+ @props[symbol]
13
+ end
14
+
15
+ def eql?(other)
16
+ self.class == other.class &&
17
+ @props.eql?(other.instance_variable_get(:@args))
18
+ end
19
+
20
+ def hash
21
+ [self.class, @props].hash
22
+ end
23
+
24
+ def [](key)
25
+ key = key.to_sym if key.is_a?(String)
26
+ @props[key]
27
+ end
28
+
29
+ def inspect
30
+ PP.pp(self, +"", 79)
31
+ end
32
+
33
+ # https://docs.ruby-lang.org/en/master/PP.html
34
+ def pretty_print(pp)
35
+ pp.object_group(self) do
36
+ pp.breakable
37
+ @props.each do |key, value|
38
+ pp.text "#{key}="
39
+ pp.pp value
40
+ pp.comma_breakable unless key == @props.keys.last
41
+ end
42
+ end
43
+ end
44
+
45
+ # From the ostruct implementation
46
+ def to_h(&block)
47
+ if block
48
+ @props.map(&block).to_h
49
+ else
50
+ @props.dup
51
+ end
52
+ end
53
+
54
+ def to_json(*args)
55
+ @props.to_json(*args)
56
+ end
57
+ end
58
+ end
59
+
60
+ # Dynamically defined output classes are instantiated using this class
61
+ class DynamicStruct < OpenStruct
62
+ def to_json(*args)
63
+ @table.to_json(*args)
64
+ end
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: baml-cc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.208.5
5
+ platform: ruby
6
+ authors:
7
+ - BoundaryML
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-09-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A gem for users to interact with BoundaryML's Language Model clients
14
+ (LLM) in Ruby.
15
+ email:
16
+ - contact@boundaryml.com
17
+ executables:
18
+ - baml-cli
19
+ - baml
20
+ extensions:
21
+ - ext/ruby_ffi/extconf.rb
22
+ extra_rdoc_files: []
23
+ files:
24
+ - exe/baml
25
+ - exe/baml-cli
26
+ - ext/ruby_ffi/Cargo.toml
27
+ - ext/ruby_ffi/build.rs
28
+ - ext/ruby_ffi/extconf.rb
29
+ - ext/ruby_ffi/src/function_result.rs
30
+ - ext/ruby_ffi/src/function_result_stream.rs
31
+ - ext/ruby_ffi/src/lib.rs
32
+ - ext/ruby_ffi/src/ruby_to_json.rs
33
+ - ext/ruby_ffi/src/types/client_registry.rs
34
+ - ext/ruby_ffi/src/types/lang_wrapper.rs
35
+ - ext/ruby_ffi/src/types/log_collector.rs
36
+ - ext/ruby_ffi/src/types/media.rs
37
+ - ext/ruby_ffi/src/types/mod.rs
38
+ - ext/ruby_ffi/src/types/request.rs
39
+ - ext/ruby_ffi/src/types/response.rs
40
+ - ext/ruby_ffi/src/types/runtime_ctx_manager.rs
41
+ - ext/ruby_ffi/src/types/type_builder.rs
42
+ - lib/baml.rb
43
+ - lib/checked.rb
44
+ - lib/stream.rb
45
+ - lib/struct.rb
46
+ homepage: https://github.com/BoundaryML/baml
47
+ licenses:
48
+ - MIT
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 3.1.0
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 3.3.3
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: Unified BoundaryML LLM client
69
+ test_files: []