From 7d5b14bca135ce521a48c00e54e2e34c7bb76773 Mon Sep 17 00:00:00 2001 From: sigoden Date: Thu, 6 Jun 2024 08:52:40 +0800 Subject: feat: support dotenv (#18) --- run/tool.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'run/tool.rb') diff --git a/run/tool.rb b/run/tool.rb index cf51f3f..2b47788 100755 --- a/run/tool.rb +++ b/run/tool.rb @@ -31,6 +31,23 @@ def load_func(func_file) end end +def load_env(file_path) + return unless File.exist?(file_path) + + File.readlines(file_path).each do |line| + line = line.strip + next if line.empty? || line.start_with?('#') + + key, *value = line.split('=', 2) + ENV[key.strip] = value.join('=').strip + end +rescue StandardError +end + +ENV['LLM_FUNCTIONS_DIR'] = Pathname.new(__dir__).join('..').expand_path.to_s + +load_env(Pathname.new(ENV['LLM_FUNCTIONS_DIR']).join('.env').to_s) + func_file, func_data = parse_argv if ENV["LLM_FUNCTION_ACTION"] == "declarate" -- cgit v1.2.3