Skip to content
Open
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
8 changes: 4 additions & 4 deletions lib/ruby_llm/providers/openai/capabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion spec/ruby_llm/providers/open_ai/capabilities_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down