completion-kit 0.28.34 → 0.28.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b098378de17e0d51976041f5376929f0fd220bc23e86f1044bf89133b3b7210e
4
- data.tar.gz: 65742e5a42a70e82fe3f4216652e8a80e4b08552eb54cc4a7e8621969a8dd26f
3
+ metadata.gz: f506b4c95279cd20d1085f9f3a2eb3eed2d30b03694d3232977a410044a36f8d
4
+ data.tar.gz: 4a5ea855e4fbb830f0df97dd1f957b86894710464bf011e3c17878cfaad6c416
5
5
  SHA512:
6
- metadata.gz: 3ac30e089d1ec6597556b0f4744315d07f1bf94207e174055a6e7ae51ee09f88b180a681ee79cd671cf1887cfee7cd1e99584adda5e95411d8a09ad4c96d5071
7
- data.tar.gz: ba7069754a2f1048da264f66a29e630f220225be24a7078bc4bc6b5a5004d328b02e42046b6b58c5a53a294d293fd386b81eccfbbd7f3b7cfd59d5b545062741
6
+ metadata.gz: 561278c7bf724b085e2cc05e3204d89b839e16803de24f9accfa59630edba15e4bdf85a9edbd745e03c9385807295749b95fda1b757b62c781265ebc705ca795
7
+ data.tar.gz: d2744c24f3eff96c4290bfa333145fa45941c6bf3d26cf7768968e452c6bba4d85c1668be97a8054ef1548aec9e55f782af081b82974c3c6d7a12dae6122ee41
@@ -222,7 +222,10 @@ module CompletionKit
222
222
  end
223
223
 
224
224
  def run_params
225
- params.require(:run).permit(:name, :prompt_id, :dataset_id, :judge_model, :temperature, :max_tokens, :judge_temperature, :output_column, :expected_column, metric_ids: [], tag_names: [])
225
+ permitted = params.require(:run).permit(:name, :prompt_id, :dataset_id, :judge_model, :temperature, :max_tokens, :judge_temperature, :output_column, :expected_column, :omit_temperature, metric_ids: [], tag_names: [])
226
+ omit = permitted.delete(:omit_temperature)
227
+ permitted[:temperature] = nil if omit == "1"
228
+ permitted
226
229
  end
227
230
 
228
231
  # Editing a run that already has results forks a new run — but only when a
@@ -75,6 +75,10 @@ module CompletionKit
75
75
  record_terminal_failure!(e)
76
76
  enqueue_completion_check
77
77
  return
78
+ ensure
79
+ if judge.temperature_dropped? && !run.judge_temperature_ignored?
80
+ run.update_columns(judge_temperature_ignored: true)
81
+ end
78
82
  end
79
83
 
80
84
  review = response.reviews.find_or_initialize_by(metric_id: metric.id)
@@ -337,7 +337,9 @@ module CompletionKit
337
337
  progress_current: 0,
338
338
  progress_total: 0,
339
339
  failure_summary: nil,
340
- error_message: nil
340
+ error_message: nil,
341
+ temperature_ignored: false,
342
+ judge_temperature_ignored: false
341
343
  )
342
344
  end
343
345
  rescue ActiveRecord::RecordInvalid => e
@@ -436,7 +438,7 @@ module CompletionKit
436
438
  error_status: nil,
437
439
  error_message: nil
438
440
  )
439
- update!(status: "running", failure_summary: nil, error_message: nil)
441
+ update!(status: "running", failure_summary: nil, error_message: nil, judge_temperature_ignored: false)
440
442
 
441
443
  response_ids.each do |rid|
442
444
  llm_metrics.each { |m| JudgeReviewJob.perform_later(rid, m.id, id) } if llm_judge_configured?
@@ -467,7 +469,7 @@ module CompletionKit
467
469
  end
468
470
 
469
471
  def nondeterministic_judge?
470
- judge_temperature.to_f > 0
472
+ judge_temperature.to_f > 0 || judge_temperature_ignored?
471
473
  end
472
474
 
473
475
  def rerun!
@@ -559,6 +561,7 @@ module CompletionKit
559
561
  expected_column: expected_column,
560
562
  created_at: created_at, updated_at: updated_at,
561
563
  max_tokens: max_tokens, judge_temperature: judge_temperature,
