Module: RubyCoded::Chat::State::ModelSelection
- Included in:
- RubyCoded::Chat::State
- Defined in:
- lib/ruby_coded/chat/state/model_selection.rb
Overview
This module contains the logic for the model selection management
Instance Method Summary collapse
- #append_to_model_filter(text) ⇒ Object
- #delete_last_filter_char ⇒ Object
- #enter_model_select!(models, show_all: false) ⇒ Object
- #exit_model_select! ⇒ Object
- #filtered_model_list ⇒ Object
- #model_select? ⇒ Boolean
- #model_select_down ⇒ Object
- #model_select_show_all? ⇒ Boolean
- #model_select_up ⇒ Object
- #selected_model ⇒ Object
Instance Method Details
#append_to_model_filter(text) ⇒ Object
65 66 67 68 69 |
# File 'lib/ruby_coded/chat/state/model_selection.rb', line 65 def append_to_model_filter(text) @model_select_filter << text @model_select_index = 0 mark_dirty! end |
#delete_last_filter_char ⇒ Object
71 72 73 74 75 |
# File 'lib/ruby_coded/chat/state/model_selection.rb', line 71 def delete_last_filter_char @model_select_filter.chop! @model_select_index = 0 mark_dirty! end |
#enter_model_select!(models, show_all: false) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/ruby_coded/chat/state/model_selection.rb', line 16 def enter_model_select!(models, show_all: false) @model_list = models @model_select_index = 0 @model_select_filter = String.new @model_select_show_all = show_all @mode = :model_select mark_dirty! end |
#exit_model_select! ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/ruby_coded/chat/state/model_selection.rb', line 25 def exit_model_select! @mode = :chat @model_list = [] @model_select_index = 0 @model_select_filter = String.new @model_select_show_all = false mark_dirty! end |
#filtered_model_list ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ruby_coded/chat/state/model_selection.rb', line 54 def filtered_model_list return @model_list if @model_select_filter.empty? query = @model_select_filter.downcase @model_list.select do |m| model_id = m.respond_to?(:id) ? m.id : m.to_s provider = m.respond_to?(:provider) ? m.provider.to_s : "" model_id.downcase.include?(query) || provider.downcase.include?(query) end end |
#model_select? ⇒ Boolean
8 9 10 |
# File 'lib/ruby_coded/chat/state/model_selection.rb', line 8 def model_select? @mode == :model_select end |
#model_select_down ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/ruby_coded/chat/state/model_selection.rb', line 42 def model_select_down filtered = filtered_model_list return if filtered.empty? @model_select_index = (@model_select_index + 1) % filtered.size mark_dirty! end |
#model_select_show_all? ⇒ Boolean
12 13 14 |
# File 'lib/ruby_coded/chat/state/model_selection.rb', line 12 def model_select_show_all? @model_select_show_all == true end |
#model_select_up ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/ruby_coded/chat/state/model_selection.rb', line 34 def model_select_up filtered = filtered_model_list return if filtered.empty? @model_select_index = (@model_select_index - 1) % filtered.size mark_dirty! end |
#selected_model ⇒ Object
50 51 52 |
# File 'lib/ruby_coded/chat/state/model_selection.rb', line 50 def selected_model filtered_model_list[@model_select_index] end |