dify_llm 1.6.4 → 1.7.0

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/generators/ruby_llm/chat_ui/chat_ui_generator.rb +127 -0
  4. data/lib/generators/ruby_llm/chat_ui/templates/controllers/chats_controller.rb.tt +39 -0
  5. data/lib/generators/ruby_llm/chat_ui/templates/controllers/messages_controller.rb.tt +24 -0
  6. data/lib/generators/ruby_llm/chat_ui/templates/controllers/models_controller.rb.tt +14 -0
  7. data/lib/generators/ruby_llm/chat_ui/templates/jobs/chat_response_job.rb.tt +12 -0
  8. data/lib/generators/ruby_llm/chat_ui/templates/views/chats/_chat.html.erb.tt +16 -0
  9. data/lib/generators/ruby_llm/chat_ui/templates/views/chats/_form.html.erb.tt +29 -0
  10. data/lib/generators/ruby_llm/chat_ui/templates/views/chats/index.html.erb.tt +16 -0
  11. data/lib/generators/ruby_llm/chat_ui/templates/views/chats/new.html.erb.tt +11 -0
  12. data/lib/generators/ruby_llm/chat_ui/templates/views/chats/show.html.erb.tt +23 -0
  13. data/lib/generators/ruby_llm/chat_ui/templates/views/messages/_form.html.erb.tt +21 -0
  14. data/lib/generators/ruby_llm/chat_ui/templates/views/messages/_message.html.erb.tt +10 -0
  15. data/lib/generators/ruby_llm/chat_ui/templates/views/messages/create.turbo_stream.erb.tt +9 -0
  16. data/lib/generators/ruby_llm/chat_ui/templates/views/models/_model.html.erb.tt +16 -0
  17. data/lib/generators/ruby_llm/chat_ui/templates/views/models/index.html.erb.tt +30 -0
  18. data/lib/generators/ruby_llm/chat_ui/templates/views/models/show.html.erb.tt +18 -0
  19. data/lib/generators/ruby_llm/install/install_generator.rb +227 -0
  20. data/lib/generators/ruby_llm/install/templates/chat_model.rb.tt +1 -1
  21. data/lib/generators/ruby_llm/install/templates/create_chats_migration.rb.tt +3 -3
  22. data/lib/generators/ruby_llm/install/templates/create_messages_migration.rb.tt +6 -6
  23. data/lib/generators/ruby_llm/install/templates/create_models_migration.rb.tt +3 -3
  24. data/lib/generators/ruby_llm/install/templates/create_tool_calls_migration.rb.tt +5 -5
  25. data/lib/generators/ruby_llm/install/templates/initializer.rb.tt +6 -3
  26. data/lib/generators/ruby_llm/install/templates/message_model.rb.tt +1 -1
  27. data/lib/generators/ruby_llm/install/templates/model_model.rb.tt +1 -1
  28. data/lib/generators/ruby_llm/install/templates/tool_call_model.rb.tt +1 -1
  29. data/lib/generators/ruby_llm/{migrate_model_fields → upgrade_to_v1_7}/templates/migration.rb.tt +16 -21
  30. data/lib/generators/ruby_llm/upgrade_to_v1_7/upgrade_to_v1_7_generator.rb +170 -0
  31. data/lib/ruby_llm/active_record/acts_as.rb +88 -58
  32. data/lib/ruby_llm/active_record/chat_methods.rb +51 -30
  33. data/lib/ruby_llm/active_record/message_methods.rb +2 -2
  34. data/lib/ruby_llm/aliases.json +0 -8
  35. data/lib/ruby_llm/configuration.rb +5 -0
  36. data/lib/ruby_llm/models.json +1724 -1497
  37. data/lib/ruby_llm/railtie.rb +4 -12
  38. data/lib/ruby_llm/version.rb +1 -1
  39. data/lib/ruby_llm.rb +2 -1
  40. metadata +23 -6
  41. data/lib/generators/ruby_llm/install/templates/create_chats_legacy_migration.rb.tt +0 -8
  42. data/lib/generators/ruby_llm/install/templates/create_messages_legacy_migration.rb.tt +0 -16
  43. data/lib/generators/ruby_llm/install_generator.rb +0 -184
  44. data/lib/generators/ruby_llm/migrate_model_fields_generator.rb +0 -84
@@ -5,15 +5,13 @@ module RubyLLM
5
5
  class Railtie < Rails::Railtie
6
6
  initializer 'ruby_llm.inflections' do
7
7
  ActiveSupport::Inflector.inflections(:en) do |inflect|
