ruby_llm 2.0.0.rc1 → 2.0.0.rc2

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: 3e6a6455ecb1c6bf276d863d9e1f181f1a1d3ea87092800a01522c1fb9be35fc
4
- data.tar.gz: 39554eb45edfde45e43e0a9eb9afe2a5e07cf6601b9b8076e19065493e62e0fd
3
+ metadata.gz: ef3c927159add14551e31ce03609ce42e150f9f161af9b68602f9c0e080fc31d
4
+ data.tar.gz: b894b99f6d6e541c643d76810b9542364f9d0beef4d00efd7b87b80d36c071af
5
5
  SHA512:
6
- metadata.gz: c92879f31f983745665f2a08db2e9b01a293d40ebd2a0e68ee899e1af4b77f7d4c6767c700bcbdecc85088a43a0fae58a11b617c4409e1b04b73d44a7f59b4da
7
- data.tar.gz: 853e3cdde61afafbfdff5ff84cdc3c9878002f4da1b81e45e1b105b0caf759587647a03cb05d85d806a5e3c91c48ec426d24e356615914802860cb1cdec9c6cb
6
+ metadata.gz: 7dacd51baf534c7b226e1db52f09421b72d9939ec17af6cfd4b18db8bd7d9fbe2a22b488a8571d64f2194d46ed82ba045a726a309465b448f3a31a077a1f98c1
7
+ data.tar.gz: 90f866305245b759ae821cd8932d518c8648f5a3afce588028b820ced1f8aa7b05ac5de7c55a6b0f89e5aac80052d348fbc3fec8cf3b9efc83dec5effa32b260
data/README.md CHANGED
@@ -38,7 +38,7 @@ In Rails, the API works on your own Chat and Message records, with Active Storag
38
38
 
39
39
  ## Show me the code
40
40
 
41
- These examples use **2.0.0.rc1**. Follow [Getting Started](https://rubyllm.com/next/getting-started/) to install it and configure the providers you want to try.
41
+ These examples use **2.0.0.rc2**. Follow [Getting Started](https://rubyllm.com/next/getting-started/) to install it and configure the providers you want to try.
42
42
 
43
43
  ```ruby
44
44
  # Just ask questions
@@ -195,7 +195,7 @@ response.parsed
195
195
  Install the 2.0 release candidate:
196
196
 
197
197
  ```bash
198
- bundle add ruby_llm --version 2.0.0.rc1
198
+ bundle add ruby_llm --version 2.0.0.rc2
199
199
  ```
200
200
 
201
201
  Configure a provider in your script, or in `config/initializers/ruby_llm.rb` in Rails:
@@ -21,7 +21,5 @@ class <%= create_migration_class_name(message_table_name) %> < ActiveRecord::Mig
21
21
  t.string :finish_reason
22
22
  t.timestamps
23
23
  end
24
-
25
- add_index :<%= message_table_name %>, :role
26
24
  end
27
25
  end
@@ -5,9 +5,7 @@ source 'https://rubygems.org'
5
5
  gemspec
6
6
 
7
7
  group :development do
8
- if RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.2')
9
- gem 'archspec', github: 'crmne/archspec', tag: 'v1.1.0.rc1'
10
- end
8
+ gem 'archspec' if RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.2')
11
9
  gem 'bundler', '>= 2.0'
12
10
  gem 'dotenv'
13
11
  gem 'flay'
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
24
24
  %w[.flayignore .overcommit.yml .rspec .rubocop.yml Archspec.rb LICENSE README.md]
25
25
  spec.require_paths = ['lib']
26
26
 
27
- spec.add_dependency 'ruby_llm', '>= 2.0'
27
+ spec.add_dependency 'ruby_llm', '>= 2.0.0.rc1'
28
28
  end
@@ -46,6 +46,7 @@ class <%= cleanup_migration_class_name %> < ActiveRecord::Migration<%= migration
46
46
 
47
47
  def remove_legacy_message_columns
48
48
  table = :<%= message_table_name %>
49
+ remove_matching_indexes(table, :role)
49
50
  reference_columns = %i[<%= v1_model_foreign_key %> <%= v1_tool_call_foreign_key %>]
50
51
  reference_columns.each do |column|
51
52
  remove_column_foreign_keys(table, column)
@@ -96,11 +96,17 @@ module RubyLLM
96
96
 
97
97
  def attachment_sources
98
98
  change = pending_attachment_change
99
- return attachments.map { |attachment| [attachment, nil] } unless pending_attachment_change?(change)
99
+ return attachments_with_blobs.map { |attachment| [attachment, nil] } unless pending_attachment_change?(change)
100
100
 
101
101
  change.attachments.zip(change.attachables)
102
102
  end
103
103
 
104
+ def attachments_with_blobs
105
+ records = attachments.to_a
106
+ ::ActiveRecord::Associations::Preloader.new(records: records, associations: :blob).call
107
+ records
108
+ end
109
+
104
110
  def pending_attachment_change
105
111
  attachment_changes['attachments'] if respond_to?(:attachment_changes)
106
112
  end
@@ -777,11 +777,16 @@ module RubyLLM
777
777
  return messages unless assoc.respond_to?(:klass)
778
778
 
779
779
  associations = %i[ruby_llm_tool_calls ruby_llm_parent_tool_call ruby_llm_usages]
780
+ associations << { attachments_attachments: :blob } if attachment_association?(assoc.klass)
780
781
 
781
782
  ::ActiveRecord::Associations::Preloader.new(records: messages, associations: associations).call
782
783
  messages
783
784
  end
784
785
 
786
+ def attachment_association?(message_class)
787
+ message_class.reflect_on_association(:attachments_attachments).present?
788
+ end
789
+
785
790
  def build_llm_chat
786
791
  chat = (context || RubyLLM).chat(
787
792
  model: model_id,