FIX: AI Automation scripts were broken when using seeded models (#991)
This commit is contained in:
parent
fcf2350652
commit
e3f5e86dc5
|
@ -22,7 +22,7 @@ module DiscourseAi
|
||||||
values
|
values
|
||||||
.filter do |value_h|
|
.filter do |value_h|
|
||||||
value_h["id"] > 0 ||
|
value_h["id"] > 0 ||
|
||||||
SiteSetting.ai_automation_allowed_seeded_models_map.includes?(value_h["id"].to_s)
|
SiteSetting.ai_automation_allowed_seeded_models_map.include?(value_h["id"].to_s)
|
||||||
end
|
end
|
||||||
.each { |value_h| value_h["id"] = "custom:#{value_h["id"]}" }
|
.each { |value_h| value_h["id"] = "custom:#{value_h["id"]}" }
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
RSpec.describe DiscourseAi::Automation do
|
||||||
|
describe "manually configured model" do
|
||||||
|
let!(:llm_model) { Fabricate(:llm_model) }
|
||||||
|
it "returns a list of available models for automation" do
|
||||||
|
models = DiscourseAi::Automation.available_models
|
||||||
|
expect(models).to be_an(Array)
|
||||||
|
expect(models.first["translated_name"]).to eq(llm_model.display_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "no models" do
|
||||||
|
it "returns an empty list" do
|
||||||
|
models = DiscourseAi::Automation.available_models
|
||||||
|
expect(models).to be_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "seeded models" do
|
||||||
|
let!(:llm_model) { Fabricate(:seeded_model) }
|
||||||
|
it "returns an empty list if no seeded models are allowed" do
|
||||||
|
models = DiscourseAi::Automation.available_models
|
||||||
|
expect(models).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns a list of seeded models if allowed" do
|
||||||
|
SiteSetting.ai_automation_allowed_seeded_models = llm_model.id.to_s
|
||||||
|
models = DiscourseAi::Automation.available_models
|
||||||
|
expect(models.first["translated_name"]).to eq(llm_model.display_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "mixed models" do
|
||||||
|
let!(:llm_model) { Fabricate(:llm_model) }
|
||||||
|
let!(:seeded_model) { Fabricate(:seeded_model) }
|
||||||
|
|
||||||
|
it "returns only the manually configured model if seeded is not allowed" do
|
||||||
|
models = DiscourseAi::Automation.available_models
|
||||||
|
expect(models.length).to eq(1)
|
||||||
|
expect(models.first["translated_name"]).to eq(llm_model.display_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns a list of seeded and custom models when seeded is allowed" do
|
||||||
|
SiteSetting.ai_automation_allowed_seeded_models = seeded_model.id.to_s
|
||||||
|
models = DiscourseAi::Automation.available_models
|
||||||
|
|
||||||
|
expect(models).to match_array(
|
||||||
|
[
|
||||||
|
{ "translated_name" => "#{llm_model.display_name}", "id" => "custom:#{llm_model.id}" },
|
||||||
|
{
|
||||||
|
"translated_name" => "#{seeded_model.display_name}",
|
||||||
|
"id" => "custom:#{seeded_model.id}",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue