Skip to content
Kward Search API index

Module: Kward::ModelInfo

Defined in:
lib/kward/model/model_info.rb

Overview

Static and configured model metadata helpers.

Constant Summary collapse

DEFAULT_OPENAI_MODEL =
"gpt-5.6-sol"
DEFAULT_COPILOT_MODEL =
"gpt-5-mini"
DEFAULT_ANTHROPIC_MODEL =
"claude-sonnet-5"
DEFAULT_REASONING_EFFORT =
"medium"
OPENAI_MODEL_CHOICES =
%w[gpt-6-astra gpt-6.1-sol gpt-6-luna gpt-5.6-sol gpt-5.6-terra gpt-5.6-luna gpt-5.5 gpt-5.4 gpt-5.4-mini gpt-5.3-codex-spark].freeze
ANTHROPIC_MODEL_CHOICES =
%w[
  claude-fable-5
  claude-opus-5
  claude-opus-4-8
  claude-sonnet-5
  claude-sonnet-4-6
  claude-haiku-4-5
  claude-opus-4-7
  claude-opus-4-6
  claude-opus-4-5
  claude-sonnet-4-5
].freeze
COPILOT_MODEL_CHOICES =
%w[
  gpt-5-mini
  gpt-6-astra
  gpt-5.3-codex
  gpt-5.4
  gpt-5.4-mini
  gpt-5.5
  claude-haiku-4.5
  claude-opus-4.5
  claude-opus-4.7
  claude-opus-4.8
  claude-sonnet-4.5
  claude-sonnet-4.6
  gemini-2.5-pro
  gemini-3-flash-preview
  gemini-3.1-pro-preview
  gemini-3.5-flash
  oswe-vscode-prime
].freeze
REASONING_EFFORT_CHOICES =
[
  ["low", "Low"],
  ["medium", "Medium"],
  ["high", "High"],
  ["xhigh", "Extra High"]
].freeze
OPENAI_REASONING_EFFORT_CHOICES =
[
  ["none", "None"],
  *REASONING_EFFORT_CHOICES
].freeze
OPENAI_MAX_REASONING_EFFORT_CHOICES =
[
  *OPENAI_REASONING_EFFORT_CHOICES,
  ["max", "Max"]
].freeze
GPT_6_REASONING_EFFORT_CHOICES =
[
  *REASONING_EFFORT_CHOICES,
  ["max", "Max"]
].freeze
GPT_6_LUNA_REASONING_EFFORT_CHOICES =
[
  *OPENAI_REASONING_EFFORT_CHOICES,
  ["max", "Max"]
].freeze
ANTHROPIC_HIGH_REASONING_EFFORT_CHOICES =
[
  ["low", "Low"],
  ["medium", "Medium"],
  ["high", "High"],
  ["xhigh", "Extra High"],
  ["max", "Max"]
].freeze
ANTHROPIC_STANDARD_REASONING_EFFORT_CHOICES =
[
  ["low", "Low"],
  ["medium", "Medium"],
  ["high", "High"],
  ["max", "Max"]
].freeze
ANTHROPIC_OPUS_4_5_REASONING_EFFORT_CHOICES =
[
  ["low", "Low"],
  ["medium", "Medium"],
  ["high", "High"]
].freeze
IMAGE_UNSUPPORTED_MODELS =
[
  /(?:\A|\/)gpt-5\.3-codex-spark\z/
].freeze
CODEX_CONTEXT_WINDOWS =
[
  [/\Agpt-6(?:\.1)?-(?:astra|sol|luna)(?:\z|-)/, 1_050_000],
  [/\Agpt-5\.6/, 1_050_000],
  [/\Agpt-5\.5/, 400_000],
  [/\Agpt-5\.4-mini/, 400_000],
  [/\Agpt-5\.4/, 1_050_000],
  [/\Agpt-5-mini/, 400_000],
  [/\Agpt-5-codex/, 400_000],
  [/\Agpt-5\.3-codex-spark/, 128_000],
  [/\Agpt-5\.3-codex/, 400_000],
  [/\Agpt-5\.2-codex/, 400_000],
  [/\Agpt-5/, 400_000],
  [/\Agpt-4\.1/, 1_047_576],
  [/\Agpt-4o/, 128_000],
  [/\Ao3/, 200_000],
  [/\Ao4/, 200_000],
  [/\Agpt-4/, 128_000],
  [/\Agpt-3\.5-turbo/, 16_385]
].freeze
OPENAI_CONTEXT_WINDOWS =
[
  [/\Agpt-6(?:\.1)?-(?:astra|sol|luna)(?:\z|-)/, 1_050_000],
  [/\Agpt-5\.6/, 1_050_000],
  [/\Agpt-5\.5/, 1_050_000],
  [/\Agpt-5\.4-mini/, 400_000],
  [/\Agpt-5\.4/, 1_050_000],
  [/\Agpt-5-mini/, 400_000],
  [/\Agpt-5-codex/, 400_000],
  [/\Agpt-5\.3-codex-spark/, 128_000],
  [/\Agpt-5\.3-codex/, 400_000],
  [/\Agpt-5\.2-codex/, 400_000],
  [/\Agpt-5/, 400_000],
  [/\Agpt-4\.1/, 1_047_576],
  [/\Agpt-4o/, 128_000],
  [/\Ao3/, 200_000],
  [/\Ao4/, 200_000],
  [/\Agpt-4/, 128_000],
  [/\Agpt-3\.5-turbo/, 16_385]
].freeze
ANTHROPIC_CONTEXT_WINDOWS =
[
  [/\Aclaude-(?:fable|mythos|opus|sonnet)-5(?:\z|-)/, 1_000_000],
  [/\Aclaude-opus-4-(?:6|7|8)(?:\z|-)/, 1_000_000],
  [/\Aclaude-sonnet-4-6(?:\z|-)/, 1_000_000],
  [/\Aclaude-(?:haiku|opus|sonnet)-4-5(?:\z|-)/, 200_000],
  [/\Aclaude-(?:haiku|opus|sonnet)-4(?:\z|-)/, 200_000]
].freeze
GEMINI_CONTEXT_WINDOWS =
[
  [/\Agemini-(?:2\.5-pro|3(?:\.1)?-pro|3(?:\.5)?-flash)/, 1_048_576]
].freeze