8
- inflect.acronym 'RubyLLM'
8
+ inflect.acronym 'LLM'
9
9
  end
10
10
  end
11
11
 
12
12
  initializer 'ruby_llm.active_record' do
13
13
  ActiveSupport.on_load :active_record do
14
- model_registry_class = RubyLLM.config.model_registry_class
15
-
16
- if model_registry_class
14
+ if RubyLLM.config.use_new_acts_as
17
15
  require 'ruby_llm/active_record/acts_as'
18
16
  ::ActiveRecord::Base.include RubyLLM::ActiveRecord::ActsAs
19
17
  else
@@ -21,19 +19,13 @@ module RubyLLM
21
19
  ::ActiveRecord::Base.include RubyLLM::ActiveRecord::ActsAsLegacy
22
20
 
23
21
  Rails.logger.warn(
24
- 'RubyLLM: String-based model fields are deprecated and will be removed in RubyLLM 2.0.0. ' \
25
- 'Please migrate to the DB-backed model registry. ' \
26
- "Run 'rails generate ruby_llm:migrate_model_fields' to upgrade."
22
+ "\n!!! RubyLLM's legacy acts_as API is deprecated and will be removed in RubyLLM 2.0.0. " \
23
+ "Please consult the migration guide at https://rubyllm.com/upgrading-to-1-7/\n"
27
24
  )
28
25
  end
29
26
  end
30
27
  end
31
28
 
32
- generators do
33
- require 'generators/ruby_llm/install_generator'
34
- require 'generators/ruby_llm/migrate_model_fields_generator'
35
- end
36
-
37
29
  rake_tasks do
38
30
  load 'tasks/ruby_llm.rake'
39
31
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyLLM
4
- VERSION = '1.6.4'
4
+ VERSION = '1.7.0'
5
5
  end
data/lib/ruby_llm.rb CHANGED
@@ -23,7 +23,8 @@ loader.inflector.inflect(
23
23
  'gpustack' => 'GPUStack',
24
24
  'mistral' => 'Mistral',
25
25
  'vertexai' => 'VertexAI',
26
- 'pdf' => 'PDF'
26
+ 'pdf' => 'PDF',
27
+ 'UI' => 'UI'
27
28
  )
28
29
  loader.ignore("#{__dir__}/tasks")
29
30
  loader.ignore("#{__dir__}/generators")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dify_llm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.4
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carmine Paolino
@@ -136,10 +136,25 @@ extra_rdoc_files: []
136
136
  files:
137
137
  - LICENSE
138
138
  - README.md
139
+ - lib/generators/ruby_llm/chat_ui/chat_ui_generator.rb
140
+ - lib/generators/ruby_llm/chat_ui/templates/controllers/chats_controller.rb.tt
141
+ - lib/generators/ruby_llm/chat_ui/templates/controllers/messages_controller.rb.tt
142
+ - lib/generators/ruby_llm/chat_ui/templates/controllers/models_controller.rb.tt
143
+ - lib/generators/ruby_llm/chat_ui/templates/jobs/chat_response_job.rb.tt
144
+ - lib/generators/ruby_llm/chat_ui/templates/views/chats/_chat.html.erb.tt
145
+ - lib/generators/ruby_llm/chat_ui/templates/views/chats/_form.html.erb.tt
146
+ - lib/generators/ruby_llm/chat_ui/templates/views/chats/index.html.erb.tt
147
+ - lib/generators/ruby_llm/chat_ui/templates/views/chats/new.html.erb.tt
148
+ - lib/generators/ruby_llm/chat_ui/templates/views/chats/show.html.erb.tt
149
+ - lib/generators/ruby_llm/chat_ui/templates/views/messages/_form.html.erb.tt
150
+ - lib/generators/ruby_llm/chat_ui/templates/views/messages/_message.html.erb.tt
151
+ - lib/generators/ruby_llm/chat_ui/templates/views/messages/create.turbo_stream.erb.tt
152
+ - lib/generators/ruby_llm/chat_ui/templates/views/models/_model.html.erb.tt
153
+ - lib/generators/ruby_llm/chat_ui/templates/views/models/index.html.erb.tt
154
+ - lib/generators/ruby_llm/chat_ui/templates/views/models/show.html.erb.tt
155
+ - lib/generators/ruby_llm/install/install_generator.rb
139
156
  - lib/generators/ruby_llm/install/templates/chat_model.rb.tt
140
- - lib/generators/ruby_llm/install/templates/create_chats_legacy_migration.rb.tt
141
157
  - lib/generators/ruby_llm/install/templates/create_chats_migration.rb.tt
