Class: Ghostest::Config

Inherits:
Object
  • Object
show all
Includes:
AttrReader
Defined in:
lib/ghostest/config.rb

Defined Under Namespace

Classes: Agent

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, options) ⇒ Config

Returns a new instance of Config.

Raises:



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/ghostest/config.rb', line 6

def initialize(hash, options)
  @llm = options[:llm]
  @debug = options[:debug]

  @max_token = hash[:max_token] || 32000
  @language = (hash[:language] || raise(ConfigError.new("Language is required"))).to_sym
  @watch_files = hash[:watch_files] || raise(ConfigError.new("Watch files are required"))
  agents = hash[:agents] || []
  @agents = Hash[agents.map { |k, h| [k, Agent.new(k, h, self)] }].with_indifferent_access
  raise(ConfigError.new("2 Agents are required")) if @agents.size < 2
end

Instance Attribute Details

#agentsObject (readonly)

Returns the value of attribute agents.



4
5
6
# File 'lib/ghostest/config.rb', line 4

def agents
  @agents
end

#debugObject (readonly)

Returns the value of attribute debug.



4
5
6
# File 'lib/ghostest/config.rb', line 4

def debug
  @debug
end

#languageObject (readonly)

Returns the value of attribute language.



4
5
6
# File 'lib/ghostest/config.rb', line 4

def language
  @language
end

#llmObject (readonly)

Returns the value of attribute llm.



4
5
6
# File 'lib/ghostest/config.rb', line 4

def llm
  @llm
end

#max_tokenObject (readonly)

Returns the value of attribute max_token.



4
5
6
# File 'lib/ghostest/config.rb', line 4

def max_token
  @max_token
end

#watch_filesObject (readonly)

Returns the value of attribute watch_files.



4
5
6
# File 'lib/ghostest/config.rb', line 4

def watch_files
  @watch_files
end

Class Method Details

.load(config_path, options) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ghostest/config.rb', line 37

def load(config_path, options)
  options = options.with_indifferent_access
  default_config = parse_config_file(File.expand_path('config/ghostest.yml'))
  if config_path.nil?
    Config.new(default_config.with_indifferent_access, options)
  elsif File.exist?(config_path)
    Config.new(default_config.merge(parse_config_file(config_path)).with_indifferent_access, options)
  elsif (expanded = File.expand_path(config_path)) && File.exist?(expanded)
    Config.new(default_config.merge(parse_config_file(expanded)).with_indifferent_access, options)
  else
    raise ConfigError.new("Config file #{config_path} not found")
  end
end

Instance Method Details

#language_klassObject



27
28
29
30
31
32
33
34
# File 'lib/ghostest/config.rb', line 27

def language_klass
  case self.language
  when :ruby
    return Ghostest::Languages::Ruby
  else
    raise ConfigError.new("Unknown language #{self.language}")
  end
end

#llm_klassObject



18
19
20
21
22
23
24
25
# File 'lib/ghostest/config.rb', line 18

def llm_klass
  case @llm&.to_sym
  when :azure_open_ai
    return Llm::Clients::AzureOpenAi
  else
    raise ConfigError.new("Unknown llm #{@llm}")
  end
end