baml 0.1.0-aarch64-linux → 0.1.9-aarch64-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac1a499103bfe1463f22871d3d97348876d6b0500a4751684b8000c0b736809c
4
- data.tar.gz: 9f1644242fc6448bcbba689411edcdea7eef4e126127136792dd0aa859eb80e5
3
+ metadata.gz: fa539a467be79364e6f2c0c84ac82e3058b1fc94185e5e45d0dd55adffc4ad89
4
+ data.tar.gz: ab456ce0b9cc38ce274a975c7864237bce6e2a3e2caac28c4eaea7956a6ab33f
5
5
  SHA512:
6
- metadata.gz: c2f427540d45fdd09aa2418f010f5e3cb1f8f95cf530173134a043f57dbb1bd069cf8c111abbfb67c478cb1207d2f7c71fbf5bf7c88da5213952aaafa598faff
7
- data.tar.gz: c7334b5aeccb57c995a529fd843557c1f6f81a20e34de25793a139ac693023e77f50d65abaed39757a59738497b8bda9c0f46b6c3cce10a95349a410dd9f8f33
6
+ metadata.gz: dff0778d274963081e565ba405137de3dbd76a962be45599a968248ff3e8c6ea34b276956e986e5a63f6e1dd8e5eea4324efa3b1c63cb22bb8416c6cd354b21f
7
+ data.tar.gz: 7ceb0c5d2d754df0e0892363b2f6f816f8fd4a6634828b9b85b50d23620f7b5b653680fc3abc32c87b3a2b4e4179bc2c6d431655ab303b99aaf3158d10112042
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
Binary file
Binary file
data/lib/baml.rb CHANGED
@@ -1,9 +1,53 @@
1
1
  begin
2
2
  ruby_version = /(\d+\.\d+)/.match(RUBY_VERSION)
3
- require_relative "#{ruby_version}/baml"
3
+ require_relative "baml/#{ruby_version}/ruby_ffi"
4
4
  rescue LoadError
5
- require_relative "baml"
5
+ require_relative "baml/ruby_ffi"
6
6
  end
7
+ require_relative "stream"
7
8
 
8
9
  module Baml
9
- end
10
+ # TODO: implement image support
11
+ class Image; end
12
+
13
+ # Dynamically + idempotently define Baml::TypeConverter
14
+ # NB: this does not respect raise_coercion_error = false
15
+ def self.convert_to(type)
16
+ if !Baml.const_defined?(:TypeConverter)
17
+ Baml.const_set(:TypeConverter, Class.new(TypeCoerce::Converter) do
18
+ def initialize(type)
19
+ super(type)
20
+ end
21
+
22
+ def _convert(value, type, raise_coercion_error, coerce_empty_to_nil)
23
+ # make string handling more strict
24
+ if type == String
25
+ if value.is_a?(String)
26
+ return value
27
+ end
28
+
29
+ raise TypeCoerce::CoercionError.new(value, type)
30
+ end
31
+
32
+ # add unions
33
+ if type.is_a?(T::Types::Union)
34
+ type.types.each do |t|
35
+ # require raise_coercion_error on the recursive union call,
36
+ # so that we can suppress the error if it fails
37
+ converted = _convert(value, t, true, coerce_empty_to_nil)
38
+ return converted
39
+ rescue
40
+ # do nothing - try every instance of the union
41
+ end
42
+
43
+ raise TypeCoerce::CoercionError.new(value, type)
44
+ end
45
+
46
+ super(value, type, raise_coercion_error, coerce_empty_to_nil)
47
+ end
48
+ end)
49
+ end
50
+
51
+ Baml.const_get(:TypeConverter).new(type)
52
+ end
53
+ end
data/lib/stream.rb ADDED
@@ -0,0 +1,73 @@
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
+ partial_coerce:,
30
+ final_coerce:,
31
+ ctx_manager:
32
+ )
33
+ @ffi_stream = ffi_stream
34
+ @partial_coerce = partial_coerce
35
+ @final_coerce = final_coerce
36
+ @ctx_manager = ctx_manager
37
+
38
+ @final_response = nil
39
+ end
40
+
41
+ # Calls the given block once for each event in the stream, where event is a parsed
42
+ # partial response. Returns `self` to enable chaining `.get_final_response`.
43
+ #
44
+ # Must be called with a block.
45
+ #
46
+ # @yieldparam [PartialType] event the parsed partial response
47
+ # @return [BamlStream] self
48
+ def each(&block)
49
+ # Implementing this and include-ing Enumerable allows users to treat this as a Ruby
50
+ # collection: https://ruby-doc.org/3.1.6/Enumerable.html#module-Enumerable-label-Usage
51
+ if @final_response == nil
52
+ @final_response = @ffi_stream.done(@ctx_manager) do |event|
53
+ block.call @partial_coerce.new.from(event.parsed_using_types(Baml::PartialTypes))
54
+ end
55
+ end
56
+
57
+ self
58
+ end
59
+
60
+
61
+ # Gets the final response from the stream.
62
+ #
63
+ # @return [FinalType] the parsed final response
64
+ sig {returns(FinalType)}
65
+ def get_final_response
66
+ if @final_response == nil
67
+ @final_response = @ffi_stream.done(@ctx_manager)
68
+ end
69
+
70
+ @final_coerce.new.from(@final_response.parsed_using_types(Baml::Types))
71
+ end
72
+ end
73
+ end
metadata CHANGED
@@ -1,25 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.9
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - BoundaryML
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-24 00:00:00.000000000 Z
11
+ date: 2024-06-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A gem for users to interact with BoundaryML's Language Model clients
14
14
  (LLM) in Ruby.
15
15
  email:
16
16
  - contact@boundaryml.com
17
- executables: []
17
+ executables:
18
+ - baml-cli
18
19
  extensions: []
19
20
  extra_rdoc_files: []
20
21
  files:
22
+ - exe/baml-cli
21
23
  - lib/baml.rb
22
- - lib/baml/baml.so
24
+ - lib/baml/2.7/ruby_ffi.so
25
+ - lib/baml/3.0/ruby_ffi.so
26
+ - lib/baml/3.1/ruby_ffi.so
27
+ - lib/baml/3.2/ruby_ffi.so
28
+ - lib/baml/3.3/ruby_ffi.so
29
+ - lib/stream.rb
23
30
  homepage: https://github.com/BoundaryML/baml
24
31
  licenses:
25
32
  - MIT
@@ -32,7 +39,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
32
39
  requirements:
33
40
  - - ">="
34
41
  - !ruby/object:Gem::Version
35
- version: '3.3'
42
+ version: '2.7'
36
43
  - - "<"
37
44
  - !ruby/object:Gem::Version
38
45
  version: 3.4.dev
data/lib/baml/baml.so DELETED
Binary file