Class Method Summary collapse

Class Method Details

.anthropic_context_window(id) ⇒ Object



423
424
425
# File 'lib/kward/model/model_info.rb', line 423

def anthropic_context_window(id)
  pattern_context_window(ANTHROPIC_CONTEXT_WINDOWS, normalize_anthropic_model(id))
end

.anthropic_reasoning_effort_choices(id) ⇒ Object



473
474
475
476
477
478
479
480
# File 'lib/kward/model/model_info.rb', line 473

def anthropic_reasoning_effort_choices(id)
  text = normalize_anthropic_model(id)
  return ANTHROPIC_HIGH_REASONING_EFFORT_CHOICES if text.match?(/\Aclaude-(?:fable|mythos|opus|sonnet)-5(?:\z|-)|\Aclaude-opus-4-(?:7|8)(?:\z|-)/)
  return ANTHROPIC_STANDARD_REASONING_EFFORT_CHOICES if text.match?(/\Aclaude-(?:opus-4-6|sonnet-4-6)(?:\z|-)/)
  return ANTHROPIC_OPUS_4_5_REASONING_EFFORT_CHOICES if text.match?(/\Aclaude-opus-4-5(?:\z|-)/)

  []
end

.boolean_value(value, default: false) ⇒ Object



525
526
527
528
529
530
# File 'lib/kward/model/model_info.rb', line 525

def boolean_value(value, default: false)
  return default if value.nil?
  return value if value == true || value == false

  value.to_s == "true"
end

.config_key_for_provider(provider) ⇒ Object



253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/kward/model/model_info.rb', line 253

