baml 0.54.1-arm-linux

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '08b89c80d2f949ee6a9750083bb534d0ff6dee96e5c6e1947df74054c7f8a860'
4
+ data.tar.gz: 2673b06185439a4d4dbcf9c377ac42e3ccacb02b35cf4a0c612742192be53750
5
+ SHA512:
6
+ metadata.gz: b5a7703dd15d9ddb730067ec92b1941910dbd775d9595db947c9fd12f3f2c592eee702491e63186acbc3862f71a001503ac5c189ae203d5fe2462e59b132885a
7
+ data.tar.gz: 8967b466e55669228b692d06f63ae404cc679aa2020053aa1047983729a05f55fa4f3a281293efb1fd8cdba7c2407793231f1c4160e9c607aa834bd0aef1acc6
data/exe/baml-cli ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require "baml"
3
+
4
+ Baml::Ffi::invoke_runtime_cli(Process.argv0, ARGV)
Binary file
Binary file
Binary file
data/lib/baml.rb ADDED
@@ -0,0 +1,56 @@
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
+
11
+ module Baml
12
+ ClientRegistry = Baml::Ffi::ClientRegistry
13
+ Image = Baml::Ffi::Image
14
+ Audio = Baml::Ffi::Audio
15
+
16
+ # Dynamically + idempotently define Baml::TypeConverter
17
+ # NB: this does not respect raise_coercion_error = false
18
+ def self.convert_to(type)
19
+ if !Baml.const_defined?(:TypeConverter)
20
+ Baml.const_set(:TypeConverter, Class.new(TypeCoerce::Converter) do
21
+ def initialize(type)
22
+ super(type)
23
+ end
24
+
25
+ def _convert(value, type, raise_coercion_error, coerce_empty_to_nil)
26
+ # make string handling more strict
27
+ if type == String
28
+ if value.is_a?(String)
29
+ return value
30
+ end
31
+
32
+ raise TypeCoerce::CoercionError.new(value, type)
33
+ end
34
+
35
+ # add unions
36
+ if type.is_a?(T::Types::Union)
37
+ type.types.each do |t|
38
+ # require raise_coercion_error on the recursive union call,
39
+ # so that we can suppress the error if it fails
40
+ converted = _convert(value, t, true, coerce_empty_to_nil)
41
+ return converted
42
+ rescue
43
+ # do nothing - try every instance of the union
44
+ end
45
+
46
+ raise TypeCoerce::CoercionError.new(value, type)
47
+ end
48
+
49
+ super(value, type, raise_coercion_error, coerce_empty_to_nil)
50
+ end
51
+ end)
52
+ end
53
+
54
+ Baml.const_get(:TypeConverter).new(type)
55
+ end
56
+ end
data/lib/stream.rb ADDED
@@ -0,0 +1,70 @@
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 BamlStream
19
+ extend T::Sig
20
+ extend T::Generic
21
+
22
+ include Enumerable
23
+
24
+ PartialType = type_member
25
+ FinalType = type_member
26
+
27
+ def initialize(
28
+ ffi_stream:,
29
+ ctx_manager:
30
+ )
31
+ @ffi_stream = ffi_stream
32
+ @ctx_manager = ctx_manager
33
+
34
+ @final_response = nil
35
+ end
36
+
37
+ # Calls the given block once for each event in the stream, where event is a parsed
38
+ # partial response. Returns `self` to enable chaining `.get_final_response`.
39
+ #
40
+ # Must be called with a block.
41
+ #
42
+ # @yieldparam [PartialType] event the parsed partial response
43
+ # @return [BamlStream] self
44
+ sig { params(block: T.proc.params(event: PartialType).void).returns(BamlStream)}
45
+ def each(&block)
46
+ # Implementing this and include-ing Enumerable allows users to treat this as a Ruby
47
+ # collection: https://ruby-doc.org/3.1.6/Enumerable.html#module-Enumerable-label-Usage
48
+ if @final_response == nil
49
+ @final_response = @ffi_stream.done(@ctx_manager) do |event|
50
+ block.call event.parsed_using_types(Baml::PartialTypes)
51
+ end
52
+ end
53
+
54
+ self
55
+ end
56
+
57
+
58
+ # Gets the final response from the stream.
59
+ #
60
+ # @return [FinalType] the parsed final response
61
+ sig {returns(FinalType)}
62
+ def get_final_response
63
+ if @final_response == nil
64
+ @final_response = @ffi_stream.done(@ctx_manager)
65
+ end
66
+
67
+ @final_response.parsed_using_types(Baml::Types)
68
+ end
69
+ end
70
+ 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,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: baml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.54.1
5
+ platform: arm-linux
6
+ authors:
7
+ - BoundaryML
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-09-03 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
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - exe/baml-cli
23
+ - lib/baml.rb
24
+ - lib/baml/3.1/ruby_ffi.so
25
+ - lib/baml/3.2/ruby_ffi.so
26
+ - lib/baml/3.3/ruby_ffi.so
27
+ - lib/stream.rb
28
+ - lib/struct.rb
29
+ homepage: https://github.com/BoundaryML/baml
30
+ licenses:
31
+ - MIT
32
+ metadata: {}
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '3.1'
42
+ - - "<"
43
+ - !ruby/object:Gem::Version
44
+ version: 3.4.dev
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubygems_version: 3.4.4
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Unified BoundaryML LLM client
55
+ test_files: []