mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-03-08 18:29:32 +00:00
* FEATURE: Composer AI helper This change introduces a new composer button for the group members listed in the `ai_helper_allowed_groups` site setting. Users can use chatGPT to review, improve, or translate their posts to English. * Add a safeguard for PMs and don't rely on parentView
28 lines
673 B
Ruby
28 lines
673 B
Ruby
# frozen_string_literal: true
|
|
|
|
module ::DiscourseAi
|
|
module Inference
|
|
class OpenAiEmbeddings
|
|
def self.perform!(content, model = nil)
|
|
headers = {
|
|
"Authorization" => "Bearer #{SiteSetting.ai_openai_api_key}",
|
|
"Content-Type" => "application/json",
|
|
}
|
|
|
|
model ||= "text-embedding-ada-002"
|
|
|
|
response =
|
|
Faraday.post(
|
|
"https://api.openai.com/v1/embeddings",
|
|
{ model: model, input: content }.to_json,
|
|
headers,
|
|
)
|
|
|
|
raise Net::HTTPBadResponse unless response.status == 200
|
|
|
|
JSON.parse(response.body, symbolize_names: true)
|
|
end
|
|
end
|
|
end
|
|
end
|