Module: OllamaChat::Dialog
- Included in:
- Chat
- Defined in:
- lib/ollama_chat/dialog.rb
Instance Attribute Summary collapse
-
#document_policy ⇒ Object
writeonly
Sets the attribute document_policy.
Instance Method Summary collapse
- #ask?(prompt:) ⇒ Boolean
- #change_system_prompt(default, system: nil) ⇒ Object
- #change_voice ⇒ Object
- #choose_collection(current_collection) ⇒ Object
- #choose_document_policy ⇒ Object
- #choose_model(cli_model, current_model) ⇒ Object
- #choose_prompt ⇒ Object
- #message_list ⇒ Object
Instance Attribute Details
#document_policy=(value) ⇒ Object (writeonly)
Sets the attribute document_policy
52 53 54 |
# File 'lib/ollama_chat/dialog.rb', line 52 def document_policy=(value) @document_policy = value end |
Instance Method Details
#ask?(prompt:) ⇒ Boolean
29 30 31 32 |
# File 'lib/ollama_chat/dialog.rb', line 29 def ask?(prompt:) print prompt STDIN.gets.chomp end |
#change_system_prompt(default, system: nil) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/ollama_chat/dialog.rb', line 76 def change_system_prompt(default, system: nil) selector = if system =~ /\A\?(.+)\z/ Regexp.new($1) else Regexp.new(system.to_s) end prompts = config.system_prompts.attribute_names.compact.grep(selector) if prompts.size == 1 system = config.system_prompts.send(prompts.first) else prompts.unshift('[EXIT]').unshift('[NEW]') chosen = OllamaChat::Utils::Chooser.choose(prompts) system = case chosen when '[NEW]' ask?(prompt: "Enter new system prompt to use: ") when '[EXIT]' STDOUT.puts "Exiting chooser." return when nil default when *prompts config.system_prompts.send(chosen) else default end end @messages.set_system_prompt(system) end |
#change_voice ⇒ Object
118 119 120 121 |
# File 'lib/ollama_chat/dialog.rb', line 118 def change_voice chosen = OllamaChat::Utils::Chooser.choose(config.voice.list) @current_voice = chosen.full? || config.voice.default end |
#choose_collection(current_collection) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ollama_chat/dialog.rb', line 34 def choose_collection(current_collection) collections = [ current_collection ] + @documents.collections collections = collections.compact.map(&:to_s).uniq.sort collections.unshift('[EXIT]').unshift('[NEW]') collection = OllamaChat::Utils::Chooser.choose(collections) || current_collection case collection when '[NEW]' @documents.collection = ask?(prompt: "Enter name of the new collection: ") when nil, '[EXIT]' STDOUT.puts "Exiting chooser." when /./ @documents.collection = collection end ensure STDOUT.puts "Using collection #{bold{@documents.collection}}." info end |
#choose_document_policy ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ollama_chat/dialog.rb', line 54 def choose_document_policy policies = %w[ importing embedding summarizing ignoring ].sort current = if policies.index(@document_policy) @document_policy elsif policies.index(config.document_policy) config.document_policy else policies.first end policies.unshift('[EXIT]') policy = OllamaChat::Utils::Chooser.choose(policies) case policy when nil, '[EXIT]' STDOUT.puts "Exiting chooser." policy = current end self.document_policy = policy ensure STDOUT.puts "Using document policy #{bold{@document_policy}}." info end |
#choose_model(cli_model, current_model) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ollama_chat/dialog.rb', line 13 def choose_model(cli_model, current_model) selector = if cli_model =~ /\A\?+(.*)\z/ cli_model = '' Regexp.new($1) end models = ollama..models.sort_by(&:name).map { |m| model_with_size(m) } selector and models = models.grep(selector) model = if cli_model == '' OllamaChat::Utils::Chooser.choose(models) || current_model else cli_model || current_model end ensure STDOUT.puts green { "Connecting to #{model}@#{ollama.base_url} now…" } end |
#choose_prompt ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/ollama_chat/dialog.rb', line 106 def choose_prompt prompts = config.prompts.attribute_names prompts.unshift('[EXIT]') case chosen = OllamaChat::Utils::Chooser.choose(prompts) when '[EXIT]', nil STDOUT.puts "Exiting chooser." return when *prompts config.prompts.send(chosen) end end |
#message_list ⇒ Object
123 124 125 |
# File 'lib/ollama_chat/dialog.rb', line 123 def MessageList.new(self) end |