Class: Ragdoll::ConfigurationService
- Inherits:
-
Object
- Object
- Ragdoll::ConfigurationService
- Defined in:
- app/services/ragdoll/configuration_service.rb
Overview
Service class for centralized configuration logic Provides a clean interface for accessing configuration with validation
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Expose config for access.
Instance Method Summary collapse
-
#chunking_config(content_type = :text) ⇒ Object
Get chunking configuration for content type.
-
#initialize(config = nil) ⇒ ConfigurationService
constructor
A new instance of ConfigurationService.
-
#prompt_template(template_name = :rag_enhancement) ⇒ Object
Get prompt template with validation.
-
#provider_credentials(provider = nil) ⇒ Object
Get provider credentials with fallback to default provider.
-
#resolve_model(task_type, content_type = :text) ⇒ Object
Resolve model for a task with inheritance support.
-
#search_config ⇒ Object
Get search configuration.
-
#valid? ⇒ Boolean
Check if configuration is valid without raising.
-
#validate! ⇒ Object
Validate configuration completeness.
Constructor Details
#initialize(config = nil) ⇒ ConfigurationService
Returns a new instance of ConfigurationService.
7 8 9 |
# File 'app/services/ragdoll/configuration_service.rb', line 7 def initialize(config = nil) @config = config || Ragdoll.config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Expose config for access
12 13 14 |
# File 'app/services/ragdoll/configuration_service.rb', line 12 def config @config end |
Instance Method Details
#chunking_config(content_type = :text) ⇒ Object
Get chunking configuration for content type
43 44 45 46 |
# File 'app/services/ragdoll/configuration_service.rb', line 43 def chunking_config(content_type = :text) @config.processing[content_type]&.dig(:chunking) || @config.processing[:default][:chunking] end |
#prompt_template(template_name = :rag_enhancement) ⇒ Object
Get prompt template with validation
54 55 56 57 58 59 60 61 62 |
# File 'app/services/ragdoll/configuration_service.rb', line 54 def prompt_template(template_name = :rag_enhancement) template = @config.prompt_templates[template_name] if template.nil? raise Ragdoll::ConfigurationError, "Prompt template '#{template_name}' not found" end template end |
#provider_credentials(provider = nil) ⇒ Object
Get provider credentials with fallback to default provider
31 32 33 34 35 36 37 38 39 40 |
# File 'app/services/ragdoll/configuration_service.rb', line 31 def provider_credentials(provider = nil) provider ||= @config.llm_providers[:default_provider] credentials = @config.llm_providers[provider] if credentials.nil? raise Ragdoll::ConfigurationError, "Provider '#{provider}' not configured" end credentials end |
#resolve_model(task_type, content_type = :text) ⇒ Object
Resolve model for a task with inheritance support
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/services/ragdoll/configuration_service.rb', line 17 def resolve_model(task_type, content_type = :text) case task_type when :embedding @config.(content_type) when :summary, :keywords # Check for task-specific model, fall back to default task_model = @config.models[:text_generation][task_type] task_model || @config.models[:text_generation][:default] else @config.models[:text_generation][:default] end end |
#search_config ⇒ Object
Get search configuration
49 50 51 |
# File 'app/services/ragdoll/configuration_service.rb', line 49 def search_config @config.processing[:search] end |
#valid? ⇒ Boolean
Check if configuration is valid without raising
103 104 105 106 107 108 |
# File 'app/services/ragdoll/configuration_service.rb', line 103 def valid? validate! true rescue Ragdoll::ConfigurationError false end |
#validate! ⇒ Object
Validate configuration completeness
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/services/ragdoll/configuration_service.rb', line 65 def validate! errors = [] # Check required database configuration errors << "Database password not configured" if @config.database[:password].nil? # Check default LLM provider configuration default_provider = @config.llm_providers[:default_provider] if default_provider.nil? errors << "Default LLM provider not specified" else provider_config = @config.llm_providers[default_provider] if provider_config.nil? errors << "Default provider '#{default_provider}' not configured" elsif provider_config[:api_key].nil? errors << "API key for default provider '#{default_provider}' not configured" end end # Check embedding configuration if @config.models.[:text].nil? errors << "Text embedding model not configured" end # Ensure log directory can be created log_dir = File.dirname(@config.logging[:filepath]) unless Dir.exist?(log_dir) || File.writable?(File.dirname(log_dir)) errors << "Cannot create log directory '#{log_dir}'" end unless errors.empty? raise Ragdoll::ConfigurationError, "Configuration validation failed:\n - #{errors.join("\n - ")}" end true end |