Module: Config

Includes:
Files
Included in:
Context, Main, Prompt
Defined in:
lib/config.rb

Class Method Summary collapse

Methods included from Files

config_path, context_file_path, context_path, file_path, root

Class Method Details

.load_context_lengthObject



27
28
29
30
# File 'lib/config.rb', line 27

def self.load_context_length
  config = YAML.load_file(Files.config_path)
  config['CONTEXT_LENGTH']
end

.load_keyObject



5
6
7
8
# File 'lib/config.rb', line 5

def self.load_key()
  config = YAML.load_file(Files.config_path)
  config['OPENAI_API_KEY']
end

.load_temperatureObject



16
17
18
19
# File 'lib/config.rb', line 16

def self.load_temperature
  config = YAML.load_file(Files.config_path)
  config['TEMPERATURE']
end

.save_context_length(context_length) ⇒ Object



32
33
34
35
36
# File 'lib/config.rb', line 32

def self.save_context_length(context_length)
  config = YAML.load_file(Files.config_path)
  config['CONTEXT_LENGTH'] = context_length.to_i
  File.open(Files.config_path, 'w') { |f| YAML.dump(config, f) }
end

.save_key(api_key) ⇒ Object



10
11
12
13
14
# File 'lib/config.rb', line 10

def self.save_key(api_key)
  config = YAML.load_file(Files.config_path)
  config['OPENAI_API_KEY'] = api_key
  File.open(Files.config_path, 'w') { |f| YAML.dump(config, f) }
end

.save_temperature(temperature) ⇒ Object



21
22
23
24
25
# File 'lib/config.rb', line 21

def self.save_temperature(temperature)
  config = YAML.load_file(Files.config_path)
  config['TEMPERATURE'] = temperature.to_f
  File.open(Files.config_path, 'w') { |f| YAML.dump(config, f) }
end

.set_config(value) ⇒ Object



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
# File 'lib/config.rb', line 38

def self.set_config(value)
  puts 'value',value
  if value.include?('key')
    stript_value = value.sub(/^key/, '').strip
    if stript_value.empty?
      puts 'No API key given'
      exit
    end
    save_key(stript_value)
  elsif value.include?('temp')
    stript_value = value.sub(/^temp/, '').strip
    if stript_value.empty?
      puts 'No temperature given'
      exit
    end
    save_temperature(stript_value)
  elsif value.include?('context')
    stript_value = value.sub(/^context/, '').strip
    if stript_value.empty?
      puts 'No context length given'
      exit
    end
    save_context_length(stript_value)
  else
    puts 'Invalid config value'
  end
end