FIX: when creating an llm we were not creating user (#685)

This meant that if you toggle ai user early it surprisingly did
not work.

Also remove safety settings from gemini, it is overly cautious
This commit is contained in:
Sam 2024-06-24 09:59:42 +10:00 committed by GitHub
parent 346dd734d1
commit 1d5fa0ce6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 1 deletions

View File

@ -7,6 +7,7 @@ class LlmModel < ActiveRecord::Base
belongs_to :user
validates :url, exclusion: { in: [RESERVED_VLLM_SRV_URL] }
before_save :toggle_companion_user_before_save
def self.enable_or_disable_srv_llm!
srv_model = find_by(url: RESERVED_VLLM_SRV_URL)
@ -27,6 +28,10 @@ class LlmModel < ActiveRecord::Base
end
end
def toggle_companion_user_before_save
toggle_companion_user if enabled_chat_bot_changed? || new_record?
end
def toggle_companion_user
return if name == "fake" && Rails.env.production?

View File

@ -23,7 +23,15 @@ module DiscourseAi
end
def default_options
{ generationConfig: {} }
# the default setting is a problem, it blocks too much
categories = %w[HARASSMENT SEXUALLY_EXPLICIT HATE_SPEECH DANGEROUS_CONTENT]
safety_settings =
categories.map do |category|
{ category: "HARM_CATEGORY_#{category}", threshold: "BLOCK_NONE" }
end
{ generationConfig: {}, safetySettings: safety_settings }
end
def normalize_model_params(model_params)

View File

@ -177,6 +177,12 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Gemini do
expected_prompt = {
"generationConfig" => {
},
"safetySettings" => [
{ "category" => "HARM_CATEGORY_HARASSMENT", "threshold" => "BLOCK_NONE" },
{ "category" => "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold" => "BLOCK_NONE" },
{ "category" => "HARM_CATEGORY_HATE_SPEECH", "threshold" => "BLOCK_NONE" },
{ "category" => "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold" => "BLOCK_NONE" },
],
"contents" => [
{
"role" => "user",

View File

@ -4,6 +4,8 @@ RSpec.describe "Admin dashboard", type: :system do
fab!(:admin)
it "correctly sets defaults" do
SiteSetting.ai_bot_enabled = true
sign_in(admin)
visit "/admin/plugins/discourse-ai/ai-llms"
@ -18,6 +20,8 @@ RSpec.describe "Admin dashboard", type: :system do
find(".ai-llm-editor__next").click()
find("input.ai-llm-editor__api-key").fill_in(with: "abcd")
PageObjects::Components::DToggleSwitch.new(".ai-llm-editor__enabled-chat-bot").toggle
find(".ai-llm-editor__save").click()
expect(page).to have_current_path("/admin/plugins/discourse-ai/ai-llms")
@ -35,5 +39,6 @@ RSpec.describe "Admin dashboard", type: :system do
expect(llm.max_prompt_tokens.to_i).to eq(model_preset[:tokens])
expect(llm.provider).to eq("anthropic")
expect(llm.display_name).to eq(model_preset[:display_name])
expect(llm.user_id).not_to be_nil
end
end