564
+ temperature_ignored: temperature_ignored, judge_temperature_ignored: judge_temperature_ignored,
562
565
  responses_count: responses.count, avg_score: avg_score,
563
566
  check_pass_rate: check_pass_rate,
564
567
  metric_averages: metric_averages,
@@ -5,9 +5,6 @@ module CompletionKit
5
5
  { id: "claude-3-5-haiku-latest", name: "Claude 3.5 Haiku" }
6
6
  ].freeze
7
7
 
8
- def temperature_dropped?
9
- @temperature_dropped == true
10
- end
11
8
 
12
9
  def generate_completion(prompt, options = {})
13
10
  @temperature_dropped = false
@@ -15,11 +12,11 @@ module CompletionKit
15
12
 
16
13
  model = options[:model] || "claude-3-7-sonnet-latest"
17
14
  max_tokens = options[:max_tokens] || 1000
18
- temperature = options[:temperature] || 0.7
15
+ temperature = resolve_temperature(options)
19
16
 
20
17
  response = post_messages(model: model, prompt: prompt, max_tokens: max_tokens, temperature: temperature)
21
18
 
22
- if response.status == 400 && temperature_unsupported?(response.body)
19
+ if response.status == 400 && !temperature.nil? && temperature_unsupported?(response.body)
23
20
  @temperature_dropped = true
24
21
  response = post_messages(model: model, prompt: prompt, max_tokens: max_tokens, temperature: nil)
25
22
  end
@@ -97,9 +94,5 @@ module CompletionKit
97
94
  end
98
95
  end
99
96
 
100
- def temperature_unsupported?(body)
101
- s = body.to_s
102
- s.include?("temperature") && (s.include?("deprecated") || s.include?("not supported"))
103
- end
104
97
  end
105
98
  end
@@ -1,8 +1,5 @@
1
1
  module CompletionKit
2
2
  class AzureFoundryClient < LlmClient
3
- def temperature_dropped?
4
- @temperature_dropped == true
5
- end
6
3
 
7
4
  def generate_completion(prompt, options = {})
8
5
  @temperature_dropped = false
@@ -11,7 +8,7 @@ module CompletionKit
11
8
 
12
9
  model = options[:model]
13
10
  max_tokens = options[:max_tokens] || 1000
14
- temperature = options[:temperature] || 0.7
11
+ temperature = resolve_temperature(options)
15
12
  max_completion = false
16
13
 
17
14
  response = post_chat(model: model, prompt: prompt, max_tokens: max_tokens, temperature: temperature, max_completion: max_completion)
@@ -129,10 +126,6 @@ module CompletionKit
129
126
  end
130
127
  end
131
128
 
132
- def temperature_unsupported?(body)
133
- s = body.to_s
134
- s.include?("temperature") && (s.include?("deprecated") || s.include?("not supported") || s.include?("Unsupported parameter"))
135
- end
136
129
 
137
130
  def max_tokens_unsupported?(body)
138
131
  s = body.to_s
@@ -13,6 +13,10 @@ module CompletionKit
13
13
  @judge_client = LlmClient.for_model(@judge_model, ApiConfig.for_model(@judge_model))
14
14
  end
15
15
 
16
+ def temperature_dropped?
17
+ @judge_client.temperature_dropped?
18
+ end
19
+
16
20
  def evaluate(output, expected_output = nil, prompt = nil, criteria: nil, rubric_text: nil, input_data: nil, human_examples: nil, **_extras)
17
21
  raise CompletionKit::ConfigurationError, "Judge not configured" unless @judge_client.configured?
18
22
 
@@ -4,10 +4,39 @@ require "json"
4
4
 
5
5
  module CompletionKit
6
6
  class LlmClient
