class Ragdoll::Core::Configuration
Constants
- DEFAULT
Public Class Methods
Source
# File lib/ragdoll/core/configuration.rb, line 147 def self.load(path: nil) path ||= DEFAULT[:config_filepath] raise ConfigurationFileNotFoundError, "Configuration file not found: #{path}" unless File.exist?(path) new(YAML.safe_load_file(path) || {}) rescue Errno::ENOENT raise ConfigurationFileNotFoundError, "Configuration file not found: #{path}" rescue StandardError => e raise ConfigurationLoadUnknownError, "Failed to load configuration from #{path}: #{e.message}" end
Source
# File lib/ragdoll/core/configuration.rb, line 141 def initialize(config = {}) merged_config = deep_merge(self.class::DEFAULT, config) resolved_config = resolve_procs(merged_config, []) @config = OpenStruct.new(resolved_config) end
Public Instance Methods
Source
# File lib/ragdoll/core/configuration.rb, line 212 def embedding_model(content_type = :text) @config.models[:embedding][content_type] || @config.models[:embedding][:text] end
Resolve embedding model for content type
Source
# File lib/ragdoll/core/configuration.rb, line 222 def method_missing(method_name, *args, &block) @config.send(method_name, *args, &block) end
Enable method delegation to the internal OpenStruct
Source
# File lib/ragdoll/core/configuration.rb, line 180 def parse_provider_model(provider_model_string) return { provider: nil, model: nil } if provider_model_string.nil? || provider_model_string.empty? parts = provider_model_string.split("/", 2) if parts.length == 2 { provider: parts[0].to_sym, model: parts[1] } else # If no slash, let RubyLLM determine provider from model name { provider: nil, model: provider_model_string } end end
Parse a provider/model string into its components Format: “provider/model” -> { provider: :provider, model: “model” } Format: “model” -> { provider: nil, model: “model” } (RubyLLM determines provider)
Source
# File lib/ragdoll/core/configuration.rb, line 217 def prompt_template(template_name = :rag_enhancement) @config.prompt_templates[template_name] end
Get prompt template
Source
# File lib/ragdoll/core/configuration.rb, line 206 def provider_credentials(provider = nil) provider ||= @config.llm_providers[:default_provider] @config.llm_providers[provider] || {} end
Get provider credentials for a given provider
Source
# File lib/ragdoll/core/configuration.rb, line 194 def resolve_model(task_type) case task_type when :embedding @config.models[:embedding] when :text, :summary, :keywords, :default @config.models[:text_generation][task_type] || @config.models[:text_generation][:default] else @config.models[:text_generation][:default] end end
Resolve model with inheritance support Returns the model string for a given task, with inheritance from default
Source
# File lib/ragdoll/core/configuration.rb, line 226 def respond_to_missing?(method_name, include_private = false) @config.respond_to?(method_name, include_private) || super end
Calls superclass method
Source
# File lib/ragdoll/core/configuration.rb, line 159 def save(path: nil) if path.nil? path = @config.config_filepath else save_filepath = @config.config_filepath @config.config_filepath = path end FileUtils.mkdir_p(File.dirname(path)) File.write(path, @config.to_yaml) rescue StandardError => e @config.config_filepath = save_filepath unless save_filepath.nil? raise ConfigurationSaveError, "Failed to save configuration to #{path}: #{e.message}" end