Class: Main
Class Method Summary collapse
Methods included from Logging
Methods included from Files
config_path, context_file_path, context_path, file_path, root
Methods included from Config
load_context_length, load_key, load_temperature, save_context_length, save_key, save_temperature, set_config
Class Method Details
.run ⇒ Object
18 19 20 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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/main.rb', line 18 def self.run() config = load_env() ## This does not work. Need to fix this. if (config == false || config.nil?) Logging.log("No API key found.") Help.display_api_key() Logging.log('If you want to set your API key now, type (y)es and press enter.') while input = Readline.readline("> ", true) do if input.empty? Logging.log("Exiting.") exit elsif input == "y" || input == "yes" || input == "Y" || input == "Yes" set_key() break else Logging.log('Invalid input (y)es or press enter to exit.') end end end context = Context.load_context() = HandleArgs.handle_args() = .select { |k, v| k.start_with?("option_") } input = ["input"] = ["-h", "--help", "-v", "--version", "--key"] ## Hack... Need to fix this. if .empty? = { "option_0" => "simple" } end .each do |k, v| if .include?(v) ## Options that halt the program. case v when "-h", "--help" Help.display_help() exit when "-v", "--version" Help.display_version() exit when "--key" set_key(api_key: nil) else Help.display_help() exit end else ## Options that don't halt the program. case v when "-f", "--file" file_as_string = Context.load_context_file() if file_as_string.empty? exit end Prompt.stream_prompt(input, file_as_string) when "-lf", "--loadfile" Logging.log("Loading File #{input}") Context.save_context_file(input) when "-d", "--delete" if input.nil? Context.delete_context() else Context.delete_context() Context.save_context(Prompt.stream_prompt(input, context)) end when "-c", "--conversation" Logging.log(input) Context.save_context(Prompt.stream_prompt(input, context)) when "-w", "--whisper" Logging.log(Prompt.whisper_transcribe(input)) when "-t", "--translate" Logging.log(Prompt.whisper_translate(input)) when "-i", "--interactive" Logging.log("Interactive mode...") Help.interactive_desc() while input = Readline.readline("\n> ", true) do case input when "exit", "quit" break when "clear" Logging.log("Clearing context...") Context.delete_context() when 'help' Help.interactive_desc() when /^help/ strip_input = input.sub(/^help/, "").strip #TODO: This should be a specific help for interactive. Help.interactive_help(strip_input) when "show" Logging.log("\n") Logging.log(Context.load_context()) when /^-w/ stript_input = input.sub(/^-w/, "").strip Logging.log(Prompt.whisper_transcribe(stript_input, interactive: true)) when /^-t/ stript_input = input.sub(/^-t/, "").strip Logging.log(Prompt.whisper_translate(stript_input, interactive: true)) when /^-lf/ stript_input = input.sub(/^-lf/, "").strip Logging.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? Logging.log("No file loaded.") next end Logging.log("") Prompt.stream_prompt(stript_input, file_as_string) Logging.log("") when "" Logging.log("No input given.") when /^config/ strip_input = input.sub(/^config/, "").strip Config.set_config(strip_input) #set_key(api_key: nil) else #options_and_input = HandleArgs.handle_args() context = Context.load_context() Logging.log("") Context.save_context(Prompt.stream_prompt(input, context)) Logging.log("") end end Logging.log("Exiting...") when "simple" if !input.nil? Prompt.stream_prompt(input) else Logging.log("No input given.") Help.display_help() end else Help.display_help() end end end end |