Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 9d6fa07

Browse files
committed
FEATURE: migrate to new open ai image apis
1 parent 1074801 commit 9d6fa07

File tree

7 files changed

+463
-84
lines changed

7 files changed

+463
-84
lines changed

config/locales/server.en.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ en:
5555
ai_nsfw_flag_threshold_sexy: "Threshold for an image classified as sexy to be considered NSFW."
5656
ai_nsfw_models: "Models to use for NSFW inference."
5757

58-
ai_openai_api_key: "API key for OpenAI API. ONLY used for Dall-E. For GPT use the LLM config tab"
58+
ai_openai_api_key: "API key for OpenAI API. ONLY used for Image creation and edits. For GPT use the LLM config tab"
59+
ai_openai_image_generation_url: "URL for OpenAI image generation API"
60+
ai_openai_image_edit_url: "URL for OpenAI image edit API"
5961

6062
ai_helper_enabled: "Enable the AI helper."
6163
composer_ai_helper_allowed_groups: "Users on these groups will see the AI helper button in the composer."

config/settings.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ discourse_ai:
2626
default: 60
2727
hidden: true
2828

29-
ai_openai_dall_e_3_url: "https://api.openai.com/v1/images/generations"
29+
ai_openai_image_generation_url: "https://api.openai.com/v1/images/generations"
30+
ai_openai_image_edit_url: "https://api.openai.com/v1/images/edits"
3031
ai_openai_embeddings_url:
3132
hidden: true
3233
default: "https://api.openai.com/v1/embeddings"

lib/ai_helper/painter.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ def commission_thumbnails(input, user)
2121

2222
base64_to_image(artifacts, user.id)
2323
elsif model == "dall_e_3"
24-
api_key = SiteSetting.ai_openai_api_key
25-
api_url = SiteSetting.ai_openai_dall_e_3_url
26-
27-
artifacts =
28-
DiscourseAi::Inference::OpenAiImageGenerator
29-
.perform!(input, api_key: api_key, api_url: api_url)
30-
.dig(:data)
31-
.to_a
32-
.map { |art| art[:b64_json] }
33-
34-
base64_to_image(artifacts, user.id)
24+
attribution =
25+
I18n.t(
26+
"discourse_ai.ai_helper.painter.attribution.#{SiteSetting.ai_helper_illustrate_post_model}",
27+
)
28+
results =
29+
DiscourseAi::Inference::OpenAiImageGenerator.create_uploads!(
30+
input,
31+
model: "dall-e-3",
32+
user_id: user.id,
33+
title: attribution,
34+
)
35+
results.map { |result| UploadSerializer.new(result[:upload], root: false) }
3536
end
3637
end
3738

0 commit comments

Comments
 (0)