9
10
11
12
13
14
15
16
17
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
|
# File 'lib/app_config.rb', line 9
def self.load
unless File.directory?(File.dirname(CONFIG_FILE))
Dir.mkdir(File.dirname(CONFIG_FILE))
end
unless File.exist?(self::CONFIG_FILE)
puts 'Welcome to gpterm! It looks like this is your first time using this application.'.colorize(:magenta)
new_config = {}
puts "Before we get started, we need to configure the application. All the info you provide will be saved in #{self::CONFIG_FILE}.".colorize(:magenta)
puts "Enter your OpenAI API key's \"SECRET KEY\" value then hit return: ".colorize(:yellow)
new_config['openapi_key'] = Input.non_empty
puts "Your PATH environment variable is: #{ENV['PATH']}".colorize(:magenta)
puts 'Are you happy for your PATH to be sent to OpenAI to help with command generation? (Y/n then hit return) '.colorize(:yellow)
input = Input.yes_or_no
if input == 'y'
new_config['send_path'] = true
else
new_config['send_path'] = false
end
default_model = 'gpt-4-turbo-preview'
puts "The default model is #{default_model}. If you would like to change it please enter the name of your preferred model:".colorize(:yellow)
new_config['model'] = STDIN.gets.chomp.strip || default_model
self.save_config(new_config)
puts "Configuration saved to #{self::CONFIG_FILE}".colorize(:green)
new_config
else
self.load_config_from_file
end
end
|