def config_key_for_provider(provider)
  return ProviderCatalog.runtime("openai").model_config_key if provider_label(provider) == "OpenAI"

  catalog_provider = ProviderCatalog.find(provider.to_s.downcase) || ProviderCatalog.find_by_name(provider)
  return ProviderCatalog.runtime(catalog_provider.id).model_config_key if catalog_provider && catalog_provider.id != "openai"

  case provider.to_s.downcase
  when "openrouter" then "openrouter_model"
  when "copilot" then "copilot_model"
  when "anthropic", "claude" then "anthropic_model"
  when "local" then "local_model"
  else "openai_model"
  end
end

.config_provider_for_provider(provider) ⇒ Object



283
284
285
# File 'lib/kward/model/model_info.rb', line 283

def config_provider_for_provider(provider)
  provider_config_value(provider)
end

.config_values_for_selection(provider, model) ⇒ Object



287
288
289
290
291
292
# File 'lib/kward/model/model_info.rb', line 287

def config_values_for_selection(provider, model)
  {
    config_key_for_provider(provider) => model,
    "provider" => config_provider_for_provider(provider)
  }
end

.conservative_anthropic_context_window(id) ⇒ Object



394
395
396
# File 'lib/kward/model/model_info.rb', line 394

def conservative_anthropic_context_window(id)
  id.to_s.strip.empty? ? nil : 200_000
end

.conservative_context_window(id) ⇒ Object



387
388
389
390
391
392
# File 'lib/kward/model/model_info.rb', line 387

def conservative_context_window(id)
  text = id.to_s
  return 128_000 if text.match?(/\A(?:gpt-|o\d)/)
  return 200_000 if text.start_with?("claude-")
  return 128_000 if text.start_with?("gemini-")
end

.conservative_openrouter_context_window(id) ⇒ Object



409
410
411
412
413
414
# File 'lib/kward/model/model_info.rb', line 409

def conservative_openrouter_context_window(id)
  text = id.to_s
  return conservative_context_window(text.delete_prefix("openai/")) if text.start_with?("openai/")
  return conservative_context_window(normalize_anthropic_model(text.delete_prefix("anthropic/"))) if text.start_with?("anthropic/")
  return conservative_context_window(text.delete_prefix("google/")) if text.start_with?("google/")
end

.conservative_unknown_context_window(id) ⇒ Object



398
399
400
# File 'lib/kward/model/model_info.rb', line 398

def conservative_unknown_context_window(id)
  id.to_s.strip.empty? ? nil : 128_000
end

.context_window(provider, id, openrouter_models: nil) ⇒ Object



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/kward/model/model_info.rb', line 294

def context_window(provider, id, openrouter_models: nil)
  case provider
  when "Azure OpenAI"
    pattern_context_window(OPENAI_CONTEXT_WINDOWS, id) ||
      conservative_unknown_context_window(id)
  when "Google Gemini"
    pattern_context_window(GEMINI_CONTEXT_WINDOWS, id.to_s.delete_prefix("models/")) ||
      conservative_unknown_context_window(id)
  when "OpenAI"
    pattern_context_window(OPENAI_CONTEXT_WINDOWS, id) ||
      conservative_context_window(id) ||
      conservative_unknown_context_window(id)
  when "Codex"
    pattern_context_window(CODEX_CONTEXT_WINDOWS, id) ||
      openrouter_inferred_context_window(provider, id, openrouter_models: openrouter_models) ||
      conservative_context_window(id)
  when "OpenRouter"
    openrouter_cached_context_window(openrouter_models, id) ||
      openrouter_context_window(id) ||
      conservative_openrouter_context_window(id) ||
      conservative_unknown_context_window(id)
  when "Copilot"
    copilot_context_window(id) ||
      openrouter_inferred_context_window(provider, id, openrouter_models: openrouter_models) ||
      conservative_context_window(id) ||
      conservative_unknown_context_window(id)
  when "Anthropic"
    anthropic_context_window(id) ||
      openrouter_inferred_context_window(provider, id, openrouter_models: openrouter_models) ||
      conservative_context_window(normalize_anthropic_model(id)) ||
      conservative_anthropic_context_window(id)
  end
