diff options
Diffstat (limited to 'run')
| -rwxr-xr-x | run/tool.js | 21 | ||||
| -rwxr-xr-x | run/tool.py | 20 | ||||
| -rwxr-xr-x | run/tool.rb | 17 | ||||
| -rwxr-xr-x | run/tool.sh | 9 |
4 files changed, 62 insertions, 5 deletions
diff --git a/run/tool.js b/run/tool.js index ad7c151..3c8e966 100755 --- a/run/tool.js +++ b/run/tool.js @@ -1,6 +1,7 @@ #!/usr/bin/env node const path = require("path"); +const fs = require('fs'); function parseArgv() { let func_file = process.argv[1]; @@ -22,7 +23,7 @@ function parseArgv() { } function loadFunc(func_file) { - const func_path = path.resolve(__dirname, `../tools/${func_file}`) + const func_path = path.resolve(process.env["LLM_FUNCTIONS_DIR"], `tools/${func_file}`) try { return require(func_path); } catch { @@ -31,6 +32,24 @@ function loadFunc(func_file) { } } +function loadEnv(filePath) { + try { + const data = fs.readFileSync(filePath, 'utf-8'); + const lines = data.split('\n'); + + lines.forEach(line => { + if (line.trim().startsWith('#') || line.trim() === '') return; + + const [key, ...value] = line.split('='); + process.env[key.trim()] = value.join('=').trim(); + }); + } catch {} +} + +process.env["LLM_FUNCTIONS_DIR"] = path.resolve(__dirname, ".."); + +loadEnv(path.resolve(process.env["LLM_FUNCTIONS_DIR"], ".env")); + const [func_file, func_data] = parseArgv(); if (process.env["LLM_FUNCTION_ACTION"] == "declarate") { diff --git a/run/tool.py b/run/tool.py index 99163d3..d986692 100755 --- a/run/tool.py +++ b/run/tool.py @@ -22,8 +22,7 @@ def parse_argv(): return func_file, func_data def load_func(func_file): - base_dir = os.path.dirname(os.path.abspath(__file__)) - func_path = os.path.join(base_dir, f"../tools/{func_file}") + func_path = os.path.join(os.environ["LLM_FUNCTIONS_DIR"], f"tools/{func_file}") if os.path.exists(func_path): spec = importlib.util.spec_from_file_location(func_file, func_path) module = importlib.util.module_from_spec(spec) @@ -33,6 +32,23 @@ def load_func(func_file): print(f"Invalid function: {func_file}") sys.exit(1) +def load_env(file_path): + try: + with open(file_path, 'r') as f: + for line in f: + line = line.strip() + if line.startswith('#') or line == '': + continue + + key, *value = line.split('=') + os.environ[key.strip()] = '='.join(value).strip() + except FileNotFoundError: + pass + +os.environ["LLM_FUNCTIONS_DIR"] = os.path.join(os.path.dirname(__file__), "..") + +load_env(os.path.join(os.environ["LLM_FUNCTIONS_DIR"], ".env")) + func_file, func_data = parse_argv() if os.getenv("LLM_FUNCTION_ACTION") == "declarate": 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" diff --git a/run/tool.sh b/run/tool.sh index 4846c8e..faafddd 100755 --- a/run/tool.sh +++ b/run/tool.sh @@ -1,6 +1,12 @@ #!/usr/bin/env bash set -e +export LLM_FUNCTIONS_DIR="$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd)" + +if [[ -f "$LLM_FUNCTIONS_DIR/.env" ]]; then + source "$LLM_FUNCTIONS_DIR/.env" +fi + if [[ "$0" == *tool.sh ]]; then FUNC_FILE="$1" FUNC_DATA="$2" @@ -12,8 +18,7 @@ if [[ "$FUNC_FILE" != *'.sh' ]]; then FUNC_FILE="$FUNC_FILE.sh" fi -PROJECT_DIR="$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd)" -FUNC_FILE="$PROJECT_DIR/tools/$FUNC_FILE" +FUNC_FILE="$LLM_FUNCTIONS_DIR/tools/$FUNC_FILE" if [[ "$OS" == "Windows_NT" ]]; then FUNC_FILE="$(cygpath -w "$FUNC_FILE")" |
