Method: Config#set_config

Defined in:
lib/config.rb

#set_config(value) ⇒ Object



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

def set_config(value)
  if value.include?('key')
    stript_value = value.sub(/^key/, '').strip
    if stript_value.empty?
      return 'No API key given'
    end
    save_key(stript_value)
    return 'API key saved'
  elsif value.include?('temp')
    stript_value = value.sub(/^temp/, '').strip.to_f
    if stript_value.to_f > 1.0 || stript_value.to_f < 0.1
      return 'Temperature must be between 0.1 and 1.0'
    end
    save_temperature(stript_value)
    return 'Temperature saved'
  elsif value.include?('context')
    stript_value = value.sub(/^context/, '').strip.to_i
    if stript_value.to_i > 100 || stript_value.to_i < 1
      return 'Context length must be between 1 and 100'
    end
    save_context_length(stript_value)
    return 'Context length saved'
  else
    return 'Invalid config value'
  end
end