142
- - lib/generators/ruby_llm/install/templates/create_messages_legacy_migration.rb.tt
143
158
  - lib/generators/ruby_llm/install/templates/create_messages_migration.rb.tt
144
159
  - lib/generators/ruby_llm/install/templates/create_models_migration.rb.tt
145
160
  - lib/generators/ruby_llm/install/templates/create_tool_calls_migration.rb.tt
@@ -147,9 +162,8 @@ files:
147
162
  - lib/generators/ruby_llm/install/templates/message_model.rb.tt
148
163
  - lib/generators/ruby_llm/install/templates/model_model.rb.tt
149
164
  - lib/generators/ruby_llm/install/templates/tool_call_model.rb.tt
150
- - lib/generators/ruby_llm/install_generator.rb
151
- - lib/generators/ruby_llm/migrate_model_fields/templates/migration.rb.tt
152
- - lib/generators/ruby_llm/migrate_model_fields_generator.rb
165
+ - lib/generators/ruby_llm/upgrade_to_v1_7/templates/migration.rb.tt
166
+ - lib/generators/ruby_llm/upgrade_to_v1_7/upgrade_to_v1_7_generator.rb
153
167
  - lib/ruby_llm.rb
154
168
  - lib/ruby_llm/active_record/acts_as.rb
155
169
  - lib/ruby_llm/active_record/acts_as_legacy.rb
@@ -271,6 +285,9 @@ metadata:
271
285
  documentation_uri: https://rubyllm.com
272
286
  bug_tracker_uri: https://github.com/crmne/ruby_llm/issues
273
287
  rubygems_mfa_required: 'true'
288
+ post_install_message: |
289
+ Upgrading from RubyLLM <= 1.6.x? Check the upgrade guide for new features and migration instructions
290
+ --> https://rubyllm.com/upgrading-to-1-7/
274
291
  rdoc_options: []
275
292
  require_paths:
276
293
  - lib
