Class: Raif::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/raif/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



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
# File 'lib/raif/configuration.rb', line 35

def initialize
  # Set default config
  @agent_types = Set.new(["Raif::Agents::ReActAgent", "Raif::Agents::NativeToolCallingAgent"])
  @anthropic_api_key = ENV["ANTHROPIC_API_KEY"]
  @anthropic_bedrock_models_enabled = false
  @anthropic_models_enabled = ENV["ANTHROPIC_API_KEY"].present?
  @authorize_admin_controller_action = ->{ false }
  @authorize_controller_action = ->{ false }
  @aws_bedrock_region = "us-east-1"
  @aws_bedrock_model_name_prefix = "us"
  @aws_bedrock_titan_embedding_models_enabled = false
  @task_system_prompt_intro = "You are a helpful assistant."
  @conversation_entries_controller = "Raif::ConversationEntriesController"
  @conversation_system_prompt_intro = "You are a helpful assistant who is collaborating with a teammate."
  @conversation_types = Set.new(["Raif::Conversation"])
  @conversations_controller = "Raif::ConversationsController"
  @current_user_method = :current_user
  @default_embedding_model_key = "open_ai_text_embedding_3_small"
  @default_llm_model_key = "open_ai_gpt_4o"
  @llm_api_requests_enabled = true
  @llm_request_max_retries = 2
  @llm_request_retriable_exceptions = [
    Faraday::ConnectionFailed,
    Faraday::TimeoutError,
    Faraday::ServerError,
  ]
  @model_superclass = "ApplicationRecord"
  @open_ai_api_key = ENV["OPENAI_API_KEY"]
  @open_ai_embedding_models_enabled = ENV["OPENAI_API_KEY"].present?
  @open_ai_models_enabled = ENV["OPENAI_API_KEY"].present?
  @open_router_api_key = ENV["OPENROUTER_API_KEY"]
  @open_router_models_enabled = ENV["OPENROUTER_API_KEY"].present?
  @open_router_app_name = nil
  @open_router_site_url = nil
  @user_tool_types = []
end

Instance Attribute Details

#agent_typesObject

Returns the value of attribute agent_types.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def agent_types
  @agent_types
end

#anthropic_api_keyObject

Returns the value of attribute anthropic_api_key.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def anthropic_api_key
  @anthropic_api_key
end

#anthropic_bedrock_models_enabledObject

Returns the value of attribute anthropic_bedrock_models_enabled.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def anthropic_bedrock_models_enabled
  @anthropic_bedrock_models_enabled
end

#anthropic_models_enabledObject

Returns the value of attribute anthropic_models_enabled.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def anthropic_models_enabled
  @anthropic_models_enabled
end

#authorize_admin_controller_actionObject

Returns the value of attribute authorize_admin_controller_action.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def authorize_admin_controller_action
  @authorize_admin_controller_action
end

#authorize_controller_actionObject

Returns the value of attribute authorize_controller_action.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def authorize_controller_action
  @authorize_controller_action
end

#aws_bedrock_model_name_prefixObject

Returns the value of attribute aws_bedrock_model_name_prefix.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def aws_bedrock_model_name_prefix
  @aws_bedrock_model_name_prefix
end

#aws_bedrock_regionObject

Returns the value of attribute aws_bedrock_region.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def aws_bedrock_region
  @aws_bedrock_region
end

#aws_bedrock_titan_embedding_models_enabledObject

Returns the value of attribute aws_bedrock_titan_embedding_models_enabled.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def aws_bedrock_titan_embedding_models_enabled
  @aws_bedrock_titan_embedding_models_enabled
end

#conversation_entries_controllerObject

Returns the value of attribute conversation_entries_controller.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def conversation_entries_controller
  @conversation_entries_controller
end

#conversation_system_prompt_introObject

Returns the value of attribute conversation_system_prompt_intro.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def conversation_system_prompt_intro
  @conversation_system_prompt_intro
end

#conversation_typesObject

Returns the value of attribute conversation_types.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def conversation_types
  @conversation_types
end

#conversations_controllerObject

Returns the value of attribute conversations_controller.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def conversations_controller
  @conversations_controller
end

#current_user_methodObject

Returns the value of attribute current_user_method.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def current_user_method
  @current_user_method
end

#default_embedding_model_keyObject