7
+ DEFAULT_TEMPERATURE = 0.7
8
+
9
+ # Providers phrase a temperature refusal every which way. OpenAI's current
10
+ # reasoning models say "Unsupported value: 'temperature' does not support
11
+ # 0.7 with this model. Only the default (1) value is supported.", which
12
+ # shares no wording with Azure's "Unsupported parameter" or Anthropic's
13
+ # "not supported". Matching on any one phrasing silently turns a
14
+ # recoverable refusal into a failed row.
15
+ #
16
+ # The wording can sit on either side of the parameter name, so both orders
17
+ # carry the same phrase set. The gap cannot cross a brace, which keeps a
18
+ # refusal aimed at some other parameter from matching a temperature echoed
19
+ # back in a neighbouring object of the same error body. That would
20
+ # otherwise strip a temperature the model was perfectly happy with and
21
+ # flag the run as having had it ignored.
22
+ REFUSAL_PHRASE = /
23
+ deprecated | not\s+supported | does\s+not\s+support |
24
+ only\s+the\s+default | unsupported\s+(?:parameter|value)
25
+ /xi
26
+ TEMPERATURE_REFUSAL = /
27
+ temperature [^{}]{0,80}? #{REFUSAL_PHRASE}
28
+ |
29
+ #{REFUSAL_PHRASE} [^{}]{0,80}? temperature
30
+ /xi
31
+
7
32
  def initialize(config = {})
8
33
  @config = config
9
34
  end
10
35
 
36
+ def temperature_dropped?
37
+ @temperature_dropped == true
38
+ end
39
+
11
40
  def generate_completion(prompt, options = {})
12
41
  raise NotImplementedError, "Subclasses must implement generate_completion"
13
42
  end
@@ -50,6 +79,17 @@ module CompletionKit
50
79
 
51
80
  protected
52
81
 
82
+ # An explicit nil means the caller wants no temperature sent at all, which
83
+ # is the only request many current models accept. An absent key still gets
84
+ # the historical default.
85
+ def resolve_temperature(options)
86
+ options.key?(:temperature) ? options[:temperature] : DEFAULT_TEMPERATURE
87
+ end
88
+
89
+ def temperature_unsupported?(body)
90
+ TEMPERATURE_REFUSAL.match?(body.to_s)
91
+ end
92
+
53
93
  def build_connection(url, timeout: nil, open_timeout: nil)
54
94
  Faraday.new(url: url) do |f|
55
95
  f.options.timeout = timeout if timeout
@@ -181,7 +181,9 @@ module CompletionKit
181
181
  if run.metric_ids.empty?
182
182
  warnings << "No metrics are attached, so this run judges nothing. Attach metric_ids or a metric_group_id before generating."
183
183
  end
184
- if run.nondeterministic_judge?
184
+ if run.judge_temperature_ignored?
185
+ warnings << "The judge model refused the temperature parameter, so it was re-sent without one and the provider applied its own default. judge_temperature reads #{run.judge_temperature} but was never applied, and these scores are not reproducible. Pick a judge model that accepts temperature if you need reproducible scoring."
186
+ elsif run.nondeterministic_judge?
185
187
  warnings << "Judge temperature is #{run.judge_temperature}. Judging above 0 makes scores irreproducible: the same output can get a different score on a re-judge. Set judge_temperature to 0 unless you are deliberately measuring judge variance."
186
188
  end
187
189
  return json if warnings.empty?
@@ -1,8 +1,5 @@
1
1
  module CompletionKit
2
2
  class OllamaClient < LlmClient
3
- def temperature_dropped?
4
- @temperature_dropped == true
5
- end
6
3
 
7
4
  def generate_completion(prompt, options = {})
8
5
  @temperature_dropped = false
@@ -11,11 +8,11 @@ module CompletionKit
11
8
 
12
9
  model = options[:model]
13
10
  max_tokens = options[:max_tokens] || 1000
14
- temperature = options[:temperature] || 0.7
11
+ temperature = resolve_temperature(options)
15
12
 
16
13
  response = post_completion(model: model, prompt: prompt, max_tokens: max_tokens, temperature: temperature)
17
14
 
18
- if response.status == 400 && temperature_unsupported?(response.body)
15
+ if response.status == 400 && !temperature.nil? && temperature_unsupported?(response.body)
19
16
  @temperature_dropped = true
20
17
  response = post_completion(model: model, prompt: prompt, max_tokens: max_tokens, temperature: nil)
21
18
  end
@@ -97,9 +94,5 @@ module CompletionKit
97
94
  end
98
95
  end
99
96
 
100
- def temperature_unsupported?(body)
101
- s = body.to_s
102
- s.include?("temperature") && (s.include?("deprecated") || s.include?("not supported") || s.include?("Unsupported parameter"))
103
- end
104
97
  end
105
98
  end
