mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-04 04:57:51 +00:00 
			
		
		
		
	Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Sojan Jose <sojan@pepalo.com> Co-authored-by: Pranav <pranav@chatwoot.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
		
			
				
	
	
		
			24 lines
		
	
	
		
			818 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			818 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
# frozen_string_literal: true
 | 
						|
 | 
						|
require 'agents'
 | 
						|
 | 
						|
Rails.application.config.after_initialize do
 | 
						|
  api_key = InstallationConfig.find_by(name: 'CAPTAIN_OPEN_AI_API_KEY')&.value
 | 
						|
  model = InstallationConfig.find_by(name: 'CAPTAIN_OPEN_AI_MODEL')&.value.presence || OpenAiConstants::DEFAULT_MODEL
 | 
						|
  api_endpoint = InstallationConfig.find_by(name: 'CAPTAIN_OPEN_AI_ENDPOINT')&.value || OpenAiConstants::DEFAULT_ENDPOINT
 | 
						|
 | 
						|
  if api_key.present?
 | 
						|
    Agents.configure do |config|
 | 
						|
      config.openai_api_key = api_key
 | 
						|
      if api_endpoint.present?
 | 
						|
        api_base = "#{api_endpoint.chomp('/')}/v1"
 | 
						|
        config.openai_api_base = api_base
 | 
						|
      end
 | 
						|
      config.default_model = model
 | 
						|
      config.debug = false
 | 
						|
    end
 | 
						|
  end
 | 
						|
rescue StandardError => e
 | 
						|
  Rails.logger.error "Failed to configure AI Agents SDK: #{e.message}"
 | 
						|
end
 |