Skip to content
Kward Search API index

Module: Kward::CopilotModels

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

Overview

Parses and filters GitHub Copilot model catalog responses.

Class Method Summary collapse

Class Method Details

.catalog_entries(body) ⇒ Object



30
31
32
33
34
# File 'lib/kward/model/copilot_models.rb', line 30

def catalog_entries(body)
  data = JSON.parse(body.to_s)
  entries = data.is_a?(Hash) ? data["data"] || data["models"] || data["items"] || [] : data
  Array(entries)
end

.model_id(entry) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/kward/model/copilot_models.rb', line 36

def model_id(entry)
  return entry.to_s.strip unless entry.is_a?(Hash)
  return nil if entry.key?("model_picker_enabled") && entry["model_picker_enabled"] == false

  id = entry["id"] || entry["model"] || entry["name"]
  id.to_s.strip unless id.to_s.strip.empty?
end

.parse(body) ⇒ Object



9
10
11
12
13
# File 'lib/kward/model/copilot_models.rb', line 9

def parse(body)
  catalog_entries(body).filter_map { |entry| model_id(entry) }.uniq
rescue JSON::ParserError
  []
end

.resolved_chat_model(configured_model, choices) ⇒ Object



24
25
26
27
28
# File 'lib/kward/model/copilot_models.rb', line 24

def resolved_chat_model(configured_model, choices)
  return configured_model if choices.empty? || choices.include?(configured_model)

  choices.find { |model| supported?(model) } || raise("No Copilot models supported by Kward are available for this account. Kward currently supports Copilot GPT-5 Responses and Gemini/GPT-4.1 chat models.")
end

.supported?(model) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/kward/model/copilot_models.rb', line 15

def supported?(model)
  text = model.to_s
  text.match?(/\Agpt-5(?:\.|-|\z)/) || text.match?(/\A(?:gemini-|gpt-4\.1|oswe-)/)
end

.supported_choices(choices) ⇒ Object



20
21
22
# File 'lib/kward/model/copilot_models.rb', line 20

def supported_choices(choices)
  choices.select { |model| supported?(model) }.uniq
end