mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-03-07 01:39:54 +00:00
29 lines
582 B
Ruby
29 lines
582 B
Ruby
# frozen_string_literal: true
|
|
|
|
module ::DiscourseAI
|
|
class InferenceManager
|
|
def self.perform!(endpoint, model, content, api_key)
|
|
|
|
headers = {
|
|
"Referer" => Discourse.base_url,
|
|
"Content-Type" => "application/json",
|
|
}
|
|
|
|
if api_key.present?
|
|
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
|
|
|
|
JSON.parse(response.body)
|
|
end
|
|
end
|
|
end
|