Class: Ragdoll::ConfigurationController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ragdoll/configuration_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/ragdoll/configuration_controller.rb', line 5

def index
  @configuration = ::Ragdoll.configuration
  @available_providers = %w[openai anthropic google azure ollama huggingface]
  @available_models = {
    openai: ['text-embedding-3-small', 'text-embedding-3-large', 'text-embedding-ada-002'],
    anthropic: ['claude-3-haiku-20240307', 'claude-3-sonnet-20240229', 'claude-3-opus-20240229'],
    google: ['gemini-pro', 'gemini-1.5-flash', 'gemini-1.5-pro'],
    azure: ['text-embedding-3-small', 'text-embedding-3-large'],
    ollama: ['llama2', 'mistral', 'codellama'],
    huggingface: ['sentence-transformers/all-MiniLM-L6-v2', 'sentence-transformers/all-mpnet-base-v2']
  }
  
  @current_stats = {
    total_documents: ::Ragdoll::Document.count,
    total_embeddings: ::Ragdoll::Embedding.count,
    embedding_dimensions: ::Ragdoll::Embedding.first&.embedding_dimensions || 0,
    average_chunk_size: ::Ragdoll::Embedding.average('LENGTH(content)')&.round || 0
  }
end

#updateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/ragdoll/configuration_controller.rb', line 25

def update
  config_params = params.require(:configuration).permit(
    :llm_provider,
    :embedding_provider,
    :embedding_model,
    :chunk_size,
    :chunk_overlap,
    :max_search_results,
    :search_similarity_threshold,
    :enable_search_analytics,
    :enable_document_summarization,
    :enable_usage_tracking,
    :usage_ranking_enabled,
    :openai_api_key,
    :anthropic_api_key,
    :google_api_key,
    :azure_api_key,
    :ollama_url,
    :huggingface_api_key
  )
  
  begin
    # Update configuration
    config = ::Ragdoll.configuration
    
    config_params.each do |key, value|
      # Convert string values to appropriate types
      case key
      when 'chunk_size', 'chunk_overlap', 'max_search_results'
        config.send("#{key}=", value.to_i)
      when 'search_similarity_threshold'
        config.send("#{key}=", value.to_f)
      when 'enable_search_analytics', 'enable_document_summarization', 'enable_usage_tracking', 'usage_ranking_enabled'
        config.send("#{key}=", value == '1' || value == 'true')
      else
        config.send("#{key}=", value) if value.present?
      end
    end
    
    flash[:notice] = 'Configuration updated successfully.'
    
    # Test the configuration
    begin
      client = ::Ragdoll::Client.new
      test_result = client.stats
      flash[:notice] += " Configuration test successful."
    rescue => e
      flash[:warning] = "Configuration saved but test failed: #{e.message}"
    end
    
  rescue => e
    flash[:alert] = "Error updating configuration: #{e.message}"
  end
  
  redirect_to ragdoll.configuration_path
end