A platform for community discussion. Free, open, simple.
FEATURE: expand vLLM reasoning controls (#40727)
Sam2caa675f7d38
diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llm-editor-form.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llm-editor-form.gjsindex f9398fb884b..27b84d0230b 100644--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llm-editor-form.gjs+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llm-editor-form.gjs@@ -414,6 +414,8 @@ export default class AiLlmEditorForm extends Component {@title={{i18n(concat "discourse_ai.llms.provider_fields." name)}}+ @tooltip={{if params.tooltip (i18n params.tooltip)}}+ @helpText={{if params.helpText (i18n params.helpText)}}@showTitle={{not (eq params.type "checkbox")}}@format="large"@type={{this.fieldTypeForProviderParam params.type}}diff --git a/plugins/discourse-ai/app/models/llm_model.rb b/plugins/discourse-ai/app/models/llm_model.rbindex 5449616fcb8..65e1cf159cf 100644--- a/plugins/discourse-ai/app/models/llm_model.rb+++ b/plugins/discourse-ai/app/models/llm_model.rb@@ -288,11 +288,54 @@ class LlmModel < ActiveRecord::Basevllm: {disable_system_prompt: :checkbox,disable_native_tools: :checkbox,- enable_thinking: :checkbox,+ reasoning_parser: {+ type: :enum,+ values: [+ { id: "default", name: "Server default" },+ { id: "deepseek_r1", name: "deepseek_r1" },+ { id: "qwen3", name: "qwen3" },+ { id: "deepseek_v3", name: "deepseek_v3" },+ { id: "deepseek_v4", name: "deepseek_v4" },+ { id: "gemma4", name: "gemma4" },+ { id: "granite", name: "granite" },+ { id: "glm45", name: "glm45" },+ { id: "hunyuan_a13b", name: "hunyuan_a13b" },+ { id: "cohere_command3", name: "cohere_command3" },+ { id: "ernie45", name: "ernie45" },+ { id: "holo2", name: "holo2" },+ { id: "minimax_m2_append_think", name: "minimax_m2_append_think" },+ ],+ default: "default",+ tooltip: "discourse_ai.llms.provider_field_hints.reasoning_parser",+ },+ thinking_override: {+ type: :enum,+ values: [+ { id: "default", name: "Server default" },+ { id: "on", name: "Force on" },+ { id: "off", name: "Force off" },+ ],+ default: "default",+ depends_on: :reasoning_parser,+ tooltip: "discourse_ai.llms.provider_field_hints.thinking_override",+ },reasoning_effort: {type: :enum,- values: %w[default none minimal low medium high xhigh],+ values: [+ { id: "default", name: "Server default" },+ { id: "none", name: "None" },+ { id: "low", name: "Low" },+ { id: "medium", name: "Medium" },+ { id: "high", name: "High" },+ ],default: "default",+ depends_on: :reasoning_parser,+ tooltip: "discourse_ai.llms.provider_field_hints.reasoning_effort",+ },+ thinking_token_budget: {+ type: :number,+ depends_on: :reasoning_parser,+ tooltip: "discourse_ai.llms.provider_field_hints.thinking_token_budget",},disable_temperature: {type: :checkbox,diff --git a/plugins/discourse-ai/assets/javascripts/discourse/lib/llm-provider-param-helpers.js b/plugins/discourse-ai/assets/javascripts/discourse/lib/llm-provider-param-helpers.jsindex e069527f692..56d987cc62a 100644--- a/plugins/discourse-ai/assets/javascripts/discourse/lib/llm-provider-param-helpers.js+++ b/plugins/discourse-ai/assets/javascripts/discourse/lib/llm-provider-param-helpers.js@@ -44,10 +44,17 @@ export function normalizeProviderParams(rawParams) {return Object.entries(rawParams).reduce((acc, [field, value]) => {if (typeof value === "string") {acc[field] = { type: value };- } else if (typeof value === "object") {+ } else if (typeof value === "object" && value !== null) {if (value.values) {value = { ...value };- value.values = value.values.map((v) => ({ id: v, name: v }));+ value.values = value.values.map((option) => {+ if (typeof option === "object" && option !== null) {+ const id = option.id ?? option.value;+ return { id, name: option.name ?? option.label ?? id };+ }++ return { id: option, name: option };+ });}acc[field] = {@@ -56,6 +63,8 @@ export function normalizeProviderParams(rawParams) {default: value.default ?? undefined,hidden_if: value.hidden_if ?? undefined,depends_on: value.depends_on ?? undefined,+ tooltip: value.tooltip ?? undefined,+ helpText: value.helpText ?? value.help_text ?? undefined,};} else {acc[field] = { type: "text" };diff --git a/plugins/discourse-ai/config/locales/client.en.yml b/plugins/discourse-ai/config/locales/client.en.ymlindex d559d90603f..2f29362a975 100644--- a/plugins/discourse-ai/config/locales/client.en.yml+++ b/plugins/discourse-ai/config/locales/client.en.yml@@ -1024,6 +1024,9 @@ en:disable_streaming: "Disable streaming completions (convert streaming to non streaming requests)"reasoning_effort: "Reasoning effort (only applicable to reasoning models)"service_tier: "Service tier (flex = lower cost/higher latency, priority = faster processing)"+ reasoning_parser: "vLLM reasoning parser"+ thinking_override: "Thinking override"+ thinking_token_budget: "Thinking token budget"enable_reasoning: "Enable reasoning (only applicable to reasoning models)"adaptive_thinking: "Enable adaptive thinking (recommended for Claude 4.6 models)"enable_thinking: "Enable thinking (Gemini 2.5 models - uses token budget)"@@ -1038,6 +1041,12 @@ en:prompt_caching_always: "Always - Always use prompt caching"effort: "Effort level"+ provider_field_hints:+ reasoning_parser: "Must match the vLLM server --reasoning-parser setting. Discourse cannot switch parsers per request; it uses this to shape request options."+ thinking_override: "Optionally force supported vLLM chat templates to enable or disable thinking for each request. Unsupported parsers keep the server default."+ reasoning_effort: "Sends vLLM's reasoning_effort request option for parsers that support it."+ thinking_token_budget: "Optional cap for reasoning tokens. Requires a vLLM reasoning parser and is ignored when reasoning effort is None."+related_topics:title: "Related topics"pill: "Related"diff --git a/plugins/discourse-ai/lib/completions/endpoints/vllm.rb b/plugins/discourse-ai/lib/completions/endpoints/vllm.rbindex 50ace7d2947..5f6c738d26d 100644--- a/plugins/discourse-ai/lib/completions/endpoints/vllm.rb+++ b/plugins/discourse-ai/lib/completions/endpoints/vllm.rb@@ -4,6 +4,10 @@ module DiscourseAimodule Completionsmodule Endpointsclass Vllm < OpenAi+ ENABLE_THINKING_PARSERS = %w[qwen3 gemma4 deepseek_v4].freeze+ THINKING_PARSERS = %w[granite deepseek_v3 holo2].freeze+ VLLM_REASONING_EFFORTS = %w[none low medium high].freeze+def self.can_contact?(llm_model)llm_model.provider == "vllm"end@@ -17,7 +21,8 @@ module DiscourseAiresult = processor.process_message(parsed)if output_thinking- reasoning = parsed.dig(:choices, 0, :message, :reasoning_content)+ reasoning = parsed.dig(:choices, 0, :message, :reasoning).presence+ reasoning ||= parsed.dig(:choices, 0, :message, :reasoning_content)result.unshift(Thinking.new(message: reasoning)) if reasoning.present?end@@ -30,7 +35,8 @@ module DiscourseAielements = [](@decoder << chunk).each do |parsed_json|if output_thinking- reasoning = parsed_json.dig(:choices, 0, :delta, :reasoning_content)+ reasoning = parsed_json.dig(:choices, 0, :delta, :reasoning).presence+ reasoning ||= parsed_json.dig(:choices, 0, :delta, :reasoning_content)if reasoning.present?if @thinking.nil?@thinking = Thinking.new(message: reasoning.dup, partial: true)@@ -74,13 +80,75 @@ module DiscourseAipayload[:stream_options] = { include_usage: true }end- if llm_model.lookup_custom_param("enable_thinking")- payload[:chat_template_kwargs] = { enable_thinking: true }- end+ apply_thinking_template_kwargs(payload)+ apply_thinking_token_budget(payload)payloadend+ def apply_thinking_template_kwargs(payload)+ template_kwargs = thinking_template_kwargs+ return if template_kwargs.blank?++ payload[:chat_template_kwargs] ||= {}+ payload[:chat_template_kwargs].merge!(template_kwargs)+ end++ def thinking_template_kwargs+ override = active_custom_param("thinking_override")++ if override+ return {} if !%w[on off].include?(override)++ parser = active_custom_param("reasoning_parser")+ thinking_enabled = override == "on"++ if ENABLE_THINKING_PARSERS.include?(parser)+ { enable_thinking: thinking_enabled }+ elsif THINKING_PARSERS.include?(parser)+ { thinking: thinking_enabled }+ else+ {}+ end+ elsif llm_model.lookup_custom_param("enable_thinking")+ { enable_thinking: true }+ else+ {}+ end+ end++ def apply_thinking_token_budget(payload)+ return if active_custom_param("reasoning_parser").blank?+ return if reasoning_effort == "none"++ budget = llm_model.lookup_custom_param("thinking_token_budget").to_i+ payload[:thinking_token_budget] = budget if budget.positive?+ end++ def active_custom_param(key)+ value = llm_model.lookup_custom_param(key)+ value = value.strip if value.respond_to?(:strip)+ return nil if value.blank? || value == "default"++ value+ end++ def reasoning_effort+ return @reasoning_effort if defined?(@reasoning_effort)++ @reasoning_effort = raw_custom_param("reasoning_effort")+ @reasoning_effort = nil if !VLLM_REASONING_EFFORTS.include?(@reasoning_effort)+ @reasoning_effort+ end++ def raw_custom_param(key)+ value = llm_model.provider_params&.dig(key) || llm_model.provider_params&.dig(key.to_sym)+ value = value.strip if value.respond_to?(:strip)+ return nil if value.blank? || value == "default"++ value+ end+def prepare_request(payload)headers = { "Referer" => Discourse.base_url, "Content-Type" => "application/json" }diff --git a/plugins/discourse-ai/spec/lib/completions/endpoints/vllm_spec.rb b/plugins/discourse-ai/spec/lib/completions/endpoints/vllm_spec.rbindex c562da660ed..fbdb7be8387 100644--- a/plugins/discourse-ai/spec/lib/completions/endpoints/vllm_spec.rb+++ b/plugins/discourse-ai/spec/lib/completions/endpoints/vllm_spec.rb@@ -125,10 +125,10 @@ class VllmMock < EndpointMockmodel.default_options.merge(messages: prompt)- .tap do |b|- b[:stream] = true if stream- b[:tools] = [tool_payload] if tool_call- b[:stream_options] = { include_usage: true } if stream+ .tap do |body|+ body[:stream] = true if stream+ body[:tools] = [tool_payload] if tool_call+ body[:stream_options] = { include_usage: true } if streamend.to_jsonend@@ -159,9 +159,34 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Vllm dolet(:request_body) { model.default_options.merge(messages: prompt).to_json }let(:stream_request_body) { model.default_options.merge(messages: prompt, stream: true).to_json }+ let(:completion_response_body) do+ {+ choices: [{ message: { role: "assistant", content: "hello" } }],+ usage: {+ prompt_tokens: 10,+ completion_tokens: 5,+ },+ }.to_json+ endbefore { enable_current_plugin }+ def capture_payload_for_completion+ captured_payload = nil+ stub =+ stub_request(:post, "https://test.dev/v1/chat/completions")+ .with do |request|+ captured_payload = JSON.parse(request.body)+ true+ end+ .to_return(status: 200, body: completion_response_body)++ llm.generate("say hello", user: Discourse.system_user)++ expect(stub).to have_been_requested+ captured_payload+ end+describe "tool support" doit "is able to invoke XML tools correctly" dollm_model.update!(provider_params: { "disable_native_tools" => true })@@ -325,47 +350,189 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Vllm doexpect(log.response_tokens).to eq(26)end- describe "enable_thinking" do- it "sends chat_template_kwargs when enable_thinking is set" do+ describe "thinking controls" do+ it "sends enable_thinking for Qwen thinking overrides" do+ llm_model.update!(+ provider_params: {+ "reasoning_parser" => "qwen3",+ "thinking_override" => "off",+ },+ )++ payload = capture_payload_for_completion+ expect(payload["chat_template_kwargs"]).to eq("enable_thinking" => false)+ end++ it "sends enable_thinking for Gemma thinking overrides" do+ llm_model.update!(+ provider_params: {+ "reasoning_parser" => "gemma4",+ "thinking_override" => "on",+ },+ )++ payload = capture_payload_for_completion+ expect(payload["chat_template_kwargs"]).to eq("enable_thinking" => true)+ end++ it "sends enable_thinking for DeepSeek V4 thinking overrides" do+ llm_model.update!(+ provider_params: {+ "reasoning_parser" => "deepseek_v4",+ "thinking_override" => "on",+ },+ )++ payload = capture_payload_for_completion+ expect(payload["chat_template_kwargs"]).to eq("enable_thinking" => true)+ end++ it "sends thinking for Granite thinking overrides" do+ llm_model.update!(+ provider_params: {+ "reasoning_parser" => "granite",+ "thinking_override" => "on",+ },+ )++ payload = capture_payload_for_completion+ expect(payload["chat_template_kwargs"]).to eq("thinking" => true)+ end++ it "sends thinking for DeepSeek V3 thinking overrides" do+ llm_model.update!(+ provider_params: {+ "reasoning_parser" => "deepseek_v3",+ "thinking_override" => "off",+ },+ )++ payload = capture_payload_for_completion+ expect(payload["chat_template_kwargs"]).to eq("thinking" => false)+ end++ it "sends thinking for Holo thinking overrides" do+ llm_model.update!(+ provider_params: {+ "reasoning_parser" => "holo2",+ "thinking_override" => "off",+ },+ )++ payload = capture_payload_for_completion+ expect(payload["chat_template_kwargs"]).to eq("thinking" => false)+ end++ it "keeps DeepSeek R1 thinking on the server default" do+ llm_model.update!(+ provider_params: {+ "reasoning_parser" => "deepseek_r1",+ "thinking_override" => "off",+ },+ )++ payload = capture_payload_for_completion+ expect(payload).not_to have_key("chat_template_kwargs")+ end++ it "keeps legacy enable_thinking behavior" dollm_model.update!(provider_params: { "enable_thinking" => true })- stub =- stub_request(:post, "https://test.dev/v1/chat/completions").with(- body: hash_including("chat_template_kwargs" => { "enable_thinking" => true }),- ).to_return(- status: 200,- body: {- choices: [{ message: { role: "assistant", content: "hello" } }],- usage: {- prompt_tokens: 10,- completion_tokens: 5,- },- }.to_json,- )+ payload = capture_payload_for_completion+ expect(payload["chat_template_kwargs"]).to eq("enable_thinking" => true)+ end- llm.generate("say hello", user: Discourse.system_user)+ it "prefers thinking_override over legacy enable_thinking" do+ llm_model.update!(+ provider_params: {+ "enable_thinking" => true,+ "reasoning_parser" => "qwen3",+ "thinking_override" => "off",+ },+ )- expect(stub).to have_been_requested+ payload = capture_payload_for_completion+ expect(payload["chat_template_kwargs"]).to eq("enable_thinking" => false)end- it "does not send chat_template_kwargs when enable_thinking is not set" do- stub =- stub_request(:post, "https://test.dev/v1/chat/completions")- .with { |request| !JSON.parse(request.body).key?("chat_template_kwargs") }- .to_return(- status: 200,- body: {- choices: [{ message: { role: "assistant", content: "hello" } }],- usage: {- prompt_tokens: 10,- completion_tokens: 5,- },- }.to_json,- )-- llm.generate("say hello", user: Discourse.system_user)+ it "sends a positive thinking_token_budget with a parser" do+ llm_model.update!(+ provider_params: {+ "reasoning_parser" => "qwen3",+ "thinking_token_budget" => "1024",+ },+ )- expect(stub).to have_been_requested+ payload = capture_payload_for_completion+ expect(payload["thinking_token_budget"]).to eq(1024)+ end++ it "ignores thinking_token_budget without active reasoning" do+ llm_model.update!(+ provider_params: {+ "reasoning_parser" => "default",+ "thinking_token_budget" => "1024",+ },+ )++ payload = capture_payload_for_completion+ expect(payload).not_to have_key("thinking_token_budget")+ end++ it "ignores non-positive thinking_token_budget values" do+ llm_model.update!(+ provider_params: {+ "reasoning_parser" => "qwen3",+ "thinking_token_budget" => "0",+ },+ )++ payload = capture_payload_for_completion+ expect(payload).not_to have_key("thinking_token_budget")+ end++ it "ignores thinking_token_budget with reasoning_effort none" do+ llm_model.update!(+ provider_params: {+ "reasoning_parser" => "qwen3",+ "reasoning_effort" => "none",+ "thinking_token_budget" => "1024",+ },+ )++ payload = capture_payload_for_completion+ expect(payload).not_to have_key("thinking_token_budget")+ end++ it "sends supported vLLM reasoning_effort values" do+ llm_model.update!(+ provider_params: {+ "reasoning_parser" => "qwen3",+ "reasoning_effort" => "high",+ },+ )++ payload = capture_payload_for_completion+ expect(payload["reasoning_effort"]).to eq("high")+ end++ it "keeps existing reasoning_effort without a parser" do+ llm_model.update!(provider_params: { "reasoning_effort" => "high" })++ payload = capture_payload_for_completion+ expect(payload["reasoning_effort"]).to eq("high")+ end++ it "ignores unsupported vLLM reasoning_effort values" do+ llm_model.update!(+ provider_params: {+ "reasoning_parser" => "qwen3",+ "reasoning_effort" => "xhigh",+ },+ )++ payload = capture_payload_for_completion+ expect(payload).not_to have_key("reasoning_effort")endend@@ -385,6 +552,80 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Vllm doendend+ describe "reasoning" do+ it "returns Thinking and content for non-streaming response with output_thinking" do+ body = {+ choices: [+ {+ message: {+ role: "assistant",+ content: "The answer is 4.",+ reasoning: "Let me think step by step: 2+2=4",+ },+ },+ ],+ usage: {+ prompt_tokens: 10,+ completion_tokens: 20,+ },+ }++ stub_request(:post, "https://test.dev/v1/chat/completions").to_return(+ status: 200,+ body: body.to_json,+ )++ result = llm.generate("what is 2+2?", user: Discourse.system_user, output_thinking: true)++ expect(result).to be_an(Array)+ expect(result.length).to eq(2)++ thinking = result[0]+ expect(thinking).to be_a(DiscourseAi::Completions::Thinking)+ expect(thinking.message).to eq("Let me think step by step: 2+2=4")+ expect(thinking.partial?).to eq(false)++ expect(result[1]).to eq("The answer is 4.")+ end++ it "streams Thinking partials followed by content" do+ chunks = []++ chunks << "data: #{({ choices: [{ delta: { role: "assistant", reasoning: "Let me " } }] }).to_json}\n\n"+ chunks << "data: #{({ choices: [{ delta: { reasoning: "think." } }] }).to_json}\n\n"+ chunks << "data: #{({ choices: [{ delta: { content: "The answer" } }] }).to_json}\n\n"+ chunks << "data: #{({ choices: [{ delta: { content: " is 4." } }], usage: { prompt_tokens: 10, completion_tokens: 20 } }).to_json}\n\n"+ chunks << "data: [DONE]\n\n"++ stub_request(:post, "https://test.dev/v1/chat/completions").to_return(+ status: 200,+ body: chunks.join,+ )++ partials = []+ llm.generate("what is 2+2?", user: Discourse.system_user, output_thinking: true) do |partial|+ partials << partial+ end++ thinking_partials =+ partials.select { |partial| partial.is_a?(DiscourseAi::Completions::Thinking) }+ text_partials = partials.select { |partial| partial.is_a?(String) }++ expect(thinking_partials.length).to eq(3)++ expect(thinking_partials[0].message).to eq("Let me ")+ expect(thinking_partials[0].partial?).to eq(true)++ expect(thinking_partials[1].message).to eq("think.")+ expect(thinking_partials[1].partial?).to eq(true)++ expect(thinking_partials[2].message).to eq("Let me think.")+ expect(thinking_partials[2].partial?).to eq(false)++ expect(text_partials.join).to eq("The answer is 4.")+ end+ end+describe "reasoning_content" doit "returns Thinking and content for non-streaming response with output_thinking" dobody = {@@ -467,8 +708,9 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Vllm dopartials << partialend- thinking_partials = partials.select { |p| p.is_a?(DiscourseAi::Completions::Thinking) }- text_partials = partials.select { |p| p.is_a?(String) }+ thinking_partials =+ partials.select { |partial| partial.is_a?(DiscourseAi::Completions::Thinking) }+ text_partials = partials.select { |partial| partial.is_a?(String) }expect(thinking_partials.length).to eq(3)diff --git a/plugins/discourse-ai/spec/requests/admin/ai_llms_controller_spec.rb b/plugins/discourse-ai/spec/requests/admin/ai_llms_controller_spec.rbindex eaf3e550b66..21ca7f1c5fe 100644--- a/plugins/discourse-ai/spec/requests/admin/ai_llms_controller_spec.rb+++ b/plugins/discourse-ai/spec/requests/admin/ai_llms_controller_spec.rb@@ -48,6 +48,42 @@ RSpec.describe DiscourseAi::Admin::AiLlmsController do)end+ it "includes vLLM reasoning controls metadata" do+ get "/admin/plugins/discourse-ai/ai-llms.json"+ expect(response).to be_successful++ vllm_params = response.parsed_body.dig("meta", "provider_params", "vllm")+ expect(vllm_params["reasoning_parser"]["values"]).to contain_exactly(+ { "id" => "default", "name" => "Server default" },+ { "id" => "deepseek_r1", "name" => "deepseek_r1" },+ { "id" => "qwen3", "name" => "qwen3" },+ { "id" => "deepseek_v3", "name" => "deepseek_v3" },+ { "id" => "deepseek_v4", "name" => "deepseek_v4" },+ { "id" => "gemma4", "name" => "gemma4" },+ { "id" => "granite", "name" => "granite" },+ { "id" => "glm45", "name" => "glm45" },+ { "id" => "hunyuan_a13b", "name" => "hunyuan_a13b" },+ { "id" => "cohere_command3", "name" => "cohere_command3" },+ { "id" => "ernie45", "name" => "ernie45" },+ { "id" => "holo2", "name" => "holo2" },+ { "id" => "minimax_m2_append_think", "name" => "minimax_m2_append_think" },+ )+ expect(vllm_params["thinking_override"]["values"]).to contain_exactly(+ { "id" => "default", "name" => "Server default" },+ { "id" => "on", "name" => "Force on" },+ { "id" => "off", "name" => "Force off" },+ )+ expect(vllm_params["reasoning_effort"]["values"]).to contain_exactly(+ { "id" => "default", "name" => "Server default" },+ { "id" => "none", "name" => "None" },+ { "id" => "low", "name" => "Low" },+ { "id" => "medium", "name" => "Medium" },+ { "id" => "high", "name" => "High" },+ )+ expect(vllm_params["thinking_token_budget"]["type"]).to eq("number")+ expect(vllm_params).not_to have_key("enable_thinking")+ end+it "lists enabled features on appropriate LLMs" doSiteSetting.ai_bot_enabled = trueSiteSetting.ai_bot_enabled_llms = llm_model.id.to_s@@ -303,6 +339,58 @@ RSpec.describe DiscourseAi::Admin::AiLlmsController doexpect(created_model.lookup_custom_param("disable_system_prompt")).to eq(true)end+ it "stores vLLM reasoning provider params" do+ post "/admin/plugins/discourse-ai/ai-llms.json",+ params: {+ ai_llm:+ valid_attrs.merge(+ provider: "vllm",+ provider_params: {+ reasoning_parser: "qwen3",+ thinking_override: "off",+ reasoning_effort: "medium",+ thinking_token_budget: "1024",+ enable_thinking: true,+ unknown_param: "ignored",+ },+ ),+ }++ created_model = LlmModel.last++ expect(response.status).to eq(201)+ expect(created_model.provider_params).to include(+ "reasoning_parser" => "qwen3",+ "thinking_override" => "off",+ "reasoning_effort" => "medium",+ "thinking_token_budget" => "1024",+ )+ expect(created_model.provider_params).not_to include("enable_thinking", "unknown_param")+ end++ it "sanitizes vLLM params when reasoning parser is inactive" do+ post "/admin/plugins/discourse-ai/ai-llms.json",+ params: {+ ai_llm:+ valid_attrs.merge(+ provider: "vllm",+ provider_params: {+ reasoning_parser: "default",+ thinking_override: "on",+ reasoning_effort: "high",+ thinking_token_budget: "1024",+ },+ ),+ }++ created_model = LlmModel.last++ expect(response.status).to eq(201)+ expect(created_model.provider_params["thinking_override"]).to eq("default")+ expect(created_model.provider_params["reasoning_effort"]).to eq("default")+ expect(created_model.provider_params["thinking_token_budget"]).to be_nil+ end+it "casts hash-form checkbox fields to booleans" dopost "/admin/plugins/discourse-ai/ai-llms.json",params: {diff --git a/plugins/discourse-ai/test/javascripts/unit/lib/llm-provider-param-helpers-test.js b/plugins/discourse-ai/test/javascripts/unit/lib/llm-provider-param-helpers-test.jsindex 8b2bc31a9c3..6667285a562 100644--- a/plugins/discourse-ai/test/javascripts/unit/lib/llm-provider-param-helpers-test.js+++ b/plugins/discourse-ai/test/javascripts/unit/lib/llm-provider-param-helpers-test.js@@ -222,6 +222,45 @@ module("Unit | Lib | llm-provider-param-helpers", function () {]);});+ test("preserves shaped enum option labels", function (assert) {+ const result = normalizeProviderParams({+ thinking_override: {+ type: "enum",+ values: [+ { id: "default", name: "Server default" },+ { id: "on", name: "Force on" },+ ],+ default: "default",+ },+ });++ assert.deepEqual(result.thinking_override.values, [+ { id: "default", name: "Server default" },+ { id: "on", name: "Force on" },+ ]);+ });++ test("preserves tooltip and helpText metadata", function (assert) {+ const result = normalizeProviderParams({+ reasoning_parser: {+ type: "enum",+ values: ["default"],+ tooltip: "discourse_ai.llms.provider_field_hints.reasoning_parser",+ help_text:+ "discourse_ai.llms.provider_field_hints.reasoning_parser_help",+ },+ });++ assert.strictEqual(+ result.reasoning_parser.tooltip,+ "discourse_ai.llms.provider_field_hints.reasoning_parser"+ );+ assert.strictEqual(+ result.reasoning_parser.helpText,+ "discourse_ai.llms.provider_field_hints.reasoning_parser_help"+ );+ });+test("preserves depends_on and hidden_if metadata", function (assert) {const result = normalizeProviderParams({reasoning_tokens: {