code.container/lib/config.rb

41 lines
1,023 B
Ruby

# lib/config.rb
require 'yaml'
require 'fileutils'
class AgentConfig
DEFAULT_PATH = 'config/agent.yml'
# Carrega o arquivo de configuração ou usa um fallback padrão se não existir
def self.load(path = DEFAULT_PATH)
if File.exist?(path)
YAML.load_file(path) rescue {}
else
{
'debug' => true,
'backends' => {
'text' => {
'default' => 'llama',
'providers' => {
'llama' => {
'endpoint' => ENV.fetch('LLAMA_CPP_ENDPOINT', 'http://127.0.0.1:8080/v1/chat/completions'),
'model' => 'local-model',
'timeout' => 300
}
}
}
}
}
end
end
# Helper global seguro contra recursão para verificar se o debug está ativo
def self.debug?
@cached_config ||= load rescue {}
@cached_config['debug'] != false
end
# Permite resetar o cache se a configuração for atualizada
def self.reload!
@cached_config = load
end
end