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