@@ -6,9 +6,6 @@ module CompletionKit
6
6
  { id: "gpt-4o-mini", name: "GPT-4o Mini" }
7
7
  ].freeze
8
8
 
9
- def temperature_dropped?
10
- @temperature_dropped == true
11
- end
12
9
 
13
10
  def generate_completion(prompt, options = {})
14
11
  @temperature_dropped = false
@@ -16,11 +13,11 @@ module CompletionKit
16
13
 
17
14
  model = options[:model] || "gpt-4.1-mini"
18
15
  max_tokens = options[:max_tokens] || 8192
19
- temperature = options[:temperature] || 0.7
16
+ temperature = resolve_temperature(options)
20
17
 
21
18
  response = post_responses(model: model, prompt: prompt, max_tokens: max_tokens, temperature: temperature)
22
19
 
23
- if response.status == 400 && temperature_unsupported?(response.body)
20
+ if response.status == 400 && !temperature.nil? && temperature_unsupported?(response.body)
24
21
  @temperature_dropped = true
25
22
  response = post_responses(model: model, prompt: prompt, max_tokens: max_tokens, temperature: nil)
26
23
  end
@@ -38,7 +35,7 @@ module CompletionKit
38
35
  data = JSON.parse(response.body)
39
36
  if data["status"] == "incomplete"
40
37
  reason = data.dig("incomplete_details", "reason") || "unknown"
41
- return "Error: response incomplete (#{reason}) increase max_tokens=#{max_tokens} or pick a non-reasoning judge model"
38
+ return "Error: response incomplete (#{reason}). Increase max_tokens=#{max_tokens} or pick a non-reasoning judge model"
42
39
  end
43
40
  message = Array(data["output"]).find { |o| o["type"] == "message" }
44
41
  content = message&.dig("content", 0, "text").to_s.strip
@@ -93,9 +90,5 @@ module CompletionKit
93
90
  end
94
91
  end
95
92
 
96
- def temperature_unsupported?(body)
97
- s = body.to_s
98
- s.include?("temperature") && (s.include?("deprecated") || s.include?("not supported") || s.include?("Unsupported parameter"))
99
- end
100
93
  end
101
94
  end
@@ -4,9 +4,6 @@ module CompletionKit
4
4
  REFERER = "https://completionkit.com".freeze
5
5
  APP_TITLE = "CompletionKit".freeze
6
6
 
7
- def temperature_dropped?
8
- @temperature_dropped == true
9
- end
10
7
 
11
8
  def generate_completion(prompt, options = {})
12
9
  @temperature_dropped = false
@@ -14,11 +11,11 @@ module CompletionKit
14
11
 
15
12
  model = options[:model] || "openai/gpt-4o-mini"
16
13
  max_tokens = options[:max_tokens] || 8192
17
- temperature = options[:temperature] || 0.7
14
+ temperature = resolve_temperature(options)
18
15
 
19
16
  response = post_chat(model: model, prompt: prompt, max_tokens: max_tokens, temperature: temperature)
20
17
 
21
- if response.status == 400 && temperature_unsupported?(response.body)
18
+ if response.status == 400 && !temperature.nil? && temperature_unsupported?(response.body)
22
19
  @temperature_dropped = true
23
20
  response = post_chat(model: model, prompt: prompt, max_tokens: max_tokens, temperature: nil)
24
21
  end
@@ -90,9 +87,5 @@ module CompletionKit
90
87
  end
91
88
  end
92
89
 
93
- def temperature_unsupported?(body)
94
- s = body.to_s
95
- s.include?("temperature") && (s.include?("deprecated") || s.include?("not supported") || s.include?("Unsupported parameter"))
96
- end
97
90
  end
98
91
  end
@@ -85,12 +85,21 @@
85
85
 
86
86
  <div class="ck-field">
87
87
  <label class="ck-label" for="run_temperature" style="position: relative;">
