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.



41
42
43
# File 'lib/ollama_chat/dialog.rb', line 41

def document_policy=(value)
  @document_policy = value
end

Instance Method Details

#ask?(prompt:) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/ollama_chat/dialog.rb', line 18

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

#change_system_prompt(default, system: nil) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ollama_chat/dialog.rb', line 65

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_voiceObject



95
96
97
98
# File 'lib/ollama_chat/dialog.rb', line 95

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

#choose_collection(current_collection) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ollama_chat/dialog.rb', line 23

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



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ollama_chat/dialog.rb', line 43

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
12
13
14
15
16
# File 'lib/ollama_chat/dialog.rb', line 2

def choose_model(cli_model, current_model)
  selector = if cli_model =~ /\A\?+(.*)\z/
               cli_model = ''
               Regexp.new($1)
             end
  models = ollama.tags.models.map(&:name).sort
  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

#message_listObject



100
101
102
# File 'lib/ollama_chat/dialog.rb', line 100

def message_list
  MessageList.new(self)
end