Module: Kward::CopilotModels
- Defined in:
- lib/kward/model/copilot_models.rb
Overview
Parses and filters GitHub Copilot model catalog responses.
Class Method Summary collapse
- .catalog_entries(body, strict: false) ⇒ Object
- .model_id(entry) ⇒ Object
- .parse(body, strict: false) ⇒ Object
- .resolved_chat_model(configured_model, choices) ⇒ Object
- .supported?(model) ⇒ Boolean
- .supported_choices(choices) ⇒ Object
Class Method Details
.catalog_entries(body, strict: false) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/kward/model/copilot_models.rb', line 32 def catalog_entries(body, strict: false) data = JSON.parse(body.to_s) entries = data.is_a?(Hash) ? data["data"] || data["models"] || data["items"] : data raise "Invalid Copilot model catalog" if strict && !entries.is_a?(Array) Array(entries) end |
.model_id(entry) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/kward/model/copilot_models.rb', line 40 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, strict: false) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/kward/model/copilot_models.rb', line 9 def parse(body, strict: false) catalog_entries(body, strict: strict).filter_map { |entry| model_id(entry) }.uniq rescue JSON::ParserError raise if strict [] end |
.resolved_chat_model(configured_model, choices) ⇒ Object
26 27 28 29 30 |
# File 'lib/kward/model/copilot_models.rb', line 26 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/GPT-6 Responses and Gemini/GPT-4.1 chat models.") end |
.supported?(model) ⇒ Boolean
17 18 19 20 |
# File 'lib/kward/model/copilot_models.rb', line 17 def supported?(model) text = model.to_s text.match?(/\Agpt-(?:5|6)(?:\.|-|\z)/) || text.match?(/\A(?:gemini-|gpt-4\.1|oswe-)/) end |
.supported_choices(choices) ⇒ Object
22 23 24 |
# File 'lib/kward/model/copilot_models.rb', line 22 def supported_choices(choices) choices.select { |model| supported?(model) }.uniq end |