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.2-astra gpt-6.2-sol gpt-6.1-terra 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-2
  claude-mythos-5-2
  claude-opus-5-5
  claude-sonnet-5-5
  claude-haiku-5-5
  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(?:\.\d+)?-(?:astra|sol|luna|terra)(?:\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(?:\.\d+)?-(?:astra|sol|luna|terra)(?:\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|haiku)-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



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

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

.anthropic_reasoning_effort_choices(id) ⇒ Object



479
480
481
482
483
484
485
486
# File 'lib/kward/model/model_info.rb', line 479

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|haiku)-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



543
544
545
546
547
548
# File 'lib/kward/model/model_info.rb', line 543

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



258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/kward/model/model_info.rb', line 258

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



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

def config_provider_for_provider(provider)
  provider_config_value(provider)
end

.config_values_for_selection(provider, model) ⇒ Object



292
293
294
295
296
297
# File 'lib/kward/model/model_info.rb', line 292

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



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

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

.conservative_context_window(id) ⇒ Object



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

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



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

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



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

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

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



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
327
328
329
330
331
# File 'lib/kward/model/model_info.rb', line 299

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



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

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



372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/kward/model/model_info.rb', line 372

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



530
531
532
533
534
535
536
537
538
539
540
541
# File 'lib/kward/model/model_info.rb', line 530

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

.default_selectable_model?(model) ⇒ Boolean

Unknown capabilities and the selection in the caller's context stay visible.

Returns:

  • (Boolean)


489
490
491
492
493
494
495
496
497
498
# File 'lib/kward/model/model_info.rb', line 489

def default_selectable_model?(model)
  return true if model[:current]

  capabilities = Array(model[:supportedParameters]).map { |value| value.to_s.downcase }
  return true if capabilities.empty?

  capabilities.any? do |capability|
    ["tools", "toolchoice", "functioncalling", "generatecontent", "streamgeneratecontent"].include?(capability.delete("_-"))
  end
end

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



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/kward/model/model_info.rb', line 145

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



500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
# File 'lib/kward/model/model_info.rb', line 500

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: current_provider && current_model ? provider == current_provider && id == current_model : boolean_value(model["current"])
  }.compact.then { |entry| entry.merge(defaultSelectable: default_selectable_model?(entry)) }
end

.normalize_anthropic_model(id) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/kward/model/model_info.rb', line 173

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



519
520
521
522
523
524
525
526
527
528
# File 'lib/kward/model/model_info.rb', line 519

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



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/kward/model/model_info.rb', line 188

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



468
469
470
471
472
473
474
475
476
477
# File 'lib/kward/model/model_info.rb', line 468

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 OPENAI_MAX_REASONING_EFFORT_CHOICES if text.match?(/\Agpt-6\.1-terra(?:\z|-)/)
  return GPT_6_REASONING_EFFORT_CHOICES if text.match?(/\Agpt-6\.2-(?:astra|sol)(?:\z|-)|\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



338
339
340
341
342
343
344
345
346
# File 'lib/kward/model/model_info.rb', line 338

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



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

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



354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/kward/model/model_info.rb', line 354

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



348
349
350
351
352
# File 'lib/kward/model/model_info.rb', line 348

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



333
334
335
336
# File 'lib/kward/model/model_info.rb', line 333

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

.positive_integer(value) ⇒ Object



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

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

.provider_config_value(provider) ⇒ Object



243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/kward/model/model_info.rb', line 243

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



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/kward/model/model_info.rb', line 227

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



273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/kward/model/model_info.rb', line 273

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



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/kward/model/model_info.rb', line 207

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



453
454
455
456
457
458
459
460
461
462
463
464
465
466
# File 'lib/kward/model/model_info.rb', line 453

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)


438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/kward/model/model_info.rb', line 438

def reasoning_supported?(provider, id)
  case provider
  when "Codex", "OpenRouter"
    true
  when "OpenAI"
    id.to_s.match?(/\Agpt-6(?:\.\d+)?-(?:astra|sol|luna|terra)(?:\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



550
551
552
# File 'lib/kward/model/model_info.rb', line 550

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

.supports_images?(provider, id) ⇒ Boolean

Returns:

  • (Boolean)


432
433
434
435
436
# File 'lib/kward/model/model_info.rb', line 432

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

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