From 39f14bebbdf0ec3f4ee5bf9cd05304244325a17e Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Mon, 24 Jul 2023 12:48:53 +0530 Subject: [PATCH] fix: undefined method `first` for nil:NilClass (#7567) Co-authored-by: Sojan Jose --- lib/integrations/openai_base_service.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/integrations/openai_base_service.rb b/lib/integrations/openai_base_service.rb index ce1fce245..73cc9b44f 100644 --- a/lib/integrations/openai_base_service.rb +++ b/lib/integrations/openai_base_service.rb @@ -75,6 +75,8 @@ class Integrations::OpenaiBaseService } response = HTTParty.post(API_URL, headers: headers, body: body) - JSON.parse(response.body)['choices'].first['message']['content'] + choices = JSON.parse(response.body)['choices'] + + choices.present? ? choices.first['message']['content'] : nil end end