ruby_llm 1.8.1 → 1.8.2
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 +4 -4
- data/README.md +4 -4
- data/lib/generators/ruby_llm/chat_ui/chat_ui_generator.rb +117 -69
- data/lib/generators/ruby_llm/chat_ui/templates/controllers/chats_controller.rb.tt +12 -12
- data/lib/generators/ruby_llm/chat_ui/templates/controllers/messages_controller.rb.tt +7 -7
- data/lib/generators/ruby_llm/chat_ui/templates/controllers/models_controller.rb.tt +4 -4
- data/lib/generators/ruby_llm/chat_ui/templates/jobs/chat_response_job.rb.tt +6 -6
- data/lib/generators/ruby_llm/chat_ui/templates/views/chats/_chat.html.erb.tt +4 -4
- data/lib/generators/ruby_llm/chat_ui/templates/views/chats/_form.html.erb.tt +5 -5
- data/lib/generators/ruby_llm/chat_ui/templates/views/chats/index.html.erb.tt +5 -5
- data/lib/generators/ruby_llm/chat_ui/templates/views/chats/new.html.erb.tt +4 -4
- data/lib/generators/ruby_llm/chat_ui/templates/views/chats/show.html.erb.tt +8 -8
- data/lib/generators/ruby_llm/chat_ui/templates/views/messages/_form.html.erb.tt +5 -5
- data/lib/generators/ruby_llm/chat_ui/templates/views/messages/_message.html.erb.tt +9 -6
- data/lib/generators/ruby_llm/chat_ui/templates/views/messages/_tool_calls.html.erb.tt +7 -0
- data/lib/generators/ruby_llm/chat_ui/templates/views/messages/create.turbo_stream.erb.tt +5 -5
- data/lib/generators/ruby_llm/chat_ui/templates/views/models/_model.html.erb.tt +9 -9
- data/lib/generators/ruby_llm/chat_ui/templates/views/models/index.html.erb.tt +4 -6
- data/lib/generators/ruby_llm/chat_ui/templates/views/models/show.html.erb.tt +11 -11
- data/lib/generators/ruby_llm/generator_helpers.rb +131 -87
- data/lib/generators/ruby_llm/install/install_generator.rb +75 -79
- data/lib/generators/ruby_llm/install/templates/initializer.rb.tt +1 -1
- data/lib/generators/ruby_llm/upgrade_to_v1_7/upgrade_to_v1_7_generator.rb +88 -85
- data/lib/ruby_llm/active_record/acts_as.rb +11 -2
- data/lib/ruby_llm/connection.rb +1 -1
- data/lib/ruby_llm/version.rb +1 -1
- metadata +2 -1
@@ -5,117 +5,120 @@ require 'rails/generators/active_record'
|
|
5
5
|
require_relative '../generator_helpers'
|
6
6
|
|
7
7
|
module RubyLLM
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
8
|
+
module Generators
|
9
|
+
# Generator to upgrade existing RubyLLM apps to v1.7 with new Rails-like API
|
10
|
+
class UpgradeToV17Generator < Rails::Generators::Base
|
11
|
+
include Rails::Generators::Migration
|
12
|
+
include RubyLLM::GeneratorHelpers
|
13
|
+
|
14
|
+
namespace 'ruby_llm:upgrade_to_v1_7'
|
15
|
+
source_root File.expand_path('templates', __dir__)
|
16
|
+
|
17
|
+
# Override source_paths to include install templates
|
18
|
+
def self.source_paths
|
19
|
+
[
|
20
|
+
File.expand_path('templates', __dir__),
|
21
|
+
File.expand_path('../install/templates', __dir__)
|
22
|
+
]
|
23
|
+
end
|
22
24
|
|
23
|
-
|
25
|
+
argument :model_mappings, type: :array, default: [], banner: 'chat:ChatName message:MessageName ...'
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
+
desc 'Upgrades existing RubyLLM apps to v1.7 with new Rails-like API\n' \
|
28
|
+
'Usage: rails g ruby_llm:upgrade_to_v1_7 [chat:ChatName] [message:MessageName] ...'
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
def self.next_migration_number(dirname)
|
31
|
+
::ActiveRecord::Generators::Base.next_migration_number(dirname)
|
32
|
+
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
+
def create_migration_file
|
35
|
+
@model_table_already_existed = table_exists?(table_name_for(model_model_name))
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
# First check if models table exists, if not create it
|
38
|
+
unless @model_table_already_existed
|
39
|
+
migration_template 'create_models_migration.rb.tt',
|
40
|
+
"db/migrate/create_#{table_name_for(model_model_name)}.rb",
|
41
|
+
migration_version: migration_version,
|
42
|
+
model_model_name: model_model_name
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
+
sleep 1 # Ensure different timestamp
|
45
|
+
end
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
47
|
+
migration_template 'migration.rb.tt',
|
48
|
+
'db/migrate/migrate_to_ruby_llm_model_references.rb',
|
49
|
+
migration_version: migration_version,
|
50
|
+
chat_model_name: chat_model_name,
|
51
|
+
message_model_name: message_model_name,
|
52
|
+
tool_call_model_name: tool_call_model_name,
|
53
|
+
model_model_name: model_model_name,
|
54
|
+
model_table_already_existed: @model_table_already_existed
|
55
|
+
end
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
+
def create_model_file
|
58
|
+
create_namespace_modules
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
+
template 'model_model.rb.tt', "app/models/#{model_model_name.underscore}.rb"
|
61
|
+
end
|
60
62
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
def update_existing_models
|
64
|
+
update_model_acts_as(chat_model_name, 'acts_as_chat', acts_as_chat_declaration)
|
65
|
+
update_model_acts_as(message_model_name, 'acts_as_message', acts_as_message_declaration)
|
66
|
+
update_model_acts_as(tool_call_model_name, 'acts_as_tool_call', acts_as_tool_call_declaration)
|
67
|
+
end
|
66
68
|
|
67
|
-
|
68
|
-
|
69
|
+
def update_initializer
|
70
|
+
initializer_path = 'config/initializers/ruby_llm.rb'
|
69
71
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
unless File.exist?(initializer_path)
|
73
|
+
say_status :warning, 'No initializer found. Creating one...', :yellow
|
74
|
+
template 'initializer.rb.tt', initializer_path
|
75
|
+
return
|
76
|
+
end
|
75
77
|
|
76
|
-
|
78
|
+
initializer_content = File.read(initializer_path)
|
77
79
|
|
78
|
-
|
80
|
+
return if initializer_content.include?('config.use_new_acts_as')
|
79
81
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
inject_into_file initializer_path, before: /^end/ do
|
83
|
+
lines = ["\n # Enable the new Rails-like API", ' config.use_new_acts_as = true']
|
84
|
+
lines << " config.model_registry_class = \"#{model_model_name}\"" if model_model_name != 'Model'
|
85
|
+
lines << "\n"
|
86
|
+
lines.join("\n")
|
87
|
+
end
|
85
88
|
end
|
86
|
-
end
|
87
89
|
|
88
|
-
|
89
|
-
|
90
|
-
|
90
|
+
def show_next_steps
|
91
|
+
say_status :success, 'Upgrade prepared!', :green
|
92
|
+
say <<~INSTRUCTIONS
|
91
93
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
94
|
+
Next steps:
|
95
|
+
1. Review the generated migrations
|
96
|
+
2. Run: rails db:migrate
|
97
|
+
3. Update your code to use the new API: #{chat_model_name}.create! now has the same signature as RubyLLM.chat
|
96
98
|
|
97
|
-
|
98
|
-
|
99
|
+
⚠️ If you get "undefined method 'acts_as_model'" during migration:
|
100
|
+
Add this to config/application.rb BEFORE your Application class:
|
99
101
|
|
100
|
-
|
101
|
-
|
102
|
-
|
102
|
+
RubyLLM.configure do |config|
|
103
|
+
config.use_new_acts_as = true
|
104
|
+
end
|
103
105
|
|
104
|
-
|
106
|
+
📚 See the full migration guide: https://rubyllm.com/upgrading-to-1-7/
|
105
107
|
|
106
|
-
|
107
|
-
|
108
|
+
INSTRUCTIONS
|
109
|
+
end
|
108
110
|
|
109
|
-
|
111
|
+
private
|
110
112
|
|
111
|
-
|
112
|
-
|
113
|
-
|
113
|
+
def update_model_acts_as(model_name, old_acts_as, new_acts_as)
|
114
|
+
model_path = "app/models/#{model_name.underscore}.rb"
|
115
|
+
return unless File.exist?(Rails.root.join(model_path))
|
114
116
|
|
115
|
-
|
116
|
-
|
117
|
+
content = File.read(Rails.root.join(model_path))
|
118
|
+
return unless content.match?(/^\s*#{old_acts_as}/)
|
117
119
|
|
118
|
-
|
120
|
+
gsub_file model_path, /^\s*#{old_acts_as}.*$/, " #{new_acts_as}"
|
121
|
+
end
|
119
122
|
end
|
120
123
|
end
|
121
124
|
end
|
@@ -45,10 +45,12 @@ module RubyLLM
|
|
45
45
|
has_many messages,
|
46
46
|
-> { order(created_at: :asc) },
|
47
47
|
class_name: self.message_class,
|
48
|
+
foreign_key: ActiveSupport::Inflector.foreign_key(table_name.singularize),
|
48
49
|
dependent: :destroy
|
49
50
|
|
50
51
|
belongs_to model,
|
51
52
|
class_name: self.model_class,
|
53
|
+
foreign_key: ActiveSupport::Inflector.foreign_key(model.to_s.singularize),
|
52
54
|
optional: true
|
53
55
|
|
54
56
|
delegate :add_message, to: :to_llm
|
@@ -78,7 +80,9 @@ module RubyLLM
|
|
78
80
|
validates :provider, presence: true
|
79
81
|
validates :name, presence: true
|
80
82
|
|
81
|
-
has_many chats,
|
83
|
+
has_many chats,
|
84
|
+
class_name: self.chat_class,
|
85
|
+
foreign_key: ActiveSupport::Inflector.foreign_key(table_name.singularize)
|
82
86
|
|
83
87
|
define_method :chats_association do
|
84
88
|
send(chats_association_name)
|
@@ -102,10 +106,12 @@ module RubyLLM
|
|
102
106
|
|
103
107
|
belongs_to chat,
|
104
108
|
class_name: self.chat_class,
|
109
|
+
foreign_key: ActiveSupport::Inflector.foreign_key(chat.to_s.singularize),
|
105
110
|
touch: touch_chat
|
106
111
|
|
107
112
|
has_many tool_calls,
|
108
113
|
class_name: self.tool_call_class,
|
114
|
+
foreign_key: ActiveSupport::Inflector.foreign_key(table_name.singularize),
|
109
115
|
dependent: :destroy
|
110
116
|
|
111
117
|
belongs_to :parent_tool_call,
|
@@ -120,6 +126,7 @@ module RubyLLM
|
|
120
126
|
|
121
127
|
belongs_to model,
|
122
128
|
class_name: self.model_class,
|
129
|
+
foreign_key: ActiveSupport::Inflector.foreign_key(model.to_s.singularize),
|
123
130
|
optional: true
|
124
131
|
|
125
132
|
delegate :tool_call?, :tool_result?, to: :to_llm
|
@@ -147,10 +154,12 @@ module RubyLLM
|
|
147
154
|
self.result_class = (result_class || self.message_class).to_s
|
148
155
|
|
149
156
|
belongs_to message,
|
150
|
-
class_name: self.message_class
|
157
|
+
class_name: self.message_class,
|
158
|
+
foreign_key: ActiveSupport::Inflector.foreign_key(message.to_s.singularize)
|
151
159
|
|
152
160
|
has_one result,
|
153
161
|
class_name: self.result_class,
|
162
|
+
foreign_key: ActiveSupport::Inflector.foreign_key(table_name.singularize),
|
154
163
|
dependent: :nullify
|
155
164
|
|
156
165
|
define_method :message_association do
|
data/lib/ruby_llm/connection.rb
CHANGED
data/lib/ruby_llm/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_llm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carmine Paolino
|
@@ -149,6 +149,7 @@ files:
|
|
149
149
|
- lib/generators/ruby_llm/chat_ui/templates/views/messages/_content.html.erb.tt
|
150
150
|
- lib/generators/ruby_llm/chat_ui/templates/views/messages/_form.html.erb.tt
|
151
151
|
- lib/generators/ruby_llm/chat_ui/templates/views/messages/_message.html.erb.tt
|
152
|
+
- lib/generators/ruby_llm/chat_ui/templates/views/messages/_tool_calls.html.erb.tt
|
152
153
|
- lib/generators/ruby_llm/chat_ui/templates/views/messages/create.turbo_stream.erb.tt
|
153
154
|
- lib/generators/ruby_llm/chat_ui/templates/views/models/_model.html.erb.tt
|
154
155
|
- lib/generators/ruby_llm/chat_ui/templates/views/models/index.html.erb.tt
|