chore: Fix OpenAI sentry errors (#7687)

- add check for nil condition
- add logs for openAI
This commit is contained in:
Sojan Jose
2023-08-07 14:08:26 -07:00
committed by GitHub
parent ed82eb2932
commit 4c75bb68f4
3 changed files with 16 additions and 2 deletions

View File

@@ -74,7 +74,10 @@ class Integrations::OpenaiBaseService
'Authorization' => "Bearer #{hook.settings['api_key']}"
}
Rails.logger.info("OpenAI API request: #{body}")
response = HTTParty.post(API_URL, headers: headers, body: body)
Rails.logger.info("OpenAI API response: #{response.body}")
choices = JSON.parse(response.body)['choices']
choices.present? ? choices.first['message']['content'] : nil