From 16d666fe699e13b95b064bb5f3e4386aca6791c5 Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Silva Date: Wed, 24 Jan 2024 15:57:18 -0300 Subject: [PATCH] FIX: Misconfigured OpenAI API for embeddings shouldn't spam logs (#440) --- lib/inference/open_ai_embeddings.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/inference/open_ai_embeddings.rb b/lib/inference/open_ai_embeddings.rb index 92009cce..0879a9f6 100644 --- a/lib/inference/open_ai_embeddings.rb +++ b/lib/inference/open_ai_embeddings.rb @@ -20,14 +20,18 @@ module ::DiscourseAi { model: model, input: content }.to_json, headers, ) - if response.status != 200 + + case response.status + when 200 + JSON.parse(response.body, symbolize_names: true) + when 429 + # TODO add a AdminDashboard Problem? + else Rails.logger.warn( "OpenAI Embeddings failed with status: #{response.status} body: #{response.body}", ) raise Net::HTTPBadResponse end - - JSON.parse(response.body, symbolize_names: true) end end end