feat: use captain endpoint config in legacy OpenAI base service (#12060)
This PR migrates the legacy OpenAI integration (where users provide their own API keys) from using hardcoded `https://api.openai.com` endpoints to use the configurable `CAPTAIN_OPEN_AI_ENDPOINT` from the captain configuration. This ensures consistency across all OpenAI integrations in the platform. ## Changes - Updated `lib/integrations/openai_base_service.rb` to use captain endpoint config - Updated `enterprise/app/models/enterprise/concerns/article.rb` to use captain endpoint config - Removed unused `enterprise/lib/chat_gpt.rb` class - Added tests for endpoint configuration behavior
This commit is contained in:
@@ -4,7 +4,6 @@ class Integrations::OpenaiBaseService
|
||||
# sticking with 120000 to be safe
|
||||
# 120000 * 4 = 480,000 characters (rounding off downwards to 400,000 to be safe)
|
||||
TOKEN_LIMIT = 400_000
|
||||
API_URL = 'https://api.openai.com/v1/chat/completions'.freeze
|
||||
GPT_MODEL = ENV.fetch('OPENAI_GPT_MODEL', 'gpt-4o-mini').freeze
|
||||
|
||||
ALLOWED_EVENT_NAMES = %w[rephrase summarize reply_suggestion fix_spelling_grammar shorten expand make_friendly make_formal simplify].freeze
|
||||
@@ -81,6 +80,12 @@ class Integrations::OpenaiBaseService
|
||||
self.class::CACHEABLE_EVENTS.include?(event_name)
|
||||
end
|
||||
|
||||
def api_url
|
||||
endpoint = InstallationConfig.find_by(name: 'CAPTAIN_OPEN_AI_ENDPOINT')&.value || 'https://api.openai.com/'
|
||||
endpoint = endpoint.chomp('/')
|
||||
"#{endpoint}/v1/chat/completions"
|
||||
end
|
||||
|
||||
def make_api_call(body)
|
||||
headers = {
|
||||
'Content-Type' => 'application/json',
|
||||
@@ -88,7 +93,7 @@ class Integrations::OpenaiBaseService
|
||||
}
|
||||
|
||||
Rails.logger.info("OpenAI API request: #{body}")
|
||||
response = HTTParty.post(API_URL, headers: headers, body: body)
|
||||
response = HTTParty.post(api_url, headers: headers, body: body)
|
||||
Rails.logger.info("OpenAI API response: #{response.body}")
|
||||
|
||||
return { error: response.parsed_response, error_code: response.code } unless response.success?
|
||||
|
||||
Reference in New Issue
Block a user