end

.copilot_context_window(id) ⇒ Object



416
417
418
419
420
421
# File 'lib/kward/model/model_info.rb', line 416

def copilot_context_window(id)
  text = id.to_s
  pattern_context_window(OPENAI_CONTEXT_WINDOWS, text) ||
    anthropic_context_window(normalize_anthropic_model(text)) ||
    pattern_context_window(GEMINI_CONTEXT_WINDOWS, text)
end

.copilot_openrouter_equivalent_ids(id) ⇒ Object



367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/kward/model/model_info.rb', line 367

def copilot_openrouter_equivalent_ids(id)
  return ["openai/#{id.delete_prefix("openai/")}"] if id.start_with?("openai/") || id.match?(/\A(?:gpt-|o\d)/)
  return ["google/#{id.delete_prefix("google/")}"] if id.start_with?("google/") || id.start_with?("gemini-")

  if id.start_with?("anthropic/") || id.start_with?("claude-")
    raw = id.delete_prefix("anthropic/")
    normalized = normalize_anthropic_model(raw)
    return ["anthropic/#{raw}", "anthropic/#{normalized}"].uniq
  end

  []
end

.current_payload(provider:, model:, reasoning_effort: nil, context_window: nil) ⇒ Object



512
513
514
515
516
517
518
519
520
521
522
523
# File 'lib/kward/model/model_info.rb', line 512

def current_payload(provider:, model:, reasoning_effort: nil, context_window: nil)
  normalize(
    {
      provider: provider,
      id: model,
      model: model,
      reasoningEffort: reasoning_effort,
      contextWindow: context_window,
      current: true
    }
  )
end

.model_for(provider, config:, override_model: nil, env: ENV) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/kward/model/model_info.rb', line 140

def model_for(provider, config:, override_model: nil, env: ENV)
  return override_model if override_model

  if provider_label(provider) == "OpenAI"
    runtime = ProviderCatalog.runtime("openai")
    return env["OPENAI_API_MODEL"] || ConfigFiles.config_value(config, runtime.model_config_key) || DEFAULT_OPENAI_MODEL
  end

  catalog_provider = ProviderCatalog.find_by_name(provider) || ProviderCatalog.find(provider.to_s.downcase)
  if catalog_provider && !["anthropic", "openrouter", "copilot"].include?(catalog_provider.id)
    runtime = ProviderCatalog.runtime(catalog_provider.id)
    return env["#{catalog_provider.id.upcase}_MODEL"] || ConfigFiles.config_value(config, runtime.model_config_key, "model")
  end

  case provider
  when "Local"
    env["KWARD_LOCAL_MODEL"] || ConfigFiles.config_value(config, "local_model")
  when "OpenRouter"
    env["OPENROUTER_MODEL"] || ConfigFiles.config_value(config, "openrouter_model", "model")
  when "Copilot"
    normalize_copilot_model(env["COPILOT_MODEL"] || ConfigFiles.config_value(config, "copilot_model", "model") || DEFAULT_COPILOT_MODEL)
  when "Anthropic"
    normalize_anthropic_model(env["ANTHROPIC_MODEL"] || ConfigFiles.config_value(config, "anthropic_model", "model") || DEFAULT_ANTHROPIC_MODEL)
  else
    env["OPENAI_MODEL"] || ConfigFiles.config_value(config, "openai_model", "model") || DEFAULT_OPENAI_MODEL
  end
end

.normalize(model, current_provider: nil, current_model: nil, current_reasoning_effort: nil) ⇒ Object



482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
# File 'lib/kward/model/model_info.rb', line 482