Returns the value of attribute default_embedding_model_key.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def default_embedding_model_key
  @default_embedding_model_key
end

#default_llm_model_keyObject

Returns the value of attribute default_llm_model_key.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def default_llm_model_key
  @default_llm_model_key
end

#llm_api_requests_enabledObject

Returns the value of attribute llm_api_requests_enabled.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def llm_api_requests_enabled
  @llm_api_requests_enabled
end

#llm_request_max_retriesObject

Returns the value of attribute llm_request_max_retries.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def llm_request_max_retries
  @llm_request_max_retries
end

#llm_request_retriable_exceptionsObject

Returns the value of attribute llm_request_retriable_exceptions.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def llm_request_retriable_exceptions
  @llm_request_retriable_exceptions
end

#model_superclassObject

Returns the value of attribute model_superclass.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def model_superclass
  @model_superclass
end

#open_ai_api_keyObject

Returns the value of attribute open_ai_api_key.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def open_ai_api_key
  @open_ai_api_key
end

#open_ai_embedding_models_enabledObject

Returns the value of attribute open_ai_embedding_models_enabled.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def open_ai_embedding_models_enabled
  @open_ai_embedding_models_enabled
end

#open_ai_models_enabledObject

Returns the value of attribute open_ai_models_enabled.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def open_ai_models_enabled
  @open_ai_models_enabled
end

#open_router_api_keyObject

Returns the value of attribute open_router_api_key.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def open_router_api_key
  @open_router_api_key
end

#open_router_app_nameObject

Returns the value of attribute open_router_app_name.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def open_router_app_name
  @open_router_app_name
end

#open_router_models_enabledObject

Returns the value of attribute open_router_models_enabled.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def open_router_models_enabled
  @open_router_models_enabled
end

#open_router_site_urlObject

Returns the value of attribute open_router_site_url.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def open_router_site_url
  @open_router_site_url
end

#task_system_prompt_introObject

Returns the value of attribute task_system_prompt_intro.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def task_system_prompt_intro
  @task_system_prompt_intro
end

#user_tool_typesObject

Returns the value of attribute user_tool_types.



5
6
7
# File 'lib/raif/configuration.rb', line 5

def user_tool_types
  @user_tool_types
end

Instance Method Details

#validate!Object



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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/raif/configuration.rb', line 72

def validate!
  unless Raif.available_llm_keys.include?(default_llm_model_key.to_sym)
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.default_llm_model_key was set to #{default_llm_model_key}, but must be one of: #{Raif.available_llm_keys.join(", ")}"
  end

  unless Raif.available_embedding_model_keys.include?(default_embedding_model_key.to_sym)
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.default_embedding_model_key was set to #{default_embedding_model_key}, but must be one of: #{Raif.available_embedding_model_keys.join(", ")}" # rubocop:disable Layout/LineLength
  end

  if authorize_controller_action.respond_to?(:call)
    authorize_controller_action.freeze
  else
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.authorize_controller_action must respond to :call and return a boolean"
  end

  if authorize_admin_controller_action.respond_to?(:call)
    authorize_admin_controller_action.freeze
  else
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.authorize_admin_controller_action must respond to :call and return a boolean"
  end

  if open_ai_models_enabled && open_ai_api_key.blank?
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.open_ai_api_key is required when Raif.config.open_ai_models_enabled is true. Set it via Raif.config.open_ai_api_key or ENV[\"OPENAI_API_KEY\"]" # rubocop:disable Layout/LineLength
  end

  if open_ai_embedding_models_enabled && open_ai_api_key.blank?
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.open_ai_api_key is required when Raif.config.open_ai_embedding_models_enabled is true. Set it via Raif.config.open_ai_api_key or ENV[\"OPENAI_API_KEY\"]" # rubocop:disable Layout/LineLength
  end

  if anthropic_models_enabled && anthropic_api_key.blank?
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.anthropic_api_key is required when Raif.config.anthropic_models_enabled is true. Set it via Raif.config.anthropic_api_key or ENV['ANTHROPIC_API_KEY']" # rubocop:disable Layout/LineLength
  end

  if open_router_models_enabled && open_router_api_key.blank?
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.open_router_api_key is required when Raif.config.open_router_models_enabled is true. Set it via Raif.config.open_router_api_key or ENV['OPENROUTER_API_KEY']" # rubocop:disable Layout/LineLength
  end
end