Class: Main

Inherits:
Object
  • Object
show all
Extended by:
Config, Files, Logging
Defined in:
lib/main.rb

Constant Summary collapse

LIST =
[
  "exit", "quit", "version", "clear", "help", "show",
  "-w", "-t", "-lf", "-f", "config", "temp", "context"
].sort

Class Method Summary collapse

Methods included from Config

load_context_length, load_env, load_key, load_temperature, save_context_length, save_key, save_temperature, set_config, set_key

Methods included from Files

config_path, context_file_path, context_path, file_path, root

Methods included from Logging

log

Class Method Details

.runObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/main.rb', line 21

def self.run()

  ## When using Readline, TAB will auto-complete
  ## But it will only auto-complete from the LIST
  ## Need to handle directories and files when -lf, -w, -t are used
  #comp = proc { |s| LIST.grep(/^#{Regexp.escape(s)}/) }
  #Readline.completion_append_character = ""
  #Readline.completion_proc = comp

  Help.interactive_desc()
  while input = Readline.readline("\n> ", true) do
    case input
    when "exit", "quit"
      break
    when "version"
      Help.display_version()
    when "clear"
      log("Clearing context...")
      Context.delete_context()
    when 'help'
      Help.interactive_desc()
    when /^help/
      strip_input = input.sub(/^help/, "").strip
      Help.interactive_help(strip_input)
    when "show"
      log("\n")
      log(Context.load_context())
    when /^-w/ 
      stript_input = input.sub(/^-w/, "").strip
      log(Prompt.whisper_transcribe(stript_input, interactive: true))
    when /^-t/
      stript_input = input.sub(/^-t/, "").strip
      log(Prompt.whisper_translate(stript_input, interactive: true))
    when /^-lf/
      stript_input = input.sub(/^-lf/, "").strip
      log("Loading File #{stript_input}")
      Context.save_context_file(stript_input)
    when /^-f/
      stript_input = input.sub(/^-f/, "").strip
      file_as_string = Context.load_context_file()
      if file_as_string.empty?
        log("No file loaded.")
        next
      end
      log("")
      Prompt.stream_prompt(stript_input, file_as_string)
      log("")
    when ""
      log("No input given.")
    when /^config/
      strip_input = input.sub(/^config/, "").strip
      res = set_config(strip_input)
      if res.is_a?(String)
        log(res)
      end
    else
      context = Context.load_context()
      log("")
      Context.save_context(Prompt.stream_prompt(input, context))
      log("")
    end
  end
end