FIX: Show illustrate post only if stability API key present (#395)
This commit is contained in:
parent
f8fdb6db76
commit
1a5985134a
|
@ -5,8 +5,16 @@ module DiscourseAi
|
|||
class Assistant
|
||||
def available_prompts(name_filter: nil)
|
||||
cp = CompletionPrompt
|
||||
prompts = []
|
||||
|
||||
prompts = name_filter ? [cp.enabled_by_name(name_filter)] : cp.where(enabled: true)
|
||||
if name_filter
|
||||
prompts = [cp.enabled_by_name(name_filter)]
|
||||
else
|
||||
prompts = cp.where(enabled: true)
|
||||
# Only show the illustrate_post prompt if the API key is present
|
||||
prompts =
|
||||
prompts.where.not(name: "illustrate_post") if !SiteSetting.ai_stability_api_key.present?
|
||||
end
|
||||
|
||||
prompts.map do |prompt|
|
||||
translation =
|
||||
|
|
|
@ -10,6 +10,52 @@ RSpec.describe DiscourseAi::AiHelper::Assistant do
|
|||
defends himself, but instead exclaims: 'You too, my son!' Shakespeare and Quevedo capture the pathetic cry.
|
||||
STRING
|
||||
|
||||
describe("#available_prompts") do
|
||||
context "when no name filter is provided" do
|
||||
it "returns all available prompts" do
|
||||
prompts = subject.available_prompts
|
||||
|
||||
expect(prompts.length).to eq(6)
|
||||
expect(prompts.map { |p| p[:name] }).to contain_exactly(
|
||||
"translate",
|
||||
"generate_titles",
|
||||
"proofread",
|
||||
"markdown_table",
|
||||
"custom_prompt",
|
||||
"explain",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "when name filter is provided" do
|
||||
it "returns the prompt with the given name" do
|
||||
prompts = subject.available_prompts(name_filter: "translate")
|
||||
|
||||
expect(prompts.length).to eq(1)
|
||||
expect(prompts.first[:name]).to eq("translate")
|
||||
end
|
||||
end
|
||||
|
||||
context "when stability API key is present" do
|
||||
before { SiteSetting.ai_stability_api_key = "foo" }
|
||||
|
||||
it "returns the illustrate_post prompt in the list of all prompts" do
|
||||
prompts = subject.available_prompts
|
||||
|
||||
expect(prompts.length).to eq(7)
|
||||
expect(prompts.map { |p| p[:name] }).to contain_exactly(
|
||||
"translate",
|
||||
"generate_titles",
|
||||
"proofread",
|
||||
"markdown_table",
|
||||
"custom_prompt",
|
||||
"explain",
|
||||
"illustrate_post",
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#generate_and_send_prompt" do
|
||||
context "when using a prompt that returns text" do
|
||||
let(:mode) { CompletionPrompt::TRANSLATE }
|
||||
|
|
|
@ -138,6 +138,7 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController do
|
|||
sign_in(user)
|
||||
user.group_ids = [Group::AUTO_GROUPS[:trust_level_1]]
|
||||
SiteSetting.ai_helper_allowed_groups = Group::AUTO_GROUPS[:trust_level_1]
|
||||
SiteSetting.ai_stability_api_key = "foo"
|
||||
end
|
||||
|
||||
it "returns a list of prompts when no name_filter is provided" do
|
||||
|
|
Loading…
Reference in New Issue