mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-02-16 08:24:45 +00:00
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:
parent
346dd734d1
commit
1d5fa0ce6c
@ -7,6 +7,7 @@ class LlmModel < ActiveRecord::Base
|
|||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
validates :url, exclusion: { in: [RESERVED_VLLM_SRV_URL] }
|
validates :url, exclusion: { in: [RESERVED_VLLM_SRV_URL] }
|
||||||
|
before_save :toggle_companion_user_before_save
|
||||||
|
|
||||||
def self.enable_or_disable_srv_llm!
|
def self.enable_or_disable_srv_llm!
|
||||||
srv_model = find_by(url: RESERVED_VLLM_SRV_URL)
|
srv_model = find_by(url: RESERVED_VLLM_SRV_URL)
|
||||||
@ -27,6 +28,10 @@ class LlmModel < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def toggle_companion_user_before_save
|
||||||
|
toggle_companion_user if enabled_chat_bot_changed? || new_record?
|
||||||
|
end
|
||||||
|
|
||||||
def toggle_companion_user
|
def toggle_companion_user
|
||||||
return if name == "fake" && Rails.env.production?
|
return if name == "fake" && Rails.env.production?
|
||||||
|
|
||||||
|
@ -23,7 +23,15 @@ module DiscourseAi
|
|||||||
end
|
end
|
||||||
|
|
||||||
def default_options
|
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
|
end
|
||||||
|
|
||||||
def normalize_model_params(model_params)
|
def normalize_model_params(model_params)
|
||||||
|
@ -177,6 +177,12 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Gemini do
|
|||||||
expected_prompt = {
|
expected_prompt = {
|
||||||
"generationConfig" => {
|
"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" => [
|
"contents" => [
|
||||||
{
|
{
|
||||||
"role" => "user",
|
"role" => "user",
|
||||||
|
@ -4,6 +4,8 @@ RSpec.describe "Admin dashboard", type: :system do
|
|||||||
fab!(:admin)
|
fab!(:admin)
|
||||||
|
|
||||||
it "correctly sets defaults" do
|
it "correctly sets defaults" do
|
||||||
|
SiteSetting.ai_bot_enabled = true
|
||||||
|
|
||||||
sign_in(admin)
|
sign_in(admin)
|
||||||
|
|
||||||
visit "/admin/plugins/discourse-ai/ai-llms"
|
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(".ai-llm-editor__next").click()
|
||||||
find("input.ai-llm-editor__api-key").fill_in(with: "abcd")
|
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()
|
find(".ai-llm-editor__save").click()
|
||||||
|
|
||||||
expect(page).to have_current_path("/admin/plugins/discourse-ai/ai-llms")
|
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.max_prompt_tokens.to_i).to eq(model_preset[:tokens])
|
||||||
expect(llm.provider).to eq("anthropic")
|
expect(llm.provider).to eq("anthropic")
|
||||||
expect(llm.display_name).to eq(model_preset[:display_name])
|
expect(llm.display_name).to eq(model_preset[:display_name])
|
||||||
|
expect(llm.user_id).not_to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user