Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/models/llm_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,16 @@ def lookup_custom_param(key)
end

def seeded?
id < 0
id.present? && id < 0
end

def api_key
if seeded?
env_key = "DISCOURSE_AI_SEEDED_LLM_API_KEY_#{id.abs}"
ENV[env_key] || self[:api_key]
else
self[:api_key]
end
end

private
Expand Down
13 changes: 13 additions & 0 deletions spec/models/llm_model_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

RSpec.describe LlmModel do
describe "api_key" do
fab!(:llm_model) { Fabricate(:seeded_model) }

before { ENV["DISCOURSE_AI_SEEDED_LLM_API_KEY_2"] = "blabla" }

it "should use environment variable over database value if seeded LLM" do
expect(llm_model.api_key).to eq("blabla")
end
end
end