fix: use committed model registry for RubyLLM (#14067)
RubyLLM bundles a static models.json that doesn't know about models released after the gem was published. Self-hosted users configuring newer models hit ModelNotFoundError. Added a rake task that refreshes the registry from models.dev and saves to disk. ~~Called during Docker image build so every deploy gets fresh model data. Falls back silently to the bundled registry if models.dev is unreachable.~~ Commit the models.json file to code so it is available across deployments. --------- Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
24264
config/llm_models.json
Normal file
24264
config/llm_models.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -20,6 +20,7 @@ module Llm::Config
|
|||||||
end
|
end
|
||||||
|
|
||||||
def with_api_key(api_key, api_base: nil)
|
def with_api_key(api_key, api_base: nil)
|
||||||
|
initialize!
|
||||||
context = RubyLLM.context do |config|
|
context = RubyLLM.context do |config|
|
||||||
config.openai_api_key = api_key
|
config.openai_api_key = api_key
|
||||||
config.openai_api_base = api_base
|
config.openai_api_base = api_base
|
||||||
@@ -34,6 +35,7 @@ module Llm::Config
|
|||||||
RubyLLM.configure do |config|
|
RubyLLM.configure do |config|
|
||||||
config.openai_api_key = system_api_key if system_api_key.present?
|
config.openai_api_key = system_api_key if system_api_key.present?
|
||||||
config.openai_api_base = openai_endpoint.chomp('/') if openai_endpoint.present?
|
config.openai_api_base = openai_endpoint.chomp('/') if openai_endpoint.present?
|
||||||
|
config.model_registry_file = Rails.root.join('config/llm_models.json').to_s
|
||||||
config.logger = Rails.logger
|
config.logger = Rails.logger
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
17
lib/tasks/ruby_llm.rake
Normal file
17
lib/tasks/ruby_llm.rake
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# Refresh the RubyLLM model registry from models.dev and configured providers.
|
||||||
|
# Updates config/llm_models.json so new models are available without a gem upgrade.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# bundle exec rake ruby_llm:refresh_models
|
||||||
|
#
|
||||||
|
# Run this when new models are released, commit the updated config/llm_models.json.
|
||||||
|
namespace :ruby_llm do
|
||||||
|
desc 'Refresh RubyLLM model registry from models.dev'
|
||||||
|
task refresh_models: :environment do
|
||||||
|
registry_path = Rails.root.join('config/llm_models.json').to_s
|
||||||
|
puts 'Refreshing RubyLLM model registry...'
|
||||||
|
RubyLLM.models.refresh!
|
||||||
|
RubyLLM.models.save_to_json(registry_path)
|
||||||
|
puts "RubyLLM model registry updated with #{RubyLLM.models.all.size} models at #{registry_path}"
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user