def normalize(model, current_provider: nil, current_model: nil, current_reasoning_effort: nil)
  model = stringify_keys(model || {})
  provider = model["provider"]
  id = model["id"] || model["model"]
  reasoning = boolean_value(model["reasoning"], default: reasoning_supported?(provider, id))
  reasoning_effort = model["reasoningEffort"] || model["reasoning_effort"] || (current_reasoning_effort if reasoning)
  {
    provider: provider,
    id: id,
    name: model["name"] || id,
    reasoning: reasoning,
    reasoningEffort: reasoning_effort,
    contextWindow: model["contextWindow"] || model["context_window"] || context_window(provider, id),
    supportedParameters: model["supportedParameters"] || model["supported_parameters"],
    source: model["source"],
    current: boolean_value(model["current"], default: provider == current_provider && id == current_model)
  }.compact
end

.normalize_anthropic_model(id) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/kward/model/model_info.rb', line 168

def normalize_anthropic_model(id)
  text = id.to_s.strip
  return DEFAULT_ANTHROPIC_MODEL if text.empty?
  text = text.delete_prefix("anthropic/").delete_prefix("claude/")
  {
    "claude-sonnet-4.6" => "claude-sonnet-4-6",
    "claude-sonnet-4.5" => "claude-sonnet-4-5",
    "claude-opus-4.8" => "claude-opus-4-8",
    "claude-opus-4.7" => "claude-opus-4-7",
    "claude-opus-4.6" => "claude-opus-4-6",
    "claude-opus-4.5" => "claude-opus-4-5",
    "claude-haiku-4.5" => "claude-haiku-4-5"
  }.fetch(text, text)
end

.normalize_available(models, current_provider:, current_model:, current_reasoning_effort: nil) ⇒ Object



501
502
503
504
505
506
507
508
509
510
# File 'lib/kward/model/model_info.rb', line 501

def normalize_available(models, current_provider:, current_model:, current_reasoning_effort: nil)
  Array(models).map do |model|
    normalize(
      model,
      current_provider: current_provider,
      current_model: current_model,
      current_reasoning_effort: current_reasoning_effort
    )
  end
end

.normalize_copilot_model(id) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/kward/model/model_info.rb', line 183

def normalize_copilot_model(id)
  text = id.to_s.strip
  return DEFAULT_COPILOT_MODEL if text.empty?
  text = text.delete_prefix("copilot/")

  {
    "claude-haiku-4-5" => "claude-haiku-4.5",
    "claude-opus-4-5" => "claude-opus-4.5",
    "claude-opus-4-6" => "claude-opus-4.6",
    "claude-opus-4-6-fast" => "claude-opus-4.6-fast",
    "claude-opus-4-7" => "claude-opus-4.7",
    "claude-opus-4-8" => "claude-opus-4.8",
    "claude-sonnet-4-5" => "claude-sonnet-4.5",
    "claude-sonnet-4-6" => "claude-sonnet-4.6",
    "gemini-3.1-pro" => "gemini-3.1-pro-preview",
    "gemini-3-flash" => "gemini-3-flash-preview"
  }.fetch(text, text)
end

.openai_reasoning_effort_choices(id) ⇒ Object



463
464
465
466
467
468
469
470
471
# File 'lib/kward/model/model_info.rb', line 463

def openai_reasoning_effort_choices(id)
  text = id.to_s.delete_prefix("openai/")
  return GPT_6_LUNA_REASONING_EFFORT_CHOICES if text.match?(/\Agpt-6-luna(?:\z|-)/)
  return GPT_6_REASONING_EFFORT_CHOICES if text.match?(/\Agpt-6\.1-sol(?:\z|-)|\Agpt-6-astra(?:\z|-)/)
  return REASONING_EFFORT_CHOICES if text.match?(/\Agpt-5\.[23]-codex/)
  return OPENAI_MAX_REASONING_EFFORT_CHOICES if text.match?(/\Agpt-5\.6(?:\z|-)/)

  OPENAI_REASONING_EFFORT_CHOICES
end

.openrouter_cached_context_window(models, id) ⇒ Object



333
334
335
336
337
338
339
340
341
# File 'lib/kward/model/model_info.rb', line 333

