This commit is contained in:
Rafael dos Santos Silva 2023-02-22 20:48:51 -03:00
parent 6cf411ec90
commit f572a7cc2c
No known key found for this signature in database
GPG Key ID: 5E50360227B34938
3 changed files with 5 additions and 16 deletions

View File

@ -25,7 +25,7 @@ module ::DiscourseAI
"#{SiteSetting.ai_sentiment_inference_service_api_endpoint}/api/v1/classify", "#{SiteSetting.ai_sentiment_inference_service_api_endpoint}/api/v1/classify",
model, model,
content, content,
SiteSetting.ai_sentiment_inference_service_api_key SiteSetting.ai_sentiment_inference_service_api_key,
) )
store_classification(model, classification) store_classification(model, classification)

View File

@ -26,7 +26,7 @@ module ::DiscourseAI
"#{SiteSetting.ai_toxicity_inference_service_api_endpoint}/api/v1/classify", "#{SiteSetting.ai_toxicity_inference_service_api_endpoint}/api/v1/classify",
SiteSetting.ai_toxicity_inference_service_api_model, SiteSetting.ai_toxicity_inference_service_api_model,
content, content,
SiteSetting.ai_toxicity_inference_service_api_key SiteSetting.ai_toxicity_inference_service_api_key,
) )
store_classification store_classification
consider_flagging consider_flagging

View File

@ -3,22 +3,11 @@
module ::DiscourseAI module ::DiscourseAI
class InferenceManager class InferenceManager
def self.perform!(endpoint, model, content, api_key) def self.perform!(endpoint, model, content, api_key)
headers = { "Referer" => Discourse.base_url, "Content-Type" => "application/json" }
headers = { headers["X-API-KEY"] = api_key if api_key.present?
"Referer" => Discourse.base_url,
"Content-Type" => "application/json",
}
if api_key.present? response = Faraday.post(endpoint, { model: model, content: content }.to_json, headers)
headers["X-API-KEY"] = api_key
end
response =
Faraday.post(
endpoint,
{ model: model, content: content }.to_json,
headers,
)
raise Net::HTTPBadResponse unless response.status == 200 raise Net::HTTPBadResponse unless response.status == 200