FIX: Misconfigured OpenAI API for embeddings shouldn't spam logs (#440)

This commit is contained in:
Rafael dos Santos Silva 2024-01-24 15:57:18 -03:00 committed by GitHub
parent 04bc402aae
commit 16d666fe69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 3 deletions

View File

@ -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