From 628083eaf3ab923eff1195537a0e19df0086ff21 Mon Sep 17 00:00:00 2001 From: Philippe Lehoux Date: Fri, 14 Nov 2025 15:58:40 -0500 Subject: [PATCH] Fix temperature normalization for search models Models like gpt-5-search-api were incorrectly matching the gpt-5 pattern and getting temperature=1.0, when they should match the -search pattern and get nil. Reordered conditions to check for -search models first, ensuring the more specific pattern takes precedence. --- lib/ruby_llm/providers/openai/capabilities.rb | 8 ++++---- spec/ruby_llm/providers/open_ai/capabilities_spec.rb | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/ruby_llm/providers/openai/capabilities.rb b/lib/ruby_llm/providers/openai/capabilities.rb index 37c320da8..317c24ea2 100644 --- a/lib/ruby_llm/providers/openai/capabilities.rb +++ b/lib/ruby_llm/providers/openai/capabilities.rb @@ -224,12 +224,12 @@ def special_prefix_format(prefix) end def self.normalize_temperature(temperature, model_id) - if model_id.match?(/^(o\d|gpt-5)/) - RubyLLM.logger.debug "Model #{model_id} requires temperature=1.0, ignoring provided value" - 1.0 - elsif model_id.match?(/-search/) + if model_id.match?(/-search/) RubyLLM.logger.debug "Model #{model_id} does not accept temperature parameter, removing" nil + elsif model_id.match?(/^(o\d|gpt-5)/) + RubyLLM.logger.debug "Model #{model_id} requires temperature=1.0, ignoring provided value" + 1.0 else temperature end diff --git a/spec/ruby_llm/providers/open_ai/capabilities_spec.rb b/spec/ruby_llm/providers/open_ai/capabilities_spec.rb index 2eede6708..5c00bee29 100644 --- a/spec/ruby_llm/providers/open_ai/capabilities_spec.rb +++ b/spec/ruby_llm/providers/open_ai/capabilities_spec.rb @@ -10,8 +10,14 @@ end end + it 'forces temperature to 1.0 for GPT-5 models' do + %w[gpt-5 gpt-5-mini gpt-5-nano].each do |model| + expect(described_class.normalize_temperature(0.7, model)).to eq(1.0) + end + end + it 'returns nil for search preview models' do - %w[gpt-4o-search-preview gpt-4o-mini-search-preview].each do |model| + %w[gpt-4o-search-preview gpt-4o-mini-search-preview gpt-5-search-api].each do |model| expect(described_class.normalize_temperature(0.7, model)).to be_nil end end