iachat/enterprise/app/services/llm/base_open_ai_service.rb
Shivam Mishra 441cc065ae
feat: add config for OpenAI endpoint (#12051)
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
2025-07-29 09:44:50 +05:30

26 lines
693 B
Ruby

class Llm::BaseOpenAiService
DEFAULT_MODEL = 'gpt-4o-mini'.freeze
def initialize
@client = OpenAI::Client.new(
access_token: InstallationConfig.find_by!(name: 'CAPTAIN_OPEN_AI_API_KEY').value,
uri_base: uri_base,
log_errors: Rails.env.development?
)
setup_model
rescue StandardError => e
raise "Failed to initialize OpenAI client: #{e.message}"
end
private
def uri_base
InstallationConfig.find_by(name: 'CAPTAIN_OPEN_AI_ENDPOINT')&.value || 'https://api.openai.com/'
end
def setup_model
config_value = InstallationConfig.find_by(name: 'CAPTAIN_OPEN_AI_MODEL')&.value
@model = (config_value.presence || DEFAULT_MODEL)
end
end