88
- Temperature<span class="ck-info-toggle" tabindex="0">?</span><span class="ck-info-popup">Controls how random the model's output is. Lower values are more focused and deterministic the model picks the most likely words. Higher values are more varied and creative, with more risk of odd phrasing. Most LLMs default to 1.0; for evaluation, try a few values and see how your prompt holds up. Newer reasoning models (Claude Opus 4.7, GPT-5 family, etc.) ignore temperature entirely CompletionKit detects this and re-sends without the parameter.</span>
88
+ Temperature<span class="ck-info-toggle" tabindex="0">?</span><span class="ck-info-popup">Controls how random the model's output is. Lower values are more focused and deterministic, so the model picks the most likely words. Higher values are more varied and creative, with more risk of odd phrasing. Most LLMs default to 1.0; for evaluation, try a few values and see how your prompt holds up. Newer reasoning models (Claude Opus 4.7, GPT-5 family, etc.) refuse temperature outright. CompletionKit detects that and re-sends without the parameter, and flags the run so you know the value was never applied. Tick the box below to skip sending it in the first place.</span>
89
89
  </label>
90
90
  <div class="ck-slider-row">
91
- <%= form.range_field :temperature, min: 0, max: 1, step: 0.1, class: "ck-slider", id: "run_temperature", oninput: "document.getElementById('temp-value').textContent = this.value" %>
92
- <span class="ck-slider-value" id="temp-value"><%= run.temperature || 1.0 %></span>
91
+ <%= form.range_field :temperature, min: 0, max: 1, step: 0.1, class: "ck-slider", id: "run_temperature", disabled: run.temperature.nil?, oninput: "document.getElementById('temp-value').textContent = this.value" %>
92
+ <span class="ck-slider-value" id="temp-value"><%= run.temperature.nil? ? "off" : run.temperature %></span>
93
93
  </div>
94
+ <label class="ck-checkbox-label">
95
+ <%= check_box_tag "run[omit_temperature]", "1", run.temperature.nil?, id: "run_omit_temperature", class: "ck-checkbox",
96
+ onchange: "document.getElementById('run_temperature').disabled = this.checked; document.getElementById('temp-value').textContent = this.checked ? 'off' : document.getElementById('run_temperature').value;" %>
97
+ <span class="ck-checkbox-label__box" aria-hidden="true"></span>
98
+ <span class="ck-checkbox-label__body">
99
+ <span class="ck-checkbox-label__text">Send no temperature</span>
100
+ <span class="ck-checkbox-label__hint">The model applies its own default. Required by models that refuse the parameter, which most current frontier models do.</span>
101
+ </span>
102
+ </label>
94
103
  </div>
95
104
 
96
105
  <div class="ck-field">
@@ -96,7 +96,9 @@
96
96
  <div class="ck-run-config__row">
97
97
  <span class="ck-run-config__key">Judge temperature</span>
98
98
  <span><%= @run.judge_temperature %></span>
99
- <% if @run.nondeterministic_judge? %>
99
+ <% if @run.judge_temperature_ignored? %>
100
+ <span class="ck-run-config__warn" style="color: var(--ck-warning);" title="The judge model refused the temperature parameter, so CompletionKit re-sent the request without it and the provider applied its own default. The scores are not reproducible despite the setting above.">refused by judge, not reproducible</span>
101
+ <% elsif @run.nondeterministic_judge? %>
100
102
  <span class="ck-run-config__warn" style="color: var(--ck-warning);" title="Judging above temperature 0 makes scores irreproducible. The same output can get a different score on a re-judge.">scores not reproducible</span>
101
103
  <% end %>
102
104
  </div>
@@ -0,0 +1,5 @@
1
+ class AddJudgeTemperatureIgnoredToRuns < ActiveRecord::Migration[8.0]
2
+ def change
3
+ add_column :completion_kit_runs, :judge_temperature_ignored, :boolean, default: false, null: false
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module CompletionKit
2
- VERSION = "0.28.34"
2
+ VERSION = "0.28.35"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: completion-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.28.34
4
+ version: 0.28.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Bastin
@@ -447,6 +447,7 @@ files:
447
447
  - db/migrate/20260728000001_add_max_tokens_to_completion_kit_runs.rb
448
448
  - db/migrate/20260730000001_add_judge_temperature_to_completion_kit_runs.rb
449
449
  - db/migrate/20260730000002_create_completion_kit_prompt_serves.rb
450
+ - db/migrate/20260804000001_add_judge_temperature_ignored_to_runs.rb
450
451
  - lib/completion-kit.rb
451
452
  - lib/completion_kit.rb
452
453
  - lib/completion_kit/concurrency_check.rb