diff --git a/lib/inference/cloudflare_workers_ai.rb b/lib/inference/cloudflare_workers_ai.rb index 134dc9f6..099ae5be 100644 --- a/lib/inference/cloudflare_workers_ai.rb +++ b/lib/inference/cloudflare_workers_ai.rb @@ -19,7 +19,17 @@ module ::DiscourseAi raise Net::HTTPBadResponse if ![200].include?(response.status) - JSON.parse(response.body, symbolize_names: true) + case response.status + when 200 + JSON.parse(response.body, symbolize_names: true) + when 429 + # TODO add a AdminDashboard Problem? + else + Rails.logger.warn( + "Cloudflare Workers AI Embeddings failed with status: #{response.status} body: #{response.body}", + ) + raise Net::HTTPBadResponse + end end end end diff --git a/lib/inference/gemini_embeddings.rb b/lib/inference/gemini_embeddings.rb index 0bd78645..cedda24c 100644 --- a/lib/inference/gemini_embeddings.rb +++ b/lib/inference/gemini_embeddings.rb @@ -14,9 +14,17 @@ module ::DiscourseAi conn = Faraday.new { |f| f.adapter FinalDestination::FaradayAdapter } response = conn.post(url, body.to_json, headers) - raise Net::HTTPBadResponse if ![200].include?(response.status) - - JSON.parse(response.body, symbolize_names: true) + case response.status + when 200 + JSON.parse(response.body, symbolize_names: true) + when 429 + # TODO add a AdminDashboard Problem? + else + Rails.logger.warn( + "Google Gemini Embeddings failed with status: #{response.status} body: #{response.body}", + ) + raise Net::HTTPBadResponse + end end end end