@@ -1,8 +0,0 @@
1
- class Create<%= options[:chat_model_name].pluralize %> < ActiveRecord::Migration<%= migration_version %>
2
- def change
3
- create_table :<%= options[:chat_model_name].tableize %> do |t|
4
- t.string :model_id
5
- t.timestamps
6
- end
7
- end
8
- end
@@ -1,16 +0,0 @@
1
- class Create<%= options[:message_model_name].pluralize %> < ActiveRecord::Migration<%= migration_version %>
2
- def change
3
- create_table :<%= options[:message_model_name].tableize %> do |t|
4
- t.references :<%= options[:chat_model_name].tableize.singularize %>, null: false, foreign_key: true
5
- t.string :role, null: false
6
- t.text :content
7
- t.string :model_id
8
- t.integer :input_tokens
9
- t.integer :output_tokens
10
- t.references :<%= options[:tool_call_model_name].tableize.singularize %>, foreign_key: true
11
- t.timestamps
12
- end
13
-
14
- add_index :<%= options[:message_model_name].tableize %>, :role
15
- end
16
- end
@@ -1,184 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails/generators'
4
- require 'rails/generators/active_record'
5
-
6
- module RubyLLM
7
- # Generator for RubyLLM Rails models and migrations
8
- class InstallGenerator < Rails::Generators::Base
9
- include Rails::Generators::Migration
10
-
11
- namespace 'ruby_llm:install'
12
-
13
- source_root File.expand_path('install/templates', __dir__)
14
-
15
- class_option :chat_model_name, type: :string, default: 'Chat',
16
- desc: 'Name of the Chat model class'
17
- class_option :message_model_name, type: :string, default: 'Message',
18
- desc: 'Name of the Message model class'
19
- class_option :tool_call_model_name, type: :string, default: 'ToolCall',
20
- desc: 'Name of the ToolCall model class'
21
- class_option :model_model_name, type: :string, default: 'Model',
22
- desc: 'Name of the Model model class (for model registry)'
23
- class_option :skip_model_registry, type: :boolean, default: false,
24
- desc: 'Skip creating Model registry (uses string fields instead)'
25
- class_option :skip_active_storage, type: :boolean, default: false,
26
- desc: 'Skip ActiveStorage installation and attachment setup'
27
-
28
- desc 'Creates models and migrations for RubyLLM Rails integration with ActiveStorage for file attachments'
29
-
30
- def self.next_migration_number(dirname)
31
- ::ActiveRecord::Generators::Base.next_migration_number(dirname)
32
- end
33
-
34
- def migration_version
35
- "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
36
- end
37
-
38
- def postgresql?
39
- ::ActiveRecord::Base.connection.adapter_name.downcase.include?('postgresql')
40
- rescue StandardError
41
- false
42
- end
43
-
44
- def acts_as_chat_declaration
45
- acts_as_chat_params = []
46
- if options[:message_model_name] != 'Message'
47
- acts_as_chat_params << "message_class: \"#{options[:message_model_name]}\""
48
- end
49
- if options[:tool_call_model_name] != 'ToolCall'
50
- acts_as_chat_params << "tool_call_class: \"#{options[:tool_call_model_name]}\""
51
- end
52
- if acts_as_chat_params.any?
53
- "acts_as_chat #{acts_as_chat_params.join(', ')}"
54
- else
55
- 'acts_as_chat'
56
- end
57
- end
58
-
59
- def acts_as_message_declaration
60
- acts_as_message_params = []
61
- acts_as_message_params << "chat_class: \"#{options[:chat_model_name]}\"" if options[:chat_model_name] != 'Chat'
62
- if options[:tool_call_model_name] != 'ToolCall'
63
- acts_as_message_params << "tool_call_class: \"#{options[:tool_call_model_name]}\""
64
- end
65
- if acts_as_message_params.any?
66
- "acts_as_message #{acts_as_message_params.join(', ')}"
67
- else
68
- 'acts_as_message'
69
- end
70
- end
71
-
72
- def acts_as_tool_call_declaration
73
- acts_as_tool_call_params = []
74
- if options[:message_model_name] != 'Message'
75
- acts_as_tool_call_params << "message_class: \"#{options[:message_model_name]}\""
76
- end
77
- if acts_as_tool_call_params.any?
78
- "acts_as_tool_call #{acts_as_tool_call_params.join(', ')}"
79
- else
80
- 'acts_as_tool_call'
81
- end
82
- end
83
-
84
- def acts_as_model_declaration
85
- 'acts_as_model'
86
- end
87
-
88
- def skip_model_registry?
89
- options[:skip_model_registry]
90
- end
91
-
92
- def create_migration_files
93
- # Create migrations with timestamps to ensure proper order
94
- # First create chats table
95
- template_file = skip_model_registry? ? 'create_chats_legacy_migration.rb.tt' : 'create_chats_migration.rb.tt'
96
- migration_template template_file,
97
- "db/migrate/create_#{options[:chat_model_name].tableize}.rb"
98
-
99
- # Then create messages table (must come before tool_calls due to foreign key)
100
- sleep 1 # Ensure different timestamp
101
- template_file = if skip_model_registry?
102
- 'create_messages_legacy_migration.rb.tt'
103
- else
104
- 'create_messages_migration.rb.tt'
105
- end
106
- migration_template template_file,
107
- "db/migrate/create_#{options[:message_model_name].tableize}.rb"
108
-
109
- # Then create tool_calls table (references messages)
110
- sleep 1 # Ensure different timestamp
111
- migration_template 'create_tool_calls_migration.rb.tt',
112
- "db/migrate/create_#{options[:tool_call_model_name].tableize}.rb"
113
-
114
- # Create models table unless using legacy or skipping
115
- return if skip_model_registry?
116
-
117
- sleep 1 # Ensure different timestamp
118
- migration_template 'create_models_migration.rb.tt',
119
- "db/migrate/create_#{options[:model_model_name].tableize}.rb"
120
- end
121
-
122
- def create_model_files
123
- template 'chat_model.rb.tt', "app/models/#{options[:chat_model_name].underscore}.rb"
124
- template 'message_model.rb.tt', "app/models/#{options[:message_model_name].underscore}.rb"
125
- template 'tool_call_model.rb.tt', "app/models/#{options[:tool_call_model_name].underscore}.rb"
126
-
127
- # Only create Model class if not using legacy
128
- return if skip_model_registry?
129
-
130
- template 'model_model.rb.tt', "app/models/#{options[:model_model_name].underscore}.rb"
131
- end
132
-
133
- def create_initializer
134
- template 'initializer.rb.tt', 'config/initializers/ruby_llm.rb'
135
- end
136
-
137
- def install_active_storage
138
- return if options[:skip_active_storage]
139
-
140
- say ' Installing ActiveStorage for file attachments...', :cyan
141
- rails_command 'active_storage:install'
142
- end
143
-
144
- def show_install_info
145
- say "\n ✅ RubyLLM installed!", :green
146
-
147
- say ' ✅ ActiveStorage configured for file attachments support', :green unless options[:skip_active_storage]
148
-
149
- say "\n Next steps:", :yellow
150
- say ' 1. Run: rails db:migrate'
151
- say ' 2. Set your API keys in config/initializers/ruby_llm.rb'
152
-
153
- if skip_model_registry?
154
- say " 3. Start chatting: #{options[:chat_model_name]}.create!(model_id: 'gpt-4.1-nano').ask('Hello!')"
155
-
156
- say "\n Note: Using string-based model fields", :yellow
157
- say ' For rich model metadata, consider adding the model registry:'
158
- say ' rails generate ruby_llm:migrate_model_fields'
159
- else
160
- say " 3. Start chatting: #{options[:chat_model_name]}.create!(model: 'gpt-4.1-nano').ask('Hello!')"
161
-
162
- say "\n 🚀 Model registry is database-backed!", :cyan
163
- say ' Models automatically load from the database'
164
- say ' Pass model names as strings - RubyLLM handles the rest!'
165
- end
166
- say " Specify provider when needed: Chat.create!(model: 'gemini-2.5-flash', provider: 'vertexai')"
167
-
168
- if options[:skip_active_storage]
169
- say "\n 📎 Note: ActiveStorage was skipped", :yellow
170
- say ' File attachments won\'t work without ActiveStorage.'
171
- say ' To enable later:'
172
- say ' 1. Run: rails active_storage:install && rails db:migrate'
173
- say " 2. Add to your #{options[:message_model_name]} model: has_many_attached :attachments"
174
- end
175
-
176
- say "\n 📚 Documentation: https://rubyllm.com", :cyan
177
-
178
- say "\n ❤️ Love RubyLLM?", :magenta
179
- say ' • ⭐ Star on GitHub: https://github.com/crmne/ruby_llm'
180
- say ' • 🐦 Follow for updates: https://x.com/paolino'
181
- say "\n"
182
- end
183
- end
184
- end
@@ -1,84 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails/generators'
4
- require 'rails/generators/active_record'
5
-
6
- module RubyLLM
7
- class MigrateModelFieldsGenerator < Rails::Generators::Base # rubocop:disable Style/Documentation
8
- include Rails::Generators::Migration
9
-
10
- namespace 'ruby_llm:migrate_model_fields'
11
- source_root File.expand_path('migrate_model_fields/templates', __dir__)
12
-
13
- class_option :chat_model_name, type: :string, default: 'Chat'
14
- class_option :message_model_name, type: :string, default: 'Message'
15
- class_option :model_model_name, type: :string, default: 'Model'
16
- class_option :tool_call_model_name, type: :string, default: 'ToolCall'
17
-
18
- def self.next_migration_number(dirname)
19
- ::ActiveRecord::Generators::Base.next_migration_number(dirname)
20
- end
21
-
22
- def create_migration_file
23
- migration_template 'migration.rb.tt',
24
- 'db/migrate/migrate_to_ruby_llm_model_references.rb',
25
- migration_version: migration_version
26
- end
27
-
28
- def create_model_file
29
- # Check if Model file already exists
30
- model_path = "app/models/#{options[:model_model_name].underscore}.rb"
31
-
32
- if File.exist?(Rails.root.join(model_path))
33
- say_status :skip, model_path, :yellow
34
- else
35
- create_file model_path do
36
- <<~RUBY
37
- class #{options[:model_model_name]} < ApplicationRecord
38
- acts_as_model
39
- end
40
- RUBY
41
- end
42
- end
43
- end
44
-
45
- def acts_as_model_declaration
46
- 'acts_as_model'
47
- end
48
-
49
- def update_initializer
50
- say_status :info, 'Update your config/initializers/ruby_llm.rb:', :yellow
51
- say <<~INSTRUCTIONS
52
-
53
- Add this line to enable the DB-backed model registry:
54
- config.model_registry_class = "#{options[:model_model_name]}"
55
-
56
- INSTRUCTIONS
57
- end
58
-
59
- def show_next_steps
60
- say_status :success, 'Migration created!', :green
61
- say <<~INSTRUCTIONS
62
-
63
- Next steps:
64
- 1. Review the migration: db/migrate/*_migrate_to_ruby_llm_model_references.rb
65
- 2. Run: rails db:migrate
66
- 3. Update config/initializers/ruby_llm.rb as shown above
67
- 4. Test your application thoroughly
68
-
69
- The migration will:
70
- - Create the Models table if it doesn't exist
71
- - Load all models from models.json
72
- - Migrate your existing data to use foreign keys
73
- - Preserve all existing data (string columns renamed to model_id_string)
74
-
75
- INSTRUCTIONS
76
- end
77
-
78
- private
79
-
80
- def migration_version
81
- "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
82
- end
83
- end
84
- end