Module: OllamaChat::Dialog

Included in:
Chat
Defined in:
lib/ollama_chat/dialog.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#document_policy=(value) ⇒ Object (writeonly)

Sets the attribute document_policy

Parameters:

  • value

    the value to set the attribute document_policy to.



36
37
38
# File 'lib/ollama_chat/dialog.rb', line 36

def document_policy=(value)
  @document_policy = value
end

Instance Method Details

#ask?(prompt:) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
# File 'lib/ollama_chat/dialog.rb', line 13

def ask?(prompt:)
  print prompt
  STDIN.gets.chomp
end

#change_system_prompt(default, system: nil) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ollama_chat/dialog.rb', line 60

def change_system_prompt(default, system: nil)
  selector = Regexp.new(system.to_s[1..-1].to_s)
  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_voiceObject



86
87
88
89
# File 'lib/ollama_chat/dialog.rb', line 86

def change_voice
  chosen  = OllamaChat::Utils::Chooser.choose(config.voice.list)
  @current_voice = chosen.full? || config.voice.default
end

#choose_collection(current_collection) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ollama_chat/dialog.rb', line 18

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_policyObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ollama_chat/dialog.rb', line 38

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



2
3
4
5
6
7
8
9
10
11
# File 'lib/ollama_chat/dialog.rb', line 2

def choose_model(cli_model, current_model)
  models = ollama.tags.models.map(&:name).sort
  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

#message_listObject



91
92
93
# File 'lib/ollama_chat/dialog.rb', line 91

def message_list
  MessageList.new(self)
end