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:
@@ -68,8 +68,16 @@ module Enterprise::Concerns::Article
|
||||
headers = { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{ENV.fetch('OPENAI_API_KEY', nil)}" }
|
||||
body = { model: 'gpt-4o', messages: messages, response_format: { type: 'json_object' } }.to_json
|
||||
Rails.logger.info "Requesting Chat GPT with body: #{body}"
|
||||
response = HTTParty.post('https://api.openai.com/v1/chat/completions', headers: headers, body: body)
|
||||
response = HTTParty.post(openai_api_url, headers: headers, body: body)
|
||||
Rails.logger.info "Chat GPT response: #{response.body}"
|
||||
JSON.parse(response.parsed_response['choices'][0]['message']['content'])['search_terms']
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def openai_api_url
|
||||
endpoint = InstallationConfig.find_by(name: 'CAPTAIN_OPEN_AI_ENDPOINT')&.value || 'https://api.openai.com/'
|
||||
endpoint = endpoint.chomp('/')
|
||||
"#{endpoint}/v1/chat/completions"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user