def openrouter_cached_context_window(models, id)
  model = Array(models).find do |entry|
    next false unless entry.respond_to?(:key?)

    entry["id"].to_s == id.to_s || entry[:id].to_s == id.to_s
  end
  value = model && (model["contextWindow"] || model[:contextWindow] || model["context_window"] || model[:context_window])
  positive_integer(value)
end

.openrouter_context_window(id) ⇒ Object



402
403
404
405
406
407
# File 'lib/kward/model/model_info.rb', line 402

def openrouter_context_window(id)
  text = id.to_s
  return pattern_context_window(OPENAI_CONTEXT_WINDOWS, text.delete_prefix("openai/")) if text.start_with?("openai/")
  return anthropic_context_window(text.delete_prefix("anthropic/")) if text.start_with?("anthropic/")
  return pattern_context_window(GEMINI_CONTEXT_WINDOWS, text.delete_prefix("google/")) if text.start_with?("google/")
end

.openrouter_equivalent_ids(provider, id) ⇒ Object



349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/kward/model/model_info.rb', line 349

def openrouter_equivalent_ids(provider, id)
  text = id.to_s.strip
  return [] if text.empty?

  case provider
  when "Codex"
    ["openai/#{text.delete_prefix("openai/")}"]
  when "Anthropic"
    raw = text.delete_prefix("anthropic/")
    normalized = normalize_anthropic_model(raw)
    ["anthropic/#{raw}", "anthropic/#{normalized}"].uniq
  when "Copilot"
    copilot_openrouter_equivalent_ids(text)
  else
    []
  end
end

.openrouter_inferred_context_window(provider, id, openrouter_models: nil) ⇒ Object



343
344
345
346
347
# File 'lib/kward/model/model_info.rb', line 343

def openrouter_inferred_context_window(provider, id, openrouter_models: nil)
  openrouter_equivalent_ids(provider, id).filter_map do |candidate|
    openrouter_cached_context_window(openrouter_models, candidate)
  end.min
end

.pattern_context_window(patterns, id) ⇒ Object



328
329
330
331
# File 'lib/kward/model/model_info.rb', line 328

def pattern_context_window(patterns, id)
  match = patterns.find { |pattern, _window| id.to_s.match?(pattern) }
  match&.last
end

.positive_integer(value) ⇒ Object



380
381
382
383
384
385
# File 'lib/kward/model/model_info.rb', line 380

def positive_integer(value)
  integer = Integer(value)
  integer.positive? ? integer : nil
rescue ArgumentError, TypeError
  nil
end

.provider_config_value(provider) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/kward/model/model_info.rb', line 238

def provider_config_value(provider)
  return ProviderCatalog.runtime("openai").id if provider_label(provider) == "OpenAI"

  catalog_provider = ProviderCatalog.find(provider.to_s.downcase) || ProviderCatalog.find_by_name(provider)
  return ProviderCatalog.runtime(catalog_provider.id).id if catalog_provider && catalog_provider.id != "openai"

  case provider.to_s.downcase
  when "openrouter" then "openrouter"
  when "copilot" then "copilot"
  when "anthropic", "claude" then "anthropic"
  when "local" then "local"
  else "codex"
  end
end

.provider_label(provider) ⇒ Object



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/kward/model/model_info.rb', line 222

def provider_label(provider)
  return "OpenAI" if provider.to_s == "OpenAI" || provider.to_s.downcase == "openai_api"

  catalog_provider = ProviderCatalog.find(provider.to_s.downcase) || ProviderCatalog.find_by_name(provider)
  return catalog_provider.name if catalog_provider && !["openai", "copilot"].include?(catalog_provider.id)

  case provider.to_s.downcase
  when "openrouter" then "OpenRouter"
  when "copilot" then "Copilot"
  when "anthropic", "claude" then "Anthropic"
  when "local" then "Local"
  when "codex", "openai" then "Codex"
  else provider.to_s
  end
end

.reasoning_config_key_for_provider(provider) ⇒ Object



268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/kward/model/model_info.rb', line 268

def reasoning_config_key_for_provider(provider)
  return ProviderCatalog.runtime("openai").reasoning_config_key if provider_label(provider) == "OpenAI"

  catalog_provider = ProviderCatalog.find(provider.to_s.downcase) || ProviderCatalog.find_by_name(provider)
  return ProviderCatalog.runtime(catalog_provider.id).reasoning_config_key if catalog_provider && catalog_provider.id != "openai"

  case provider.to_s.downcase
  when "openrouter" then "openrouter_reasoning_effort"
  when "copilot" then "copilot_reasoning_effort"
  when "anthropic", "claude" then "anthropic_reasoning_effort"
  when "local" then "local_reasoning_effort"
  else "openai_reasoning_effort"
  end
end

.reasoning_effort(config:, env: ENV, provider: nil) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/kward/model/model_info.rb', line 202

def reasoning_effort(config:, env: ENV, provider: nil)
  if provider_label(provider) == "OpenAI"
    runtime = ProviderCatalog.runtime("openai")
    return env["OPENAI_API_REASONING_EFFORT"] || ConfigFiles.config_value(config, runtime.reasoning_config_key) || DEFAULT_REASONING_EFFORT
  end

  case provider.to_s
  when "Local"
    nil
  when "OpenRouter"
    env["OPENROUTER_REASONING_EFFORT"] || ConfigFiles.config_value(config, "openrouter_reasoning_effort", "reasoning_effort", "thinking_level") || DEFAULT_REASONING_EFFORT
  when "Copilot"
    env["COPILOT_REASONING_EFFORT"] || ConfigFiles.config_value(config, "copilot_reasoning_effort", "reasoning_effort", "thinking_level") || DEFAULT_REASONING_EFFORT
  when "Anthropic"
    env["ANTHROPIC_REASONING_EFFORT"] || ConfigFiles.config_value(config, "anthropic_reasoning_effort", "reasoning_effort", "thinking_level") || DEFAULT_REASONING_EFFORT
  else
    env["OPENAI_REASONING_EFFORT"] || ConfigFiles.config_value(config, "openai_reasoning_effort", "reasoning_effort", "thinking_level") || DEFAULT_REASONING_EFFORT
  end
end

.reasoning_effort_choices(provider, id) ⇒ Object



448
449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/kward/model/model_info.rb', line 448

def reasoning_effort_choices(provider, id)
  case provider
  when "Codex", "OpenRouter"
    openai_reasoning_effort_choices(id)
  when "OpenAI"
    reasoning_supported?(provider, id) ? openai_reasoning_effort_choices(id) : []
  when "Anthropic"
    anthropic_reasoning_effort_choices(id)
  when "Copilot"
    id.to_s.match?(/\Agpt-(?:5|6)(?:\.|-|\z)/) ? openai_reasoning_effort_choices(id) : []
  else
    []
  end
end

.reasoning_supported?(provider, id) ⇒ Boolean

Returns:

  • (Boolean)


433
434
435
436
437
438
439
440
441
442
443
444
445
446
# File 'lib/kward/model/model_info.rb', line 433

def reasoning_supported?(provider, id)
  case provider
  when "Codex", "OpenRouter"
    true
  when "OpenAI"
    id.to_s.match?(/\Agpt-6(?:\.1)?-(?:astra|sol|luna)(?:\z|-)/)
  when "Anthropic"
    !reasoning_effort_choices(provider, id).empty?
  when "Copilot"
    id.to_s.match?(/\Agpt-(?:5|6)(?:\.|-|\z)/)
  else
    false
  end
end

.stringify_keys(value) ⇒ Object



532
533
534
# File 'lib/kward/model/model_info.rb', line 532

def stringify_keys(value)
  value.each_with_object({}) { |(key, item), result| result[key.to_s] = item }
end

.supports_images?(provider, id) ⇒ Boolean

Returns:

  • (Boolean)


427
428
429
430
431
# File 'lib/kward/model/model_info.rb', line 427

def supports_images?(provider, id)
  return false if provider == "Local"

  IMAGE_UNSUPPORTED_MODELS.none? { |pattern| id.to_s.